This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: [PATCH] Extra decimal point and thousands-sep
- From: Hamed Malek <hamed at bamdad dot org>
- To: libc-alpha <libc-alpha at sources dot redhat dot com>
- Cc: Roozbeh Pournader <roozbeh at sharif dot edu>, Behdad Esfahbod <behdad at cs dot toronto dot edu>
- Date: Sun, 08 Feb 2004 14:37:22 +0330
- Subject: Re: [PATCH] Extra decimal point and thousands-sep
- References: <1075904322.17884.83.camel@hooloo.bamdad.org>
I've slightly changed my patch.
Hamed
On Wed, 2004-02-04 at 17:56, Hamed Malek wrote:
> Hi,
>
> Some languages like Persian need extra decimal point and thousands-sep.
> Attached is a patch which adds these new elements to glibc.
>
> I wrote it based on Ulrich suggestion, which defines a new map
> (to_outpunct) for those locales, and call it for I18n numbers.
> The patch also contains the necessary changes in fa_IR.
>
> Hamed
>
--- glibc-2.3.2-200310271512.orig/include/wctype.h 2004-01-05 18:07:20.000000000 +0330
+++ glibc-2.3.2-200310271512/include/wctype.h 2004-02-03 17:52:08.000000000 +0330
@@ -49,6 +49,7 @@
extern int __iswctype (wint_t __wc, wctype_t __desc);
extern int __iswctype_internal (wint_t __wc, wctype_t __desc) attribute_hidden;
extern wctype_t __wctype (__const char *__property);
+extern wctrans_t __wctrans (const char *__property);
extern wint_t __towctrans (wint_t __wc, wctrans_t __desc);
extern __typeof (iswalnum_l) __iswalnum_l;
--- glibc-2.3.2-200310271512.orig/localedata/locales/fa_IR 2004-01-05 18:07:26.000000000 +0330
+++ glibc-2.3.2-200310271512/localedata/locales/fa_IR 2004-02-03 18:03:35.000000000 +0330
@@ -49,6 +49,10 @@
LC_CTYPE
copy "i18n"
+map to_outpunct; /
+ (<U002E>,<U066B>); /
+ (<U002C>,<U066C>)
+
outdigit <U06F0>..<U06F9>
END LC_CTYPE
@@ -269,8 +273,8 @@
END LC_MONETARY
LC_NUMERIC
-decimal_point "<U066B>"
-thousands_sep "<U066C>"
+decimal_point "<U002E>"
+thousands_sep "<U002C>"
grouping 3
END LC_NUMERIC
--- glibc-2.3.2-200310271512.orig/stdio-common/_i18n_number.h 2004-01-05 18:07:41.000000000 +0330
+++ glibc-2.3.2-200310271512/stdio-common/_i18n_number.h 2004-02-08 14:23:33.000000000 +0330
@@ -17,12 +17,54 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <wctype.h>
+#include <wchar.h>
+
#include "../locale/outdigits.h"
#include "../locale/outdigitswc.h"
+static char *
+_put_outpunct (char *s, const char *outpunct)
+{
+ size_t dlen;
+ dlen = strlen (outpunct);
+
+ s -= dlen;
+ while (dlen-- > 0)
+ s[dlen] = outpunct[dlen];
+
+ return s;
+}
+
static CHAR_T *
_i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr)
{
+ /* "to_outpunct" is a map from ASCII decimal point and thousands-sep
+ to their equivalent in locale. This is defined for locales which
+ use extra decimal point and thousands-sep. */
+
+ wctrans_t map = __wctrans ("to_outpunct");
+
+ wint_t wdecimal = (map) ? __towctrans ('.', map) : L'.';
+ wint_t wthousands = (map) ? __towctrans (',', map) : L'.';
+
+ char decimal[MB_LEN_MAX];
+ char thousands[MB_LEN_MAX];
+
+ mbstate_t state;
+ memset (&state, '\0', sizeof (state));
+ wint_t n;
+
+ n = (map) ? __wcrtomb (decimal, wdecimal, &state) : (size_t)-1;
+ if (n == (size_t)-1)
+ memcpy (decimal, ".", 2);
+
+ memset (&state, '\0', sizeof (state));
+
+ n = (map) ? __wcrtomb (thousands, wthousands, &state) : (size_t)-1;
+ if (n == (size_t)-1)
+ memcpy (thousands, ",", 2);
+
CHAR_T *src, *s;
/* Copy existing string so that nothing gets overwritten. */
@@ -41,6 +83,20 @@
else
*--w = (CHAR_T) outdigitwc_value (*s - '0');
}
+ else if (map && (*s == '.'))
+ {
+ if (sizeof (CHAR_T) == 1)
+ w = _put_outpunct (w, decimal);
+ else
+ *--w = (CHAR_T) wdecimal;
+ }
+ else if (map && (*s == ','))
+ {
+ if (sizeof (CHAR_T) == 1)
+ w = _put_outpunct (w, thousands);
+ else
+ *--w = (CHAR_T) wthousands;
+ }
else
*--w = *s;
}
--- glibc-2.3.2-200310271512.orig/wctype/wctrans.c 2004-01-05 18:08:12.000000000 +0330
+++ glibc-2.3.2-200310271512/wctype/wctrans.c 2004-02-03 17:56:57.000000000 +0330
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,97,99,2000,02 Free Software Foundation, Inc.
+/* Copyright (C) 1996,97,99,2000,02,04 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
@@ -23,7 +23,7 @@
#include "../locale/localeinfo.h"
wctrans_t
-wctrans (const char *property)
+__wctrans (const char *property)
{
const char *names;
size_t cnt;
@@ -46,3 +46,4 @@
i = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_OFFSET) + cnt;
return (wctrans_t) _NL_CURRENT_DATA (LC_CTYPE)->values[i].string;
}
+weak_alias (__wctrans, wctrans)