MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ previous_codepoint_offset()

MAYAFLUX_API size_t MayaFlux::Portal::Text::previous_codepoint_offset ( std::string_view  text,
size_t  byte_offset 
)

Byte offset of the codepoint boundary before byte_offset.

Walks backward over continuation-pattern bytes to the start of the preceding codepoint. Returns 0 if byte_offset is already 0.

Parameters
textUTF-8 encoded string.
byte_offsetCurrent byte offset, must be a codepoint boundary.
Returns
Byte offset of the previous codepoint boundary.

Definition at line 198 of file TypeSetter.cpp.

199{
200 if (byte_offset == 0) {
201 return 0;
202 }
203
204 size_t pos = byte_offset - 1;
205 constexpr size_t max_continuation_bytes = 3;
206 size_t steps = 0;
207
208 while (pos > 0 && steps < max_continuation_bytes
209 && (static_cast<uint8_t>(text[pos]) & 0xC0) == 0x80) {
210 --pos;
211 ++steps;
212 }
213
214 return pos;
215}

Referenced by erase(), index_at(), and move().

+ Here is the caller graph for this function: