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] | out | Output codepoint
  [in] | in | Input 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] | out | Output codepoint
  [in] | in | Input 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] | out | Output sequence
  [in] | in | Input 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] | out | Output sequence
  [in] | in | Input 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] | out | Output sequence
  [in] | in | Input sequence (null-terminated)
  [in] | len | Output 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] | out | Output sequence
  [in] | in | Input sequence (null-terminated)
  [in] | len | Output 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] | out | Output sequence
  [in] | in | Input sequence (null-terminated)
  [in] | len | Output 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] | out | Output sequence
  [in] | in | Input sequence (null-terminated)
  [in] | len | Output 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] | out | Output sequence
  [in] | in | Input sequence (null-terminated)
  [in] | len | Output 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] | out | Output sequence
  [in] | in | Input sequence (null-terminated)
  [in] | len | Output length

Returns
  number of output code units produced
  -1 for error

Note
  out is not null-terminated