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_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

27 lines
772 B
C

/*
* Encode a single code point as UTF-8.
*/
#include "defs.h"
#include "misc.h"
void BinarySink_put_utf8_char(BinarySink *output, unsigned ch)
{
if (ch < 0x80) {
put_byte(output, ch);
} else if (ch < 0x800) {
put_byte(output, 0xC0 | (ch >> 6));
put_byte(output, 0x80 | (ch & 0x3F));
} else if (ch < 0x10000) {
put_byte(output, 0xE0 | (ch >> 12));
put_byte(output, 0x80 | ((ch >> 6) & 0x3F));
put_byte(output, 0x80 | (ch & 0x3F));
} else {
assert(ch <= 0x10FFFF);
put_byte(output, 0xF0 | (ch >> 18));
put_byte(output, 0x80 | ((ch >> 12) & 0x3F));
put_byte(output, 0x80 | ((ch >> 6) & 0x3F));
put_byte(output, 0x80 | (ch & 0x3F));
}
}