aboutsummaryrefslogtreecommitdiff
path: root/include/unicode.h
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-24 07:44:03 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-24 07:44:03 +0100
commit9f93d621925966c22ee51fdcb5def8e131596f9b (patch)
treec1024fa92d6f422df6cf0991d5c9c8a4977b8625 /include/unicode.h
parent5da9f96ad85a2d9119d92c7a3d89deca7d904210 (diff)
downloadbusybox-w32-9f93d621925966c22ee51fdcb5def8e131596f9b.tar.gz
busybox-w32-9f93d621925966c22ee51fdcb5def8e131596f9b.tar.bz2
busybox-w32-9f93d621925966c22ee51fdcb5def8e131596f9b.zip
libbb: better unicode width support. Hopefully fixes bug 839.
Also opens up a possibility to make other unicode stuff smaller and more correct later. but: function old new delta static.combining - 516 +516 bb_wcwidth - 328 +328 unicode_cut_nchars - 141 +141 mbstowc_internal - 93 +93 in_table - 78 +78 cal_main 899 961 +62 static.combining0x10000 - 40 +40 unicode_strlen - 31 +31 bb_mbstrlen 31 - -31 bb_mbstowcs 173 102 -71 ------------------------------------------------------------------------------ (add/remove: 7/1 grow/shrink: 1/1 up/down: 1289/-102) Total: 1187 bytes Uses code of Markus Kuhn, which is in public domain: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c "Permission to use, copy, modify, and distribute this software for any purpose and without fee is hereby granted. The author disclaims all warranties with regard to this software." Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include/unicode.h')
-rw-r--r--include/unicode.h31
1 files changed, 7 insertions, 24 deletions
diff --git a/include/unicode.h b/include/unicode.h
index e11f2f9da..f1a252cc7 100644
--- a/include/unicode.h
+++ b/include/unicode.h
@@ -13,13 +13,16 @@ enum {
13 13
14#if !ENABLE_FEATURE_ASSUME_UNICODE 14#if !ENABLE_FEATURE_ASSUME_UNICODE
15 15
16# define bb_mbstrlen(string) strlen(string) 16# define unicode_strlen(string) strlen(string)
17# define unicode_scrlen(string) TODO
17# define unicode_status UNICODE_OFF 18# define unicode_status UNICODE_OFF
18# define init_unicode() ((void)0) 19# define init_unicode() ((void)0)
19 20
20#else 21#else
21 22
22size_t bb_mbstrlen(const char *string) FAST_FUNC; 23size_t FAST_FUNC unicode_strlen(const char *string);
24char* FAST_FUNC unicode_cut_nchars(unsigned width, const char *src);
25unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src);
23 26
24# if ENABLE_LOCALE_SUPPORT 27# if ENABLE_LOCALE_SUPPORT
25 28
@@ -30,7 +33,7 @@ void init_unicode(void) FAST_FUNC;
30 33
31# else 34# else
32 35
33/* Crude "locale support" which knows only C and Unicode locales */ 36/* Homegrown Unicode support. It knows only C and Unicode locales. */
34 37
35# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV 38# if !ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
36# define unicode_status UNICODE_ON 39# define unicode_status UNICODE_ON
@@ -52,6 +55,7 @@ void init_unicode(void) FAST_FUNC;
52# define iswspace bb_iswspace 55# define iswspace bb_iswspace
53# define iswalnum bb_iswalnum 56# define iswalnum bb_iswalnum
54# define iswpunct bb_iswpunct 57# define iswpunct bb_iswpunct
58# define wcwidth bb_wcwidth
55 59
56typedef int32_t wint_t; 60typedef int32_t wint_t;
57typedef struct { 61typedef struct {
@@ -68,27 +72,6 @@ int iswpunct(wint_t wc) FAST_FUNC;
68 72
69# endif /* !LOCALE_SUPPORT */ 73# endif /* !LOCALE_SUPPORT */
70 74
71
72# if 0 /* TODO: better support for printfing Unicode fields: */
73
74/* equivalent to printf("%-20.20s", str) */
75char unicode_buffer[20 * MB_CUR_MAX];
76printf("%s", unicode_exact(20, str, unicode_buffer);
77/* no need to free() anything */
78
79/* equivalent to printf("%-20s", str) */
80char *malloced = unicode_minimum(20, str);
81printf("%s", malloced);
82free(malloced); /* ugh */
83
84/* equivalent to printf("%-20s", str), better one */
85printf("%s%*s", str, unicode_pad_to_width(str, 20), "");
86/* equivalent to printf("%20s", str) */
87printf("%*s%s", unicode_pad_to_width(str, 20), "", str);
88
89# endif
90
91
92#endif /* FEATURE_ASSUME_UNICODE */ 75#endif /* FEATURE_ASSUME_UNICODE */
93 76
94#endif 77#endif