Yate

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | List of all members
UChar Class Reference

A single Unicode character. More...

`#include <yateclass.h>`

## Public Types
enum | Endianness { LE = 0, BE = 1, Native = 2 }

## Public Member Functions
| UChar (uint32_t code=0)
| UChar (int32_t code)
| UChar (signed char code)
| UChar (unsigned char code)
UChar & | operator= (uint32_t code)
UChar & | operator= (char code)
uint32_t | code () const
const char * | c_str () const
| operator const char * () const
bool | decode (const char *&str, uint32_t maxChar=0x10ffff, bool overlong=false)
bool | decode (uint16_t *&buff, unsigned int &len, Endianness order, uint32_t maxChar=0x10ffff)
bool | decode (DataBlock &buff, Endianness order, uint32_t maxChar=0x10ffff)
bool | encode (uint16_t *&buff, unsigned int &len, Endianness order)
bool | encode (DataBlock &buff, Endianness order)

## Static Public Member Functions
static bool | decode (String &out, uint16_t *&buff, unsigned int &len, Endianness order, bool checkBOM=false, uint32_t maxChar=0x10ffff)
static bool | encode (DataBlock &out, const char *&str, Endianness order, bool addBOM=false)
static bool | encode (uint16_t *&buff, unsigned int &len, const char *&str, Endianness order, bool addBOM=false)

## Detailed Description

A single Unicode character.

A simple class to hold a single Unicode character and convert it to / from UTF-8

## Constructor & Destructor Documentation

UChar | ( | uint32_t | code = `0` | ) |
| inline explicit

Constructor from unsigned numeric code

Parameters

  code | Code of the Unicode character

References UChar::encode().

UChar | ( | int32_t | code | ) |
| inline explicit

Constructor from signed numeric code

Parameters

  code | Code of the Unicode character

References UChar::encode().

UChar | ( | signed char | code | ) |
| inline explicit

Constructor from signed character

Parameters

  code | Character to construct from

References UChar::encode().

UChar | ( | unsigned char | code | ) |
| inline explicit

Constructor from unsigned character

Parameters

  code | Character to construct from

References UChar::encode().

## Member Function Documentation

const char* c_str | ( |  | ) | const
| inline

Get the value of the character as UTF-8 string.

Returns
  The character as UTF-8 C string

uint32_t code | ( |  | ) | const
| inline

Get the Unicode value of the character

Returns
  Code of the character as defined by Unicode

Referenced by UChar::operator=().

bool decode | ( | const char *& | str,
|  | uint32_t | maxChar = `0x10ffff`,
|  | bool | overlong = `false`
| ) |  |

Decode the first Unicode character from an UTF-8 C string

Parameters

  str | String to extract from, will be advanced past the character
  maxChar | Maximum accepted Unicode character code
  overlong | Accept overlong UTF-8 sequences (dangerous!)

Returns
  True if an Unicode character was decoded from string

bool decode | ( | uint16_t *& | buff,
|  | unsigned int & | len,
|  | Endianness | order,
|  | uint32_t | maxChar = `0x10ffff`
| ) |  |

Decode the first Unicode character from an UTF-16 string

Parameters

  buff | Input buffer, advanced if decoding succeeds
  len | Length of input buffer, updated if decoding succeeds
  order | Endianness to use for decoding the character
  maxChar | Maximum accepted Unicode character code

Returns
  True if decoding succeeded, false otherwise

bool decode | ( | DataBlock & | buff,
|  | Endianness | order,
|  | uint32_t | maxChar = `0x10ffff`
| ) |  |

Decode the first Unicode character from an UTF-16 string

Parameters

  buff | Input buffer from which to decode the character
  order | Endianness to use for decoding the character
  maxChar | Maximum accepted Unicode character code

Returns
  True if decoding succeeded, false otherwise

static bool decode | ( | String & | out,
|  | uint16_t *& | buff,
|  | unsigned int & | len,
|  | Endianness | order,
|  | bool | checkBOM = `false`,
|  | uint32_t | maxChar = `0x10ffff`
| ) |  |
| static

Decode a UTF-16 encoded string

Parameters

  out | String to append the decoded characters to
  buff | Input buffer to decode, advanced as decoding occurs
  len | Length of input buffer, decremented as decoding occurs
  order | Endianness to use for decoding
  checkBOM | Check for presence of BOM and interpret accordingly if present
  maxChar | Maximum accepted Unicode character code

Returns
  True if decoding succeeded, false otherwise

bool encode | ( | uint16_t *& | buff,
|  | unsigned int & | len,
|  | Endianness | order
| ) |  |

Encode the Unicode character to UTF-16 into a given buffer

Parameters

  buff | Buffer where to put encoded character, advanced after encoding
  len | Available space in given buffer, updated after encoding
  order | Endianness to use for encoding the character

Returns
  True if decoding succeeded, false otherwise

Referenced by UChar::operator=(), and UChar::UChar().

bool encode | ( | DataBlock & | buff,
|  | Endianness | order
| ) |  |

Encode the Unicode character to UTF-16 into a DataBlock

Parameters

  buff | DataBlock to which the encoded character is to be appended
  order | Endianness to use for encoding the character

Returns
  True if decoding succeeded, false otherwise

static bool encode | ( | DataBlock & | out,
|  | const char *& | str,
|  | Endianness | order,
|  | bool | addBOM = `false`
| ) |  |
| static

Encode a string to UTF-16

Parameters

  out | DataBlock to which encoded data is to be appended
  str | String to be encoded
  order | Endianness to use for encoding the character
  addBOM | True to add BOM to the resulting encoding

Returns
  True if encoding succeeded, false otherwise

static bool encode | ( | uint16_t *& | buff,
|  | unsigned int & | len,
|  | const char *& | str,
|  | Endianness | order,
|  | bool | addBOM = `false`
| ) |  |
| static

Encode a string to UTF-16 into a given buffer

Parameters

  buff | Buffer where to put encoded character, advanced after encoding
  len | Available space in given buffer, updated after encoding
  str | String to be encoded
  order | Endianness to use for encoding the character
  addBOM | True to add BOM to the resulting encoding

Returns
  True if encoding succeeded, false otherwise

operator const char * | ( |  | ) | const
| inline

Conversion to "const char *" operator.

Returns
  Pointer to the internally stored UTF-8 string

UChar& operator= | ( | uint32_t | code | ) |
| inline

Assignment operator from a character code

Parameters

  code | Character code to assign

Returns
  Reference to this object

References UChar::code(), and UChar::encode().

UChar& operator= | ( | char | code | ) |
| inline

Assignment operator from a character

Parameters

  code | Character to assign

Returns
  Reference to this object

References UChar::encode().

The documentation for this class was generated from the following file:

- yateclass.h