aboutsummaryrefslogtreecommitdiff
path: root/libbb/unicode.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-16 03:06:22 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-16 03:06:22 +0200
commit01ba1676afff4673a7dd5b355e970d52769723df (patch)
treef169a8641888cd43d01d0d084ca39b2d11f9a193 /libbb/unicode.c
parentf6106e6041895d05ab10fdc5383f12a3dba1a16d (diff)
downloadbusybox-w32-01ba1676afff4673a7dd5b355e970d52769723df.tar.gz
busybox-w32-01ba1676afff4673a7dd5b355e970d52769723df.tar.bz2
busybox-w32-01ba1676afff4673a7dd5b355e970d52769723df.zip
lineedit+unicode: code shrink
function old new delta wcrtomb_internal 161 83 -78 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/unicode.c')
-rw-r--r--libbb/unicode.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 773a0744e..3519984d9 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -48,7 +48,7 @@ void FAST_FUNC check_unicode_in_env(void)
48 48
49static size_t wcrtomb_internal(char *s, wchar_t wc) 49static size_t wcrtomb_internal(char *s, wchar_t wc)
50{ 50{
51 int n; 51 int n, i;
52 uint32_t v = wc; 52 uint32_t v = wc;
53 53
54 if (v <= 0x7f) { 54 if (v <= 0x7f) {
@@ -59,34 +59,26 @@ static size_t wcrtomb_internal(char *s, wchar_t wc)
59 /* RFC 3629 says that Unicode ends at 10FFFF, 59 /* RFC 3629 says that Unicode ends at 10FFFF,
60 * but we cover entire 32 bits */ 60 * but we cover entire 32 bits */
61 61
62 n = 2;
63 /* 4000000-FFFFFFFF -> 111111tt 10tttttt 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx */ 62 /* 4000000-FFFFFFFF -> 111111tt 10tttttt 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx */
64 if (v >= 0x4000000) {
65 s[5] = (wc & 0x3f) | 0x80;
66 wc = (uint32_t)wc >> 6; /* ensuring that high bits are 0 */
67 n++;
68 }
69 /* 200000-3FFFFFF -> 111110tt 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx */ 63 /* 200000-3FFFFFF -> 111110tt 10zzzzzz 10zzyyyy 10yyyyxx 10xxxxxx */
70 if (v >= 0x200000) {
71 s[4] = (wc & 0x3f) | 0x80;
72 wc >>= 6;
73 n++;
74 }
75 /* 10000-1FFFFF -> 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx */ 64 /* 10000-1FFFFF -> 11110zzz 10zzyyyy 10yyyyxx 10xxxxxx */
76 if (v >= 0x10000) { 65 /* 800-FFFF -> 1110yyyy 10yyyyxx 10xxxxxx */
77 s[3] = (wc & 0x3f) | 0x80; 66 /* 80-7FF -> 110yyyxx 10xxxxxx */
78 wc >>= 6; 67
68 /* How many bytes do we need? */
69 n = 2;
70 /* (0x80000000+ would result in n = 7, limiting n to 6) */
71 while (v >= 0x800 && n < 6) {
72 v >>= 5;
79 n++; 73 n++;
80 } 74 }
81 /* 800-FFFF -> 1110yyyy 10yyyyxx 10xxxxxx */ 75 /* Fill bytes n-1..1 */
82 if (v >= 0x800) { 76 i = n;
83 s[2] = (wc & 0x3f) | 0x80; 77 while (--i) {
78 s[i] = (wc & 0x3f) | 0x80;
84 wc >>= 6; 79 wc >>= 6;
85 n++;
86 } 80 }
87 /* 80-7FF -> 110yyyxx 10xxxxxx */ 81 /* Fill byte 0 */
88 s[1] = (wc & 0x3f) | 0x80;
89 wc >>= 6;
90 s[0] = wc | (uint8_t)(0x3f00 >> n); 82 s[0] = wc | (uint8_t)(0x3f00 >> n);
91 return n; 83 return n;
92} 84}