1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-18 03:20:59 -05:00

Add a manual single-char UTF-8 decoder.

This parallels encode_utf8 which we already had.

Decoding is more fraught with perils than encoding, so I've also
included a small test program.
This commit is contained in:
Simon Tatham
2022-03-12 15:53:04 +00:00
parent 21f602be40
commit b360ea6ac1
5 changed files with 216 additions and 0 deletions

11
misc.h
View File

@ -221,6 +221,17 @@ size_t encode_utf8(void *output, unsigned long ch);
* encoded in UTF-16. */
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);
/* 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);
/* Write a string out in C string-literal format. */
void write_c_string_literal(FILE *fp, ptrlen str);