Skip to content

cvedia::rt::utf8

Functions

Name
bool isAscii(unsigned char c)
Returns true if the byte is in the ASCII range (0x00-0x7F).
int sequenceLength(unsigned char leadByte)
Returns the number of bytes in a UTF-8 sequence starting with the given lead byte. Returns 1 for ASCII, 2-4 for valid multi-byte leads, 0 for invalid/continuation bytes.
std::string toLowerAscii(std::string const & val)
ASCII-safe tolower: transforms only ASCII bytes, passes multi-byte UTF-8 through unchanged.
std::string toUpperAscii(std::string const & val)
ASCII-safe toupper: transforms only ASCII bytes, passes multi-byte UTF-8 through unchanged.
std::string capitalizeFirstAscii(std::string const & val)
Capitalize the first character of a string, only if it is ASCII. Multi-byte UTF-8 lead bytes are left untouched.
bool iequalsAscii(std::string const & a, std::string const & b)
ASCII case-insensitive string comparison, safe for UTF-8 strings. Non-ASCII bytes are compared as-is (exact byte match required).
bool iequalsAscii(std::string const & a, char const * b)
ASCII case-insensitive comparison against a C string literal.
std::string trimAsciiWhitespace(std::string const & str)
Trim ASCII whitespace (0x09-0x0D, 0x20) from both ends of a UTF-8 string. Non-ASCII bytes are never considered whitespace.
std::string sanitizeKeepMultibyte(std::string const & input, std::string const & allowedAsciiChars ="-() ", char replacement ='')
Sanitize a UTF-8 string for use as an identifier.

Functions Documentation

function isAscii

inline bool isAscii(
    unsigned char c
)

Returns true if the byte is in the ASCII range (0x00-0x7F).

function sequenceLength

inline int sequenceLength(
    unsigned char leadByte
)

Returns the number of bytes in a UTF-8 sequence starting with the given lead byte. Returns 1 for ASCII, 2-4 for valid multi-byte leads, 0 for invalid/continuation bytes.

function toLowerAscii

inline std::string toLowerAscii(
    std::string const & val
)

ASCII-safe tolower: transforms only ASCII bytes, passes multi-byte UTF-8 through unchanged.

function toUpperAscii

inline std::string toUpperAscii(
    std::string const & val
)

ASCII-safe toupper: transforms only ASCII bytes, passes multi-byte UTF-8 through unchanged.

function capitalizeFirstAscii

inline std::string capitalizeFirstAscii(
    std::string const & val
)

Capitalize the first character of a string, only if it is ASCII. Multi-byte UTF-8 lead bytes are left untouched.

function iequalsAscii

inline bool iequalsAscii(
    std::string const & a,
    std::string const & b
)

ASCII case-insensitive string comparison, safe for UTF-8 strings. Non-ASCII bytes are compared as-is (exact byte match required).

function iequalsAscii

inline bool iequalsAscii(
    std::string const & a,
    char const * b
)

ASCII case-insensitive comparison against a C string literal.

function trimAsciiWhitespace

inline std::string trimAsciiWhitespace(
    std::string const & str
)

Trim ASCII whitespace (0x09-0x0D, 0x20) from both ends of a UTF-8 string. Non-ASCII bytes are never considered whitespace.

function sanitizeKeepMultibyte

inline std::string sanitizeKeepMultibyte(
    std::string const & input,
    std::string const & allowedAsciiChars ="_-() ",
    char replacement ='_'
)

Sanitize a UTF-8 string for use as an identifier.

Parameters:

  • input The input string to sanitize
  • allowedAsciiChars Additional ASCII characters to allow (besides alphanumeric)
  • replacement Character to substitute for disallowed/invalid bytes

ASCII bytes: keeps alphanumeric characters and any characters in allowedAsciiChars. Non-ASCII: preserves valid multi-byte UTF-8 sequences intact. Invalid bytes: replaced with the replacement character.