A lightweight Character class (32 bits). More...

#include <cxxtools/char.h>

Public Types

typedef int32_t value_type

Public Member Functions

 Char ()
 Constructs a character with a value of 0.
 Char (value_type ch)
 Constructs a character using the given value as base for the character value.
char narrow (char def= '?') const
 Narrows this character into an 8-bit char if possible.
wchar_t toWchar () const
Charoperator= (const Char &ch)
value_type value () const
 Returns the internal value (unsigned 32 bits) of this character.
 operator value_type () const
 This conversion operator converts the internal value of this character to unsigned 32 bits.

Static Public Member Functions

static Char null ()

Friends

bool operator== (const Char &a, const Char &b)
 Returns $true$ if the a and b are the same character; $false$ otherwise.
bool operator== (const Char &a, wchar_t b)
bool operator== (wchar_t a, const Char &b)
bool operator== (const Char &a, char b)
bool operator== (char a, const Char &b)
bool operator!= (const Char &a, const Char &b)
 Returns $true$ if the a and b are not the same character; $false$ otherwise.
bool operator!= (const Char &a, wchar_t b)
bool operator!= (wchar_t a, const Char &b)
bool operator!= (const Char &a, char b)
bool operator!= (char a, const Char &b)
bool operator< (const Char &a, const Char &b)
 Returns $true$ if the numeric value of a is less than the numeric value of b; $false$ otherwise.
bool operator< (const Char &a, wchar_t b)
bool operator< (wchar_t a, const Char &b)
bool operator< (const Char &a, char b)
bool operator< (char a, const Char &b)
bool operator> (const Char &a, const Char &b)
 Returns $true$ if the numeric value of a is greater than the numeric value of b; $false$ otherwise.
bool operator> (const Char &a, wchar_t b)
bool operator> (wchar_t a, const Char &b)
bool operator> (const Char &a, char b)
bool operator> (char a, const Char &b)
bool operator<= (const Char &a, const Char &b)
 Returns $true$ if the numeric value of a is equal or less than the numeric value of b; $false$ otherwise.
bool operator<= (const Char &a, wchar_t b)
bool operator<= (wchar_t a, const Char &b)
bool operator<= (const Char &a, char b)
bool operator<= (char a, const Char &b)
bool operator>= (const Char &a, const Char &b)
 Returns $true$ if the numeric value of a is equals or greater than the numeric value of b; $false$ otherwise.
bool operator>= (const Char &a, wchar_t b)
bool operator>= (wchar_t a, const Char &b)
bool operator>= (const Char &a, char b)
bool operator>= (char a, const Char &b)

Detailed Description

A lightweight Character class (32 bits).

Unicode characters are 32-bit entities. This class represents such an entity. It is lightweight, so it can be used everywhere. Most compilers treat it like an unsigned int of 32 bits.

This class provides methods for testing/classification, converting to and from other formats, comparing and case-converting. To convert a character or number to a instance of this class use one of the constructors provided. To check the type of the character use one of the method starting with "is", like isLetter() or isDigit(). To compare lower- or upper-case use isUpper() and isLower(). To compare two characters the corresponding operators are overloaded accordingly. Addition and substraction is supported as well. Comparison of numeric values (>, <, ==) is supported when using these operators.

The classification methods operate on the full range of Unicode characters. All methods return $true$ if the character is a certain type of character. These methods are are wrappers around category() which return the Unicode-defined category of each character.

Comparison is critical in Unicode as it covers the characters of the entire world where characters which look the same may be different in the thinking of numeric values (aka positions in the Unicode table) Comparing characters will compare based purely on the numeric Unicode value (code point) of the characters. Upper- and lower-casing using upper() and lower() will only work if the character has a well-defined upper/lower-case equivalent.

See Also
Category

Member Typedef Documentation

typedef int32_t cxxtools::Char::value_type

Constructor & Destructor Documentation

cxxtools::Char::Char ( )
inline

Constructs a character with a value of 0.

cxxtools::Char::Char ( value_type  ch)
inline

Constructs a character using the given value as base for the character value.

Member Function Documentation

char cxxtools::Char::narrow ( char  def = '?') const
inline

Narrows this character into an 8-bit char if possible.

If the character can not be converted into an 8-bit char because its value is greater than 255, the defaultCharacter which is passed to this method is returned.

If this character is equal or lower than 255 the character is cast to char.

Parameters
defThe default character which is returned if this character can not be narrowed
Returns
An 8-bit char which is a narrowed representation of this character object or the default character if this character object's value is out of range (>255).
static Char cxxtools::Char::null ( )
inlinestatic
cxxtools::Char::operator value_type ( ) const
inline

This conversion operator converts the internal value of this character to unsigned 32 bits.

As the internal value also is an unsigned 32-bit value, the internal value of this character ist returned.

Returns
The character converted to unsigned 32-bit.
Char& cxxtools::Char::operator= ( const Char ch)
inline
wchar_t cxxtools::Char::toWchar ( ) const
inline
value_type cxxtools::Char::value ( ) const
inline

Returns the internal value (unsigned 32 bits) of this character.

Returns
The 32-bit-value of this character.

Friends And Related Function Documentation

bool operator!= ( const Char a,
const Char b 
)
friend

Returns $true$ if the a and b are not the same character; $false$ otherwise.

Returns
$true$ if the a and b are not the same character; $false$ otherwise.
bool operator!= ( const Char a,
wchar_t  b 
)
friend
bool operator!= ( wchar_t  a,
const Char b 
)
friend
bool operator!= ( const Char a,
char  b 
)
friend
bool operator!= ( char  a,
const Char b 
)
friend
bool operator< ( const Char a,
const Char b 
)
friend

Returns $true$ if the numeric value of a is less than the numeric value of b; $false$ otherwise.

Returns
$true$ if the numeric value of a is less than the numeric value of b; $false$ otherwise.
bool operator< ( const Char a,
wchar_t  b 
)
friend
bool operator< ( wchar_t  a,
const Char b 
)
friend
bool operator< ( const Char a,
char  b 
)
friend
bool operator< ( char  a,
const Char b 
)
friend
bool operator<= ( const Char a,
const Char b 
)
friend

Returns $true$ if the numeric value of a is equal or less than the numeric value of b; $false$ otherwise.

Returns
$true$ if the numeric value of a is equal or less than the numeric value of b; $false$ otherwise.
bool operator<= ( const Char a,
wchar_t  b 
)
friend
bool operator<= ( wchar_t  a,
const Char b 
)
friend
bool operator<= ( const Char a,
char  b 
)
friend
bool operator<= ( char  a,
const Char b 
)
friend
bool operator== ( const Char a,
const Char b 
)
friend

Returns $true$ if the a and b are the same character; $false$ otherwise.

Returns
$true$ if the a and b are the same character; $false$ otherwise.
bool operator== ( const Char a,
wchar_t  b 
)
friend
bool operator== ( wchar_t  a,
const Char b 
)
friend
bool operator== ( const Char a,
char  b 
)
friend
bool operator== ( char  a,
const Char b 
)
friend
bool operator> ( const Char a,
const Char b 
)
friend

Returns $true$ if the numeric value of a is greater than the numeric value of b; $false$ otherwise.

Returns
$true$ if the numeric value of a is greater than the numeric value of b; $false$ otherwise.
bool operator> ( const Char a,
wchar_t  b 
)
friend
bool operator> ( wchar_t  a,
const Char b 
)
friend
bool operator> ( const Char a,
char  b 
)
friend
bool operator> ( char  a,
const Char b 
)
friend
bool operator>= ( const Char a,
const Char b 
)
friend

Returns $true$ if the numeric value of a is equals or greater than the numeric value of b; $false$ otherwise.

Returns
$true$ if the numeric value of a is equals or greater than the numeric value of b; $false$ otherwise.
bool operator>= ( const Char a,
wchar_t  b 
)
friend
bool operator>= ( wchar_t  a,
const Char b 
)
friend
bool operator>= ( const Char a,
char  b 
)
friend
bool operator>= ( char  a,
const Char b 
)
friend

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