| #include <asm/unaligned.h> |
| static inline int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len) |
| * this insists on correct encodings, though not minimal ones. |
| * BUT it currently rejects legit 4-byte UTF-8 code points, |
| * which need surrogate pairs. (Unicode 3.1 can use them.) |
| while (len != 0 && (c = (u8) *s++) != 0) { |
| * 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx |
| if ((c & 0xe0) == 0xc0) { |
| * 3-byte sequence (most CJKV characters): |
| * zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx |
| } else if ((c & 0xf0) == 0xe0) { |
| uchar = (c & 0x0f) << 12; |
| /* no bogus surrogates */ |
| if (0xd800 <= uchar && uchar <= 0xdfff) |
| * 4-byte sequence (surrogate pairs, currently rare): |
| * 11101110wwwwzzzzyy + 110111yyyyxxxxxx |
| * = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx |
| * FIXME accept the surrogate code points (only) |
| put_unaligned_le16(uchar, cp++); |
| #endif /* _LINUX_UTF_H */ |