Miosix  2.0alpha1
miosix::Unicode Class Reference

#include <unicode.h>

Public Types

enum  error { OK, INSUFFICIENT_SPACE, INVALID_STRING }
 

Static Public Member Functions

template<typename Iter >
static char32_t nextUtf8 (Iter &it, Iter end)
 
template<typename Iter >
static char32_t nextUtf8 (Iter &it)
 
static std::pair< error, int > putUtf8 (char *dst, char32_t c, int dstSize)
 
static std::pair< error, int > utf8toutf16 (char16_t *dst, int dstSize, const char *src)
 
static std::pair< error, int > utf16toutf8 (char *dst, int dstSize, const char16_t *src)
 
static std::pair< bool, int > validateUtf8 (const char *str)
 

Static Public Attributes

static const char32_t invalid =0xffffffff
 Represents an invalid code point.
 

Detailed Description

Result codes for unicode related conversion stuff

Member Enumeration Documentation

Possible errors for unicode string conversion

Enumerator
OK 

The string conversion completed successfully.

INSUFFICIENT_SPACE 

The source string is too long to fit.

INVALID_STRING 

The source string is an illegal unicode string.

Member Function Documentation

template<typename Iter >
static char32_t miosix::Unicode::nextUtf8 ( Iter &  it,
Iter  end 
)
inlinestatic

Peek an unicode code point out of an iterator into an utf8 string

Parameters
itan iterator into an utf8 encoded string
enditerator one past the last character of the string
Returns
an unicode code point, or Unicode::invalid if the string contains an invalid code point. Returns 0 if the end of string is found, and it is not in the middle of a character
template<typename Iter >
static char32_t miosix::Unicode::nextUtf8 ( Iter &  it)
inlinestatic

Peek an unicode code point out of an iterator into an utf8 string

Parameters
itan iterator into an utf8 encoded string, the string is assumed to be nul-terminated
Returns
an unicode code point, or Unicode::invalid if the string contains an invalid code point. Returns 0 if the end of string is found, and it is not in the middle of a character
pair< Unicode::error, int > miosix::Unicode::putUtf8 ( char *  dst,
char32_t  c,
int  dstSize 
)
static

Put an unicode code point into a character array, converting it to utf8.

Parameters
dstpointer to the buffer where the character is to be written
can unicode code point (utf32 char)
dstSizenumber of bytes available in dst
Returns
an error code and the number of bytes of dst that were used up to write src to dst
pair< Unicode::error, int > miosix::Unicode::utf16toutf8 ( char *  dst,
int  dstSize,
const char16_t *  src 
)
static

Convert an utf16 string in an utf8 one

Parameters
dstan utf8 string
dstSizesize in bytes of dst, to prevent overflow
srca nul-terminated utf16 string in system-dependent endianness (i.e: little endian in a little endian machine and big endian in a big endian one)
Returns
an error code and the length of the string written to dst
pair< Unicode::error, int > miosix::Unicode::utf8toutf16 ( char16_t *  dst,
int  dstSize,
const char *  src 
)
static

Convert an utf8 string in an utf16 one

Parameters
dstan utf16 string in system-dependent endianness (i.e: little endian in a little endian machine and big endian in a big endian one)
dstSizesize in units of char16_t of dst, to prevent overflow
srca nul-terminated utf8 string
Returns
an error code and the length (in units of char16_t) of the string written to dst
pair< bool, int > miosix::Unicode::validateUtf8 ( const char *  str)
static
Parameters
stran utf8 encoded string
Returns
a pair with a bool that is true if the string is valid, and the string length in bytes, not code points

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