# transcode.h File Reference

`#include <stdint.h>`

Include dependency graph for transcode.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Data Structures
struct | FAXPP_Transcoder
| Encapsulates the information needed to both decode and encode an encoding. More...
## Defines
#define | TRANSCODE_ERROR 1000
#define | TRANSCODE_PREMATURE_END_OF_BUFFER 1001
#define | TRANSCODE_BAD_ENCODING 1002
## Typedefs
typedef uint32_t | Char32
| A single unicode codepoint.
typedef unsigned int(* | FAXPP_DecodeFunction )(const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single character from the buffer into it's unicode codepoint.
typedef unsigned int(* | FAXPP_EncodeFunction )(void *buffer, void *buffer_end, Char32 ch)
| Encodes a single unicode codepoint into the given buffer.
## Functions
const char * | FAXPP_decode_to_string (FAXPP_DecodeFunction t)
| Returns a string describing the given (built-in) decode function.
const char * | FAXPP_encode_to_string (FAXPP_EncodeFunction t)
| Returns a string describing the given (built-in) encode function.
FAXPP_DecodeFunction | FAXPP_string_to_decode (const char *encodingName)
| Returns a FAXPP_DecodeFunction for the given encoding string, or 0 if one is not supported internally.
FAXPP_EncodeFunction | FAXPP_string_to_encode (const char *encodingName)
| Returns a FAXPP_EncodeFunction for the given encoding string, or 0 if one is not supported internally.
unsigned int | FAXPP_utf8_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single UTF-8 character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_iso_8859_1_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single ISO-8859-1 (Latin1) character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_utf16_le_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single UTF-16 little endian character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_utf16_be_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single UTF-16 big endian character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_utf16_native_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single UTF-16 native endian character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_ucs4_le_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single UCS-4 little endian character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_ucs4_be_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single UCS-4 big endian character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_ucs4_native_decode (const void *buffer, const void *buffer_end, Char32 *ch)
| Decodes a single UCS-4 native endian character from the buffer into it's unicode codepoint.
unsigned int | FAXPP_utf8_encode (void *buffer, void *buffer_end, Char32 ch)
| Encodes a single unicode codepoint as UTF-8 into the given buffer.
unsigned int | FAXPP_utf16_native_encode (void *buffer, void *buffer_end, Char32 ch)
| Encodes a single unicode codepoint as UTF-16 (native endian) into the given buffer.
## Variables
const FAXPP_Transcoder | FAXPP_utf8_transcoder
| Transcoder to and from UTF-8.
const FAXPP_Transcoder | FAXPP_utf16_native_transcoder
| Transcoder to and from native endian UTF-16.

## Define Documentation

#define TRANSCODE_BAD_ENCODING 1002

Definition at line 33 of file transcode.h.

#define TRANSCODE_ERROR 1000

Definition at line 31 of file transcode.h.

#define TRANSCODE_PREMATURE_END_OF_BUFFER 1001

Definition at line 32 of file transcode.h.

## Typedef Documentation

typedef uint32_t Char32

A single unicode codepoint.

Definition at line 29 of file transcode.h.

typedef unsigned int(* FAXPP_DecodeFunction)(const void *buffer, const void *buffer_end, Char32 *ch)

Decodes a single character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_utf8_decode(), FAXPP_utf16_le_decode(), FAXPP_utf16_be_decode(), FAXPP_utf16_native_decode(), FAXPP_ucs4_le_decode(), FAXPP_ucs4_be_decode(), FAXPP_ucs4_native_decode()

Definition at line 53 of file transcode.h.

typedef unsigned int(* FAXPP_EncodeFunction)(void *buffer, void *buffer_end, Char32 ch)

Encodes a single unicode codepoint into the given buffer.

Parameters:

  | buffer | The buffer to encode to
  | buffer_end | A pointer to the end of the buffer
  | ch | The unicode codepoint to encode

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If the buffer does not have enough space to encode the unicode codepoint

See also:
  FAXPP_utf8_encode(), FAXPP_utf16_native_encode()

Definition at line 71 of file transcode.h.

## Function Documentation

const char* FAXPP_decode_to_string | ( | FAXPP_DecodeFunction | t | ) |

Returns a string describing the given (built-in) decode function.

Parameters:

  | t |

Returns:
  a string

const char* FAXPP_encode_to_string | ( | FAXPP_EncodeFunction | t | ) |

Returns a string describing the given (built-in) encode function.

Parameters:

  | t |

Returns:
  a string

unsigned int FAXPP_iso_8859_1_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single ISO-8859-1 (Latin1) character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

FAXPP_DecodeFunction FAXPP_string_to_decode | ( | const char * | encodingName | ) |

Returns a FAXPP_DecodeFunction for the given encoding string, or 0 if one is not supported internally.

Parameters:

  | encodingName | The encoding to look up

Returns:
  a FAXPP_DecodeFunction

FAXPP_EncodeFunction FAXPP_string_to_encode | ( | const char * | encodingName | ) |

Returns a FAXPP_EncodeFunction for the given encoding string, or 0 if one is not supported internally.

Parameters:

  | encodingName | The encoding to look up

Returns:
  a FAXPP_EncodeFunction

unsigned int FAXPP_ucs4_be_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single UCS-4 big endian character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

unsigned int FAXPP_ucs4_le_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single UCS-4 little endian character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

unsigned int FAXPP_ucs4_native_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single UCS-4 native endian character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

unsigned int FAXPP_utf16_be_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single UTF-16 big endian character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

unsigned int FAXPP_utf16_le_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single UTF-16 little endian character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

unsigned int FAXPP_utf16_native_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single UTF-16 native endian character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

unsigned int FAXPP_utf16_native_encode | ( | void * | buffer,
|  | void * | buffer_end,
|  | Char32 | ch |
| ) |  |  |

Encodes a single unicode codepoint as UTF-16 (native endian) into the given buffer.

Parameters:

  | buffer | The buffer to encode to
  | buffer_end | A pointer to the end of the buffer
  | ch | The unicode codepoint to encode

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If the buffer does not have enough space to encode the unicode codepoint

See also:
  FAXPP_EncodeFunction

unsigned int FAXPP_utf8_decode | ( | const void * | buffer,
|  | const void * | buffer_end,
|  | Char32 * | ch |
| ) |  |  |

Decodes a single UTF-8 character from the buffer into it's unicode codepoint.

Parameters:

  | buffer | The buffer to decode from
  | buffer_end | A pointer to the end of the buffer
  `[out]` | ch | The decoded unicode codepoint

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If there is not enough buffer left to decode another character
  | TRANSCODE_BAD_ENCODING | If the the encoding is invalid

See also:
  FAXPP_DecodeFunction

unsigned int FAXPP_utf8_encode | ( | void * | buffer,
|  | void * | buffer_end,
|  | Char32 | ch |
| ) |  |  |

Encodes a single unicode codepoint as UTF-8 into the given buffer.

Parameters:

  | buffer | The buffer to encode to
  | buffer_end | A pointer to the end of the buffer
  | ch | The unicode codepoint to encode

Returns:
  The length of the char, unless it is bigger than TRANSCODE_ERROR, in which case it is an error code.

Return values:

  | TRANSCODE_PREMATURE_END_OF_BUFFER | If the buffer does not have enough space to encode the unicode codepoint

See also:
  FAXPP_EncodeFunction

## Variable Documentation

const FAXPP_Transcoder FAXPP_utf16_native_transcoder

Transcoder to and from native endian UTF-16.

See also:
  FAXPP_utf16_native_decode, FAXPP_utf16_native_encode

const FAXPP_Transcoder FAXPP_utf8_transcoder

Transcoder to and from UTF-8.

See also:
  FAXPP_utf8_decode, FAXPP_utf8_encode

Examples:
  parser_example.c, and tokenizer_example.c.