X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/3d88e64dfcf5dc0fd361ce0c504c67a9196ce44c..691b58ac4403cf73a1d71c6c2bbd5d8246d95699:/ldiscucs.c diff --git a/ldiscucs.c b/ldiscucs.c index 4ac28d7e..c4fc726d 100644 --- a/ldiscucs.c +++ b/ldiscucs.c @@ -49,19 +49,39 @@ void luni_send(void *handle, wchar_t * widebuf, int len, int interactive) if (in_utf(ldisc->term)) { /* UTF is a simple algorithm */ for (p = linebuffer, i = 0; i < len; i++) { - wchar_t ch = widebuf[i]; - /* We only deal with 16-bit wide chars */ - if ((ch&0xF800) == 0xD800) ch = '.'; + unsigned long ch = widebuf[i]; + + if ((ch & 0xF800) == 0xD800) { +#ifdef PLATFORM_IS_UTF16 + if (i+1 < len) { + unsigned long ch2 = widebuf[i+1]; + if ((ch & 0xFC00) == 0xD800 && + (ch2 & 0xFC00) == 0xDC00) { + ch = 0x10000 + ((ch & 0x3FF) << 10) + (ch2 & 0x3FF); + i++; + } + } else +#endif + { + /* Unrecognised UTF-16 sequence */ + ch = '.'; + } + } if (ch < 0x80) { *p++ = (char) (ch); } else if (ch < 0x800) { - *p++ = (0xC0 | (ch >> 6)); - *p++ = (0x80 | (ch & 0x3F)); + *p++ = (char) (0xC0 | (ch >> 6)); + *p++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x10000) { + *p++ = (char) (0xE0 | (ch >> 12)); + *p++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *p++ = (char) (0x80 | (ch & 0x3F)); } else { - *p++ = (0xE0 | (ch >> 12)); - *p++ = (0x80 | ((ch >> 6) & 0x3F)); - *p++ = (0x80 | (ch & 0x3F)); + *p++ = (char) (0xF0 | (ch >> 18)); + *p++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *p++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *p++ = (char) (0x80 | (ch & 0x3F)); } } } else {