mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-18 11:31:00 -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:
7
misc.h
7
misc.h
@ -254,15 +254,16 @@ unsigned smemeq(const void *av, const void *bv, size_t len);
|
||||
char *encode_wide_string_as_utf8(const wchar_t *wstr);
|
||||
|
||||
/* Decode a single UTF-8 character. Returns U+FFFD for any of the
|
||||
* illegal cases. */
|
||||
unsigned long decode_utf8(const char **utf8);
|
||||
* illegal cases. If the source is empty, returns L'\0' (and sets the
|
||||
* error indicator on the source, of course). */
|
||||
unsigned decode_utf8(BinarySource *src);
|
||||
|
||||
/* Decode a single UTF-8 character to an output buffer of the
|
||||
* platform's wchar_t. May write a pair of surrogates if
|
||||
* sizeof(wchar_t) == 2, assuming that in that case the wide string is
|
||||
* encoded in UTF-16. Otherwise, writes one character. Returns the
|
||||
* number written. */
|
||||
size_t decode_utf8_to_wchar(const char **utf8, wchar_t *out);
|
||||
size_t decode_utf8_to_wchar(BinarySource *src, wchar_t *out);
|
||||
|
||||
/* Write a string out in C string-literal format. */
|
||||
void write_c_string_literal(FILE *fp, ptrlen str);
|
||||
|
Reference in New Issue
Block a user