MCPcopy Create free account
hub / github.com/comaps/comaps / Truncate

Function Truncate

libs/base/string_utils.cpp:267–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267bool Truncate(std::string & utf8, size_t const maxTextLengthPlus1)
268{
269 size_t codePoints = 0;
270
271 for (size_t i = 0; i < utf8.length(); ++i)
272 {
273 if ((utf8[i] & 0xC0) != 0x80)
274 {
275 if (++codePoints == maxTextLengthPlus1)
276 {
277 --i;
278
279 auto const & byte = utf8[i];
280 uint8_t bytesInCodepoint = 1;
281
282 if ((byte & 0x80) == 0x00)
283 {}
284 else if ((byte & 0xE0) == 0xC0)
285 bytesInCodepoint = 2;
286 else if ((byte & 0xF0) == 0xE0)
287 bytesInCodepoint = 3;
288 else if ((byte & 0xF8) == 0xF0)
289 bytesInCodepoint = 4;
290
291 utf8.resize(i + bytesInCodepoint);
292 return true;
293 }
294 }
295 }
296 return false;
297}
298
299bool ReplaceFirst(std::string & str, std::string const & from, std::string const & to)
300{

Callers 2

AddChangesetTagMethod · 0.85
InitMethod · 0.85

Calls 2

lengthMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected