X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_utf8.h;h=f9008032dff0eea98abc8c59cb1134b35ab3b7c3;hp=2503f0644e605db64aae577b6523e641b3e54098;hb=f513f2b7d0b226d56d0fdb45f1f9f0463e139219;hpb=65e157fc937ac522327c9597f03edc23257102b6 diff --git a/php_http_utf8.h b/php_http_utf8.h index 2503f06..f900803 100644 --- a/php_http_utf8.h +++ b/php_http_utf8.h @@ -625,6 +625,39 @@ static inline zend_bool isualnum(unsigned ch) return isualpha(ch); } +static inline size_t wctoutf16(unsigned short u16[2], unsigned wc) +{ + if (wc > 0x10ffff || (wc >= 0xd800 && wc <= 0xdfff)) { + return 0; + } + + if (wc <= 0xffff) { + u16[0] = (unsigned short) wc; + return 1; + } + + wc -= 0x10000; + u16[0] = (unsigned short) ((wc >> 10) + 0xd800); + u16[1] = (unsigned short) ((wc & 0x3ff) + 0xdc00); + return 2; +} + +static inline size_t utf16towc(unsigned *wc, unsigned short *u16_str, size_t u16_len) +{ + if (u16_len < 1) { + return 0; + } + if (u16_str[0] - 0xd800 >= 0x800) { + *wc = u16_str[0]; + return 1; + } + if (u16_len < 2 || (u16_str[0] & 0xfffffc00) != 0xd800 || (u16_str[1] & 0xfffffc00) != 0xdc00) { + return 0; + } + *wc = (u16_str[0] << 10) + u16_str[1] - 0x35fdc00; + return 2; +} + #endif /* PHP_HTTP_UTF8_H */ /*