Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-06-03 23:28:22 +0400
committerCorinna Vinschen <corinna@vinschen.de>2009-06-03 23:28:22 +0400
commitc801709ed5776bf9d2af4c50b63405f2b6199f2e (patch)
tree02a110aeeb97fcf083990f30c1168224fa149254 /newlib/libc/locale/locale.c
parentb8c9d446690a711831cbd533968942fdfe5948dd (diff)
* libc/string/wcwidth.c: Optimize for speed.
* libc/locale/locale.c (lc_ctype_cjk_lang): New static int. (loadlocale): In case of setting LC_CTYPE, set lc_ctype_cjk_lang to 1 if the language is "jp", "ko", or "zh", to 0 otherwise. (__locale_cjk_lang): New function. * libc/string/local.h (__locale_cjk_lang): Declare. * libc/string/wcwidth.c: Fix comments. (__wcwidth): Handle CJK Ambiguous Width characters according to setting returned by __locale_cjk_lang.
Diffstat (limited to 'newlib/libc/locale/locale.c')
-rw-r--r--newlib/libc/locale/locale.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index 444a5aca8..6349bd9ad 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -204,6 +204,7 @@ static const char *__get_locale_env(struct _reent *, int);
static char lc_ctype_charset[ENCODING_LEN + 1] = "ASCII";
static char lc_message_charset[ENCODING_LEN + 1] = "ASCII";
+static int lc_ctype_cjk_lang = 0;
char *
_DEFUN(_setlocale_r, (p, category, locale),
@@ -602,6 +603,14 @@ loadlocale(struct _reent *p, int category)
__wctomb = l_wctomb;
__mbtowc = l_mbtowc;
__set_ctype (charset);
+ /* Check for the language part of the locale specifier. In case
+ of "ja", "ko", or "zh", assume the use of CJK fonts. This is
+ stored in lc_ctype_cjk_lang and tested in wcwidth() to figure
+ out the width to return (1 or 2) for the "CJK Ambiguous Width"
+ category of characters. */
+ lc_ctype_cjk_lang = (strncmp (locale, "ja", 2) == 0
+ || strncmp (locale, "ko", 2) == 0
+ || strncmp (locale, "zh", 2) == 0);
#endif
}
else if (category == LC_MESSAGES)
@@ -645,6 +654,12 @@ _DEFUN_VOID(__locale_msgcharset)
return lc_message_charset;
}
+int
+_DEFUN_VOID(__locale_cjk_lang)
+{
+ return lc_ctype_cjk_lang;
+}
+
struct lconv *
_DEFUN(_localeconv_r, (data),
struct _reent *data)