diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -349,17 +349,18 @@ int stridx(char *haystack, char needle) // 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; + int len = (wc>0x7ff)+(wc>0xffff), i; if (wc<128) { *s = wc; return 1; } else { + i = len; do { - s[1+len] = 0x80+(wc&0x3f); - wc >>= 7; - } while (len--); - *s = wc|mask; + s[1+i] = 0x80+(wc&0x3f); + wc >>= 6; + } while (i--); + *s = (((signed char) 0x80) >> (len+1)) | wc; } return 2+len; |