diff options
author | Ulrich Drepper <drepper@redhat.com> | 2000-06-29 08:44:37 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2000-06-29 08:44:37 +0000 |
commit | a748c3c64c832a9e4a8128f26aa17ed98139ca4a (patch) | |
tree | 8df4ef7c34a4e62f11862bde4e60a78deb412710 /stdlib/grouping.h | |
parent | 23335dcd5f7016f7191b781b81e1fd2525026cb5 (diff) | |
download | glibc-a748c3c64c832a9e4a8128f26aa17ed98139ca4a.tar.gz glibc-a748c3c64c832a9e4a8128f26aa17ed98139ca4a.tar.xz glibc-a748c3c64c832a9e4a8128f26aa17ed98139ca4a.zip |
Update.
2000-06-29 Ulrich Drepper <drepper@redhat.com> * stdlib/grouping.h: Correctly handle multibyte thousands separator and decimal point. * stdlib/stdtod.c: Likewise. * sysdeps/generic/strtol.c: Likewise. * locale/categories.def: Add entries for wide character decimal point and thousands separator in numeric and monetary category. 2000-06-28 Ulrich Drepper <drepper@redhat.com> * stdio-common/printf_fp.c (__printf_fp): Remove unnecessary second definition and initialization of decimal. * libio/libio.h (struct _IO_cookie_file): Move struct type defintion out. * libio/libioP.h (struct _IO_cookie_file): Move struct type defintion in. (_IO_JUMPS): Don't cast THIS--expect arg to be a (struct _IO_FILE_plus *). (_IO_iter_next, _IO_iter_file): _IO_ITER is now (struct _IO_FILE_plus *). (_IO_check_libio): Set user-visible handles to (struct _IO_FILE_plus *).
Diffstat (limited to 'stdlib/grouping.h')
-rw-r--r-- | stdlib/grouping.h | 76 |
1 files changed, 60 insertions, 16 deletions
diff --git a/stdlib/grouping.h b/stdlib/grouping.h index 71b89f9133..ca760c7978 100644 --- a/stdlib/grouping.h +++ b/stdlib/grouping.h @@ -1,5 +1,5 @@ /* Internal header for proving correct grouping in strings of numbers. - Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. The GNU C Library is free software; you can redistribute it and/or @@ -30,19 +30,24 @@ static inline const STRING_TYPE * correctly_grouped_prefix (const STRING_TYPE *begin, const STRING_TYPE *end, - wchar_t thousands, const char *grouping) +#ifdef USE_WIDE_CHAR + wchar_t thousands, +#else + const char *thousands, +#endif + const char *grouping) { +#ifndef USE_WIDE_CHAR + size_t thousands_len; + int cnt; +#endif + if (grouping == NULL) return end; - if (*grouping == '\0') - { - /* No grouping allowed. Accept all characters up to the first - thousands separator. */ - while (begin < end && *begin != thousands) - ++begin; - return begin; - } +#ifndef USE_WIDE_CHAR + thousands_len = strlen (thousands); +#endif while (end > begin) { @@ -50,8 +55,23 @@ correctly_grouped_prefix (const STRING_TYPE *begin, const STRING_TYPE *end, const char *gp = grouping; /* Check first group. */ - while (cp >= begin && (wchar_t) *cp != thousands) - --cp; + while (cp >= begin) + { +#ifdef USE_WIDE_CHAR + if (*cp == thousands) + break; +#else + if (cp[thousands_len - 1] == *thousands) + { + for (cnt = 1; thousands[cnt] != '\0'; ++cnt) + if (thousands[cnt] != cp[thousands_len - 1 - cnt]) + break; + if (thousands[cnt] == '\0') + break; + } +#endif + --cp; + } /* We allow the representation to contain no grouping at all even if the locale specifies we can have grouping. */ @@ -93,8 +113,20 @@ correctly_grouped_prefix (const STRING_TYPE *begin, const STRING_TYPE *end, ) { /* No more thousands separators are allowed to follow. */ - while (cp >= begin && (wchar_t) *cp != thousands) - --cp; + while (cp >= begin) + { +#ifdef USE_WIDE_CHAR + if (*cp == thousands) + break; +#else + for (cnt = 0; thousands[cnt] != '\0'; ++cnt) + if (thousands[cnt] != cp[thousands_len - cnt - 1]) + break; + if (thousands[cnt] == '\0') + break; +#endif + --cp; + } if (cp < begin) /* OK, only digits followed. */ @@ -105,8 +137,20 @@ correctly_grouped_prefix (const STRING_TYPE *begin, const STRING_TYPE *end, /* Check the next group. */ const STRING_TYPE *group_end = cp; - while (cp >= begin && (wchar_t) *cp != thousands) - --cp; + while (cp >= begin) + { +#ifdef USE_WIDE_CHAR + if (*cp == thousands) + break; +#else + for (cnt = 0; thousands[cnt] != '\0'; ++cnt) + if (thousands[cnt] != cp[thousands_len - cnt - 1]) + break; + if (thousands[cnt] == '\0') + break; +#endif + --cp; + } if (cp < begin && group_end - cp <= (int) *gp) /* Final group is correct. */ |