#include "argmatch.h"
#include "c-ctype.h"
#include "mbswidth.h"
+#include "mcel.h"
#include "quote.h"
#include "skipchars.h"
#include "system.h"
/* debugging for developers. Enables devmsg(). */
static bool dev_debug = false;
+static bool
+newline_or_blank (mcel_t g)
+{
+ return g.ch == '\n' || c32isblank (g.ch);
+}
static inline int
default_scale_base (enum scale_type scale)
{
/* process suffix. */
- /* Skip any blanks between the number and suffix. */
- while (isblank (to_uchar (**endptr)))
- (*endptr)++;
+ /* Skip a single blank or NBSP between the number and suffix. */
+ mcel_t g = mcel_scanz (*endptr);
+ if (c32isblank (g.ch) || c32isnbspace (g.ch))
+ (*endptr) += g.len;
if (**endptr == '\0')
break; /* Treat as no suffix. */
if (!valid_suffix (**endptr))
- return SSE_INVALID_SUFFIX;
+ {
+ /* Trailing blanks are allowed. */
+ *endptr = skip_str_matching (*endptr, newline_or_blank, true);
+ if (**endptr == '\0')
+ break;
+
+ return SSE_INVALID_SUFFIX;
+ }
if (allowed_scaling == scale_none)
return SSE_VALID_BUT_FORBIDDEN_SUFFIX;
*precision = 0; /* Reset, to select precision based on scale. */
+ /* Trailing blanks are allowed. */
+ *endptr = skip_str_matching (*endptr, newline_or_blank, true);
+
break;
}
return (e == SSE_OK || e == SSE_OK_PRECISION_LOSS);
}
-static bool
-newline_or_blank (mcel_t g)
-{
- return g.ch == '\n' || c32isblank (g.ch);
-}
-
/* Return a pointer to the beginning of the next field in line.
The line pointer is moved to the end of the next field. */
static char*
'--suffix=Foo' . 'x' x 122 . 'y 0',
{OUT => '0Foo' . 'x' x 122 . 'y'}],
['suf-21', "-d '' --from=si '4 '", {OUT => "4"}],
+ # Multiple spaces between number and suffix should be rejected
+ ['suf-22', "-d '' --from=auto '2 K'",
+ {ERR => "$prog: invalid suffix in input: '2 K'\n"},
+ {EXIT => 2}],
+ # Trailing spaces should be accepted
+ ['suf-23', "-d '' --from=auto '2 '", {OUT=>'2'}],
+ ['suf-24', "-d '' --from=auto '2 '", {OUT=>'2'}],
+ ['suf-25', "-d '' --from=auto '2K '", {OUT=>'2000'}],
## GROUPING
['lcl-fmt-7', '--format="%0\'\'6f" 1234',{OUT=>"01${lg}234"},
{ENV=>"LC_ALL=$locale"}],
+ # Single blank/NBSP acceptance between number and suffix
+ ['lcl-suf-1', "-d '' --from=auto '2 K'", {OUT => "2000"},
+ {ENV=>"LC_ALL=$locale"}],
+ ['lcl-suf-2', "-d '' --from=auto '2\tK'", {OUT => "2000"},
+ {ENV=>"LC_ALL=$locale"}],
+ # NBSP characters: U+00A0, U+2007, U+202F, U+2060
+ ['lcl-suf-3', "--from=auto '2\xc2\xa0K'", {OUT => "2000"},
+ {ENV=>"LC_ALL=$locale"}],
+ ['lcl-suf-4', "--from=auto '2\xe2\x80\x87Ki'", {OUT => "2048"},
+ {ENV=>"LC_ALL=$locale"}],
+ ['lcl-suf-5', "--from=auto '2\xe2\x80\xafK'", {OUT => "2000"},
+ {ENV=>"LC_ALL=$locale"}],
+ ['lcl-suf-6', "--from=auto '2\xe2\x81\xa0Ki'", {OUT => "2048"},
+ {ENV=>"LC_ALL=$locale"}],
+
);
if ($locale ne 'C')
{