#include "strnumcmp-in.h"
+#include <limits.h>
+
/* Compare strings A and B as integers without explicitly converting
them to machine numbers, to avoid overflow problems and perhaps
improve performance. */
int
strintcmp (char const *a, char const *b)
{
- return numcompare (a, b, -1, -1);
+ return numcompare (a, b, CHAR_MAX + 1, CHAR_MAX + 1);
}
/* Compare strings A and B as numbers without explicitly converting
them to machine numbers, to avoid overflow problems and perhaps
improve performance. DECIMAL_POINT is the decimal point and
- THOUSANDS_SEP the thousands separator. A DECIMAL_POINT of -1
- causes comparisons to act as if there is no decimal point
+ THOUSANDS_SEP the thousands separator. A DECIMAL_POINT outside
+ 'char' range causes comparisons to act as if there is no decimal point
character, and likewise for THOUSANDS_SEP. */
static inline int _GL_ATTRIBUTE_PURE
};
/* The representation of the decimal point in the current locale. */
-static int decimal_point;
+static char decimal_point;
-/* Thousands separator; if -1, then there isn't one. */
+/* Thousands separator; if outside char range, there is no separator. */
static int thousands_sep;
/* Nonzero if the corresponding locales are hard. */
they were read if all keys compare equal. */
static bool stable;
+/* An int value outside char range. */
+enum { NON_CHAR = CHAR_MAX + 1 };
+
/* If TAB has this value, blanks separate fields. */
enum { TAB_DEFAULT = CHAR_MAX + 1 };
decimal_point chars only. Returns the highest digit found in the number,
or '\0' if no digit has been found. Upon return *number points at the
character that immediately follows after the given number. */
-static unsigned char
+static char
traverse_raw_number (char const **number)
{
char const *p = *number;
- unsigned char ch;
- unsigned char max_digit = '\0';
+ char ch;
+ char max_digit = '\0';
bool ends_with_thousands_sep = false;
/* Scan to end of number.
{
bool minus_sign = (*number == '-');
char const *p = number + minus_sign;
- unsigned char max_digit = traverse_raw_number (&p);
+ char max_digit = traverse_raw_number (&p);
if ('0' < max_digit)
{
unsigned char ch = *p;
else if (key->numeric || key->human_numeric)
{
char const *p = beg + (beg < lim && *beg == '-');
- unsigned char max_digit = traverse_raw_number (&p);
+ char max_digit = traverse_raw_number (&p);
if ('0' <= max_digit)
{
unsigned char ch = *p;
/* If the locale doesn't define a decimal point, or if the decimal
point is multibyte, use the C locale's decimal point. FIXME:
add support for multibyte decimal points. */
- decimal_point = to_uchar (locale->decimal_point[0]);
+ decimal_point = locale->decimal_point[0];
if (! decimal_point || locale->decimal_point[1])
decimal_point = '.';
/* FIXME: add support for multibyte thousands separators. */
- thousands_sep = to_uchar (*locale->thousands_sep);
+ thousands_sep = locale->thousands_sep[0];
if (! thousands_sep || locale->thousands_sep[1])
- thousands_sep = -1;
+ thousands_sep = NON_CHAR;
}
have_read_stdin = false;