Enum in stdx_string.h

XUtf8Error

typedef enum XUtf8Error{
  X_UTF8_OK=0,
  X_UTF8_ERR_EOF=-1,
  X_UTF8_ERR_INVALID=-2,
  X_UTF8_ERR_OVERLONG=-3,
  X_UTF8_ERR_RANGE=-4
}XUtf8Error;
Function in stdx_string.h

x_utf8_codepoint_length

Returns the expected byte length for a UTF-8 starter byte.

X_STRING_API int32_t x_utf8_codepoint_length(unsigned char first_byte);

Parameters

unsigned char first_byte
Parameter.

Returns

1..4 for a valid starter byte; negative error code if invalid.

Function in stdx_string.h

x_utf8_codepoint_size

Returns the number of UTF-8 bytes required to encode a codepoint.

X_STRING_API uint32_t x_utf8_codepoint_size(uint32_t codepoint);

Parameters

uint32_t codepoint
Unicode codepoint to measure.

Returns

Number of UTF-8 bytes required, or 0 if the codepoint is invalid.

Function in stdx_string.h

x_utf8_decode

Decodes a single UTF-8 codepoint from the specified byte span.

X_STRING_API int32_t x_utf8_decode(
 const char *ptr,
 const char *end,
 size_t *out_len
);

Parameters

const char *ptr
Current read pointer within the byte span.
const char *end
One-past-the-end pointer for the byte span.
size_t *out_len
Output: number of bytes consumed on success or bytes to skip on error.

Returns

Decoded codepoint on success; negative X_UTF8_ERR_* on failure.

Function in stdx_string.h

x_utf8_encode

Encodes a Unicode codepoint as UTF-8.

X_STRING_API bool x_utf8_encode(
 uint32_t codepoint,
 char out[4],
 uint32_t *out_len
);

Parameters

uint32_t codepoint
Unicode codepoint to encode.
char out[4]
Destination UTF-8 byte buffer (must hold at least 4 bytes).
uint32_t *out_len
Receives the number of UTF-8 bytes written.

Returns

true if the codepoint was encoded successfully, false otherwise.

Function in stdx_string.h

x_utf8_is_single_char

Checks whether the string contains exactly one UTF-8 codepoint.

X_STRING_API bool x_utf8_is_single_char(const char *s);

Parameters

const char *s
Destination small string.

Returns

Function-specific result.

Function in stdx_string.h

x_utf8_next

Advances to the next UTF-8 codepoint boundary.

X_STRING_API uint32_t x_utf8_next(
 char const *text,
 uint32_t offset
);

Parameters

char const *text
UTF-8 encoded string.
uint32_t offset
Current byte offset into the string.

Returns

Byte offset of the next UTF-8 codepoint boundary.

Function in stdx_string.h

x_utf8_prev

Moves to the previous UTF-8 codepoint boundary.

X_STRING_API uint32_t x_utf8_prev(
 char const *text,
 uint32_t offset
);

Parameters

char const *text
UTF-8 encoded string.
uint32_t offset
Current byte offset into the string.

Returns

Byte offset of the previous UTF-8 codepoint boundary.

Function in stdx_string.h

x_utf8_strcmp

Compares two null-terminated UTF-8 strings.

X_STRING_API int32_t x_utf8_strcmp(
 const char *a,
 const char *b
);

Parameters

const char *a
First input view or string.
const char *b
Second input view or string.

Returns

Negative, zero, or positive according to lexicographic order.

Function in stdx_string.h

x_utf8_strlen

Returns the number of UTF-8 codepoints in a null-terminated string.

X_STRING_API size_t x_utf8_strlen(const char *utf8);

Parameters

const char *utf8
Source UTF-8 string.

Returns

Number of UTF-8 codepoints.

Function in stdx_string.h

x_utf8_tolower

Converts ASCII letters to lower case; leaves multibyte UTF-8 unchanged.

X_STRING_API char * x_utf8_tolower(
 char *dest,
 const char *src
);

Parameters

char *dest
Destination buffer.
const char *src
Source buffer or string.

Returns

Function-specific result.

Function in stdx_string.h

x_utf8_toupper

Converts ASCII letters to upper case; leaves multibyte UTF-8 unchanged.

X_STRING_API char * x_utf8_toupper(
 char *dest,
 const char *src
);

Parameters

char *dest
Destination buffer.
const char *src
Source buffer or string.

Returns

Function-specific result.