1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00
Files
winscp/source/putty/utils/encode_wide_string_as_utf8.c
Martin Prikryl 6c12cb97d7 PuTTY 0.82 + Giving up on trying to not-link PuTTY unicode implementation
Source commit: 510b30d0a40b051c780d3d3e69b3b57cf4e25a05
2024-12-05 14:57:30 +01:00

24 lines
594 B
C

/*
* Encode a string of wchar_t as UTF-8.
*/
#include "putty.h"
#include "misc.h"
char *encode_wide_string_as_utf8(const wchar_t *ws)
{
strbuf *sb = strbuf_new();
while (*ws) {
unsigned long ch = *ws++;
if (sizeof(wchar_t) == 2 && IS_HIGH_SURROGATE(ch) &&
IS_LOW_SURROGATE(*ws)) {
ch = FROM_SURROGATES(ch, *ws);
ws++;
} else if (IS_SURROGATE(ch)) {
ch = 0xfffd; /* illegal UTF-16 -> REPLACEMENT CHARACTER */
}
put_utf8_char(sb, ch);
}
return strbuf_to_str(sb);
}