Navigation Menu

Skip to content

Commit

Permalink
Use load_le16() and store_le16() for UTF-16 surrogate pairs
Browse files Browse the repository at this point in the history
This also appears to fix a problem in buf_append_from_utf16le() where
the byte offsets for the entirely manual load-and-shift version were
messed up.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jan 26, 2015
1 parent 426600f commit 5770e7a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions http.c
Expand Up @@ -138,8 +138,8 @@ void buf_append_from_utf16le(struct oc_text_buf *buf, const void *_utf16)

while (utf16[0] || utf16[1]) {
if ((utf16[1] & 0xfc) == 0xd8 && (utf16[3] & 0xfc) == 0xdc) {
c = utf16[3] | ((utf16[4] & 3) << 8) |
(utf16[0] << 10) | ((utf16[1] & 3) << 18);
c = ((load_le16(utf16) & 0x3ff) << 10)|
(load_le16(utf16 + 2) & 0x3ff);
c += 0x10000;
utf16 += 4;
} else {
Expand Down Expand Up @@ -228,10 +228,9 @@ int buf_append_utf16le(struct oc_text_buf *buf, const char *utf8)
utfchar -= 0x10000;
if (buf_ensure_space(buf, 4))
return buf_error(buf);
buf->data[buf->pos++] = (utfchar >> 10) & 0xff;
buf->data[buf->pos++] = 0xd8 | ((utfchar >> 18) & 3);
buf->data[buf->pos++] = utfchar & 0xff;
buf->data[buf->pos++] = 0xdc | ((utfchar >> 8) & 3);
store_le16(buf->data + buf->pos, (utfchar >> 10) | 0xd800);
store_le16(buf->data + buf->pos + 2, (utfchar & 0x3ff) | 0xdc00);
buf->pos += 4;
len += 4;
} else {
if (buf_ensure_space(buf, 2))
Expand Down

0 comments on commit 5770e7a

Please sign in to comment.