1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-03 04:22:47 -05:00

Make decode_utf8() read from a BinarySource.

This enables it to handle data that isn't presented as a
NUL-terminated string.

In particular, the NUL byte can appear _within_ the string and be
correctly translated to the NUL wide character. So I've been able to
remove the awkwardness in the test rig of having to include the
terminating NUL in every test to ensure NUL has been tested, and
instead, insert a single explicit test for it.

Similarly to the previous commit, the simplification at the (one) call
site gives me a strong feeling of 'this is what the API should have
been all along'!
This commit is contained in:
Simon Tatham
2022-11-09 19:01:04 +00:00
parent d89f2bfc55
commit 69e217d23a
4 changed files with 41 additions and 35 deletions

View File

@ -5,10 +5,10 @@
#include "putty.h"
#include "misc.h"
size_t decode_utf8_to_wchar(const char **utf8, wchar_t *out)
size_t decode_utf8_to_wchar(BinarySource *src, wchar_t *out)
{
size_t outlen = 0;
unsigned wc = decode_utf8(utf8);
unsigned wc = decode_utf8(src);
if (sizeof(wchar_t) > 2 || wc < 0x10000) {
out[outlen++] = wc;
} else {