libctru  v2.4.1
Functions
utf.h File Reference

UTF conversion functions. More...

#include <stdint.h>
#include <sys/types.h>

Go to the source code of this file.

Functions

ssize_t decode_utf8 (uint32_t *out, const uint8_t *in)
 Convert a UTF-8 sequence into a UTF-32 codepoint. More...
 
ssize_t decode_utf16 (uint32_t *out, const uint16_t *in)
 Convert a UTF-16 sequence into a UTF-32 codepoint. More...
 
ssize_t encode_utf8 (uint8_t *out, uint32_t in)
 Convert a UTF-32 codepoint into a UTF-8 sequence. More...
 
ssize_t encode_utf16 (uint16_t *out, uint32_t in)
 Convert a UTF-32 codepoint into a UTF-16 sequence. More...
 
ssize_t utf8_to_utf16 (uint16_t *out, const uint8_t *in, size_t len)
 Convert a UTF-8 sequence into a UTF-16 sequence. More...
 
ssize_t utf8_to_utf32 (uint32_t *out, const uint8_t *in, size_t len)
 Convert a UTF-8 sequence into a UTF-32 sequence. More...
 
ssize_t utf16_to_utf8 (uint8_t *out, const uint16_t *in, size_t len)
 Convert a UTF-16 sequence into a UTF-8 sequence. More...
 
ssize_t utf16_to_utf32 (uint32_t *out, const uint16_t *in, size_t len)
 Convert a UTF-16 sequence into a UTF-32 sequence. More...
 
ssize_t utf32_to_utf8 (uint8_t *out, const uint32_t *in, size_t len)
 Convert a UTF-32 sequence into a UTF-8 sequence. More...
 
ssize_t utf32_to_utf16 (uint16_t *out, const uint32_t *in, size_t len)
 Convert a UTF-32 sequence into a UTF-16 sequence. More...
 

Detailed Description

UTF conversion functions.

Function Documentation

◆ decode_utf16()

ssize_t decode_utf16 ( uint32_t *  out,
const uint16_t *  in 
)

Convert a UTF-16 sequence into a UTF-32 codepoint.

Parameters
[out]outOutput codepoint
[in]inInput sequence
Returns
number of input code units consumed
-1 for error

◆ decode_utf8()

ssize_t decode_utf8 ( uint32_t *  out,
const uint8_t *  in 
)

Convert a UTF-8 sequence into a UTF-32 codepoint.

Parameters
[out]outOutput codepoint
[in]inInput sequence
Returns
number of input code units consumed
-1 for error

◆ encode_utf16()

ssize_t encode_utf16 ( uint16_t *  out,
uint32_t  in 
)

Convert a UTF-32 codepoint into a UTF-16 sequence.

Parameters
[out]outOutput sequence
[in]inInput codepoint
Returns
number of output code units produced
-1 for error
Note
out must be able to store 2 code units

◆ encode_utf8()

ssize_t encode_utf8 ( uint8_t *  out,
uint32_t  in 
)

Convert a UTF-32 codepoint into a UTF-8 sequence.

Parameters
[out]outOutput sequence
[in]inInput codepoint
Returns
number of output code units produced
-1 for error
Note
out must be able to store 4 code units

◆ utf16_to_utf32()

ssize_t utf16_to_utf32 ( uint32_t *  out,
const uint16_t *  in,
size_t  len 
)

Convert a UTF-16 sequence into a UTF-32 sequence.

Fills the output buffer up to len code units. Returns the number of code units that the input would produce; if it returns greater than len, the output has been truncated.

Parameters
[out]outOutput sequence
[in]inInput sequence (null-terminated)
[in]lenOutput length
Returns
number of output code units produced
-1 for error
Note
out is not null-terminated

◆ utf16_to_utf8()

ssize_t utf16_to_utf8 ( uint8_t *  out,
const uint16_t *  in,
size_t  len 
)

Convert a UTF-16 sequence into a UTF-8 sequence.

Fills the output buffer up to len code units. Returns the number of code units that the input would produce; if it returns greater than len, the output has been truncated.

Parameters
[out]outOutput sequence
[in]inInput sequence (null-terminated)
[in]lenOutput length
Returns
number of output code units produced
-1 for error
Note
out is not null-terminated

◆ utf32_to_utf16()

ssize_t utf32_to_utf16 ( uint16_t *  out,
const uint32_t *  in,
size_t  len 
)

Convert a UTF-32 sequence into a UTF-16 sequence.

Parameters
[out]outOutput sequence
[in]inInput sequence (null-terminated)
[in]lenOutput length
Returns
number of output code units produced
-1 for error
Note
out is not null-terminated

◆ utf32_to_utf8()

ssize_t utf32_to_utf8 ( uint8_t *  out,
const uint32_t *  in,
size_t  len 
)

Convert a UTF-32 sequence into a UTF-8 sequence.

Fills the output buffer up to len code units. Returns the number of code units that the input would produce; if it returns greater than len, the output has been truncated.

Parameters
[out]outOutput sequence
[in]inInput sequence (null-terminated)
[in]lenOutput length
Returns
number of output code units produced
-1 for error
Note
out is not null-terminated

◆ utf8_to_utf16()

ssize_t utf8_to_utf16 ( uint16_t *  out,
const uint8_t *  in,
size_t  len 
)

Convert a UTF-8 sequence into a UTF-16 sequence.

Fills the output buffer up to len code units. Returns the number of code units that the input would produce; if it returns greater than len, the output has been truncated.

Parameters
[out]outOutput sequence
[in]inInput sequence (null-terminated)
[in]lenOutput length
Returns
number of output code units produced
-1 for error
Note
out is not null-terminated

◆ utf8_to_utf32()

ssize_t utf8_to_utf32 ( uint32_t *  out,
const uint8_t *  in,
size_t  len 
)

Convert a UTF-8 sequence into a UTF-32 sequence.

Fills the output buffer up to len code units. Returns the number of code units that the input would produce; if it returns greater than len, the output has been truncated.

Parameters
[out]outOutput sequence
[in]inInput sequence (null-terminated)
[in]lenOutput length
Returns
number of output code units produced
-1 for error
Note
out is not null-terminated