userver: utils::text::utf8 Namespace Reference
Loading...
Searching...
No Matches
utils::text::utf8 Namespace Reference

Detailed Description

UTF8 text utilities.

Functions

unsigned CodePointLengthByFirstByte (unsigned char c) noexcept
 Returns the length in bytes of the UTF-8 code point by the first byte.
 
bool IsWellFormedCodePoint (const unsigned char *bytes, std::size_t length) noexcept
 bytes must not be a nullptr, length must not be 0.
 
bool IsValid (const unsigned char *bytes, std::size_t length) noexcept
 bytes must not be a nullptr, length must not be 0.
 
std::size_t GetCodePointsCount (std::string_view text)
 
void TrimTruncatedEnding (std::string &str)
 
void TrimViewTruncatedEnding (std::string_view &view)
 
std::size_t GetTextPosByCodePointPos (std::string_view text, std::size_t pos) noexcept
 
void RemovePrefix (std::string &text, std::size_t count) noexcept
 
void RemoveViewPrefix (std::string_view &text, std::size_t count) noexcept
 
void TakePrefix (std::string &text, std::size_t count) noexcept
 
void TakeViewPrefix (std::string_view &text, std::size_t count) noexcept
 

Function Documentation

◆ GetCodePointsCount()

std::size_t utils::text::utf8::GetCodePointsCount ( std::string_view text)

returns number of utf-8 code points, text must be in utf-8 encoding

Exceptions
std::runtime_errorif not a valid UTF8 text

◆ GetTextPosByCodePointPos()

std::size_t utils::text::utf8::GetTextPosByCodePointPos ( std::string_view text,
std::size_t pos )
noexcept

Returns position in text where utf-8 code point with position pos starts OR text.length() if text contains less than or equal to pos points

Warning
this does not check if text is valid utf-8 text

◆ RemovePrefix()

void utils::text::utf8::RemovePrefix ( std::string & text,
std::size_t count )
noexcept

Removes the first count utf-8 code points from text

Warning
this does not check if text is valid utf-8 text

◆ RemoveViewPrefix()

void utils::text::utf8::RemoveViewPrefix ( std::string_view & text,
std::size_t count )
noexcept
See also
void RemovePrefix(std::string& text, std::size_t count)
Warning
this does not change the original string

◆ TakePrefix()

void utils::text::utf8::TakePrefix ( std::string & text,
std::size_t count )
noexcept

Takes the first count utf-8 code points from text

Warning
this does not check if text is valid utf-8 text

◆ TakeViewPrefix()

void utils::text::utf8::TakeViewPrefix ( std::string_view & text,
std::size_t count )
noexcept
See also
void TakePrefix(std::string& text, std::size_t count)
Warning
this does not change the original string

◆ TrimTruncatedEnding()

void utils::text::utf8::TrimTruncatedEnding ( std::string & str)

Removes the longest (possible empty) suffix of str which is a proper prefix of some utf-8 multibyte character. If str is not in utf-8 it may remove some suffix of length up to 3.

◆ TrimViewTruncatedEnding()

void utils::text::utf8::TrimViewTruncatedEnding ( std::string_view & view)
See also
void TrimTruncatedEnding(std::string& str)
Warning
this does not change the original string