MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / utf_charlen

Function utf_charlen

StereoKitC/libraries/unicode.cpp:172–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170///////////////////////////////////////////
171
172size_t utf_charlen(const char* str_utf8) {
173 if (!str_utf8) return 0;
174
175 // Single byte UTF8 characters all start with 0b0, so anything smaller than
176 // 0b1 must be single byte!
177 const unsigned char single_byte = (unsigned char)0b10000000;
178 // The first byte of multibyte UTF8 characters all begin with 0b11, so
179 // anything larger than 0b10111111 is a multibye character indicator!
180 const unsigned char multi_byte = (unsigned char)0b10111111;
181
182 size_t result = 0;
183 const unsigned char* curr = (unsigned char*)str_utf8;
184 while (*curr != '\0') {
185 if (*curr < single_byte || *curr > multi_byte) { result += 1; }
186 curr++;
187 }
188 return result;
189}
190
191///////////////////////////////////////////
192

Callers 1

ui_input_gFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected