MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / sam3_codepoint_to_utf8

Function sam3_codepoint_to_utf8

sam3.cpp:1108–1126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1106}
1107
1108static std::string sam3_codepoint_to_utf8(int cp) {
1109 std::string s;
1110 if (cp < 0x80) {
1111 s += (char)cp;
1112 } else if (cp < 0x800) {
1113 s += (char)(0xC0 | (cp >> 6));
1114 s += (char)(0x80 | (cp & 0x3F));
1115 } else if (cp < 0x10000) {
1116 s += (char)(0xE0 | (cp >> 12));
1117 s += (char)(0x80 | ((cp >> 6) & 0x3F));
1118 s += (char)(0x80 | (cp & 0x3F));
1119 } else {
1120 s += (char)(0xF0 | (cp >> 18));
1121 s += (char)(0x80 | ((cp >> 12) & 0x3F));
1122 s += (char)(0x80 | ((cp >> 6) & 0x3F));
1123 s += (char)(0x80 | (cp & 0x3F));
1124 }
1125 return s;
1126}
1127
1128// Check if position i in s starts a Unicode letter.
1129// Handles ASCII letters + treats any multibyte UTF-8 start byte as a letter.

Callers 1

sam3_init_byte_encoderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected