MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / insert_utf8_char

Function insert_utf8_char

src/base/string.cpp:104–141  ·  view source on GitHub ↗

Based on Allegro Unicode code (allegro/src/unicode.c)

Source from the content-addressed store, hash-verified

102
103// Based on Allegro Unicode code (allegro/src/unicode.c)
104static std::size_t insert_utf8_char(std::string* result, wchar_t chr)
105{
106 int size, bits, b, i;
107
108 if (chr < 128) {
109 if (result)
110 result->push_back(chr);
111 return 1;
112 }
113
114 bits = 7;
115 while (chr >= (1<<bits))
116 bits++;
117
118 size = 2;
119 b = 11;
120
121 while (b < bits) {
122 size++;
123 b += 5;
124 }
125
126 if (result) {
127 b -= (7-size);
128 int firstbyte = chr>>b;
129 for (i=0; i<size; i++)
130 firstbyte |= (0x80>>i);
131
132 result->push_back(firstbyte);
133
134 for (i=1; i<size; i++) {
135 b -= 6;
136 result->push_back(0x80 | ((chr>>b)&0x3F));
137 }
138 }
139
140 return size;
141}
142
143std::string to_utf8(const std::wstring& src)
144{

Callers 1

to_utf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected