Yate
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)
 
UCharoperator= (uint32_t code)
 
UCharoperator= (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)
inlineexplicit

Constructor from unsigned numeric code

Parameters
codeCode of the Unicode character

References UChar::encode().

UChar ( int32_t  code)
inlineexplicit

Constructor from signed numeric code

Parameters
codeCode of the Unicode character

References UChar::encode().

UChar ( signed char  code)
inlineexplicit

Constructor from signed character

Parameters
codeCharacter to construct from

References UChar::encode().

UChar ( unsigned char  code)
inlineexplicit

Constructor from unsigned character

Parameters
codeCharacter 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
strString to extract from, will be advanced past the character
maxCharMaximum accepted Unicode character code
overlongAccept 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
buffInput buffer, advanced if decoding succeeds
lenLength of input buffer, updated if decoding succeeds
orderEndianness to use for decoding the character
maxCharMaximum 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
buffInput buffer from which to decode the character
orderEndianness to use for decoding the character
maxCharMaximum 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
outString to append the decoded characters to
buffInput buffer to decode, advanced as decoding occurs
lenLength of input buffer, decremented as decoding occurs
orderEndianness to use for decoding
checkBOMCheck for presence of BOM and interpret accordingly if present
maxCharMaximum 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
buffBuffer where to put encoded character, advanced after encoding
lenAvailable space in given buffer, updated after encoding
orderEndianness 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
buffDataBlock to which the encoded character is to be appended
orderEndianness 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
outDataBlock to which encoded data is to be appended
strString to be encoded
orderEndianness to use for encoding the character
addBOMTrue 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
buffBuffer where to put encoded character, advanced after encoding
lenAvailable space in given buffer, updated after encoding
strString to be encoded
orderEndianness to use for encoding the character
addBOMTrue 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
codeCharacter 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
codeCharacter to assign
Returns
Reference to this object

References UChar::encode().


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