diff options
author | Rob Landley <rob@landley.net> | 2020-10-11 02:59:54 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-10-11 02:59:54 -0500 |
commit | 67bd0be1a4ed817954c9dcededf9bd9cb8c2f431 (patch) | |
tree | 4df0aa1044af467469e77c757bbf58dffe2f6178 /lib/lib.c | |
parent | 0f2658c806586190be3aca21826e77fff9e50f1b (diff) | |
download | toybox-67bd0be1a4ed817954c9dcededf9bd9cb8c2f431.tar.gz |
toysh: more variable/wildcard plumbing and tests.
Diffstat (limited to 'lib/lib.c')
-rw-r--r-- | lib/lib.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -346,6 +346,25 @@ int stridx(char *haystack, char needle) return off-haystack; } +// Convert wc to utf8, returning bytes written. Does not null terminate. +int wctoutf8(char *s, unsigned wc) +{ + int len = (wc>0x7ff)+(wc>0xffff), mask = 12+len+!!len; + + if (wc<128) { + *s = wc; + return 1; + } else { + do { + s[1+len] = 0x80+(wc&0x3f); + wc >>= 7; + } while (len--); + *s = wc|mask; + } + + return 2+len; +} + // Convert utf8 sequence to a unicode wide character // returns bytes consumed, or -1 if err, or -2 if need more data. int utf8towc(wchar_t *wc, char *str, unsigned len) |