MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / utf8GetCodePointSize

Function utf8GetCodePointSize

src/openrct2/core/String.hpp:186–205  ·  view source on GitHub ↗

* Returns codepoint size or no value if not valid */

Source from the content-addressed store, hash-verified

184 * Returns codepoint size or no value if not valid
185 */
186 constexpr std::optional<int> utf8GetCodePointSize(std::string_view v)
187 {
188 if (!v.empty() && !(v[0] & 0x80))
189 {
190 return { 1 };
191 }
192 if (v.size() >= 2 && ((v[0] & 0xE0) == 0xC0))
193 {
194 return { 2 };
195 }
196 if (v.size() >= 3 && ((v[0] & 0xF0) == 0xE0))
197 {
198 return { 3 };
199 }
200 if (v.size() >= 4 && ((v[0] & 0xF8) == 0xF0))
201 {
202 return { 4 };
203 }
204 return std::nullopt;
205 }
206
207 /**
208 * Truncates a string to at most `size` bytes,

Callers 2

utf8TruncateFunction · 0.85
utf8TruncateCodePointsFunction · 0.85

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected