UtfString
Public Member Functions | List of all members
UtfString::UnicodeChar Class Reference

Represents a Unicode character in an encoding-neutral way. More...

#include <UnicodeChar.h>

Public Member Functions

 UnicodeChar ()
 Initializes an empty UnicodeChar.
 
 UnicodeChar (const UnicodeChar &character)
 Initializes an instance of UnicodeChar using another instance of UnicodeChar. More...
 
 UnicodeChar (const Utf16Char &character)
 Initializes an instance of UnicodeChar using an instance of Utf16Char. More...
 
 UnicodeChar (const Utf8Char &character)
 Initializes an instance of UnicodeChar using an instance of Utf8Char. More...
 
virtual ~UnicodeChar ()
 The destructor. More...
 
bool operator== (const UnicodeChar &otherCharacter) const
 Compares the value of this character to the value of another character and tests whether the two character values are the same. More...
 
bool operator== (const Utf8Char &character) const
 Compares the value of this character to the value of a UTF-8 character and tests whether the two character Unicode values are the same. More...
 
bool operator== (const Utf16Char &character) const
 Compares the value of this character to the value of a UTF-16 character and tests whether the two character Unicode values are the same. More...
 
bool operator== (const UnicodeCharReference &characterReference) const
 Compares the value of this character to the value of a character reference and tests whether the two character values are the same. More...
 
bool operator== (const Utf8CharReference &characterReference) const
 Compares the value of this character to the value of a UTF-8 character reference and tests whether the two character Unicode values are the same. More...
 
bool operator== (const Utf16CharReference &characterReference) const
 Compares the value of this character to the value of a UTF-16 character reference and tests whether the two character Unicode values are the same. More...
 
bool operator!= (const UnicodeChar &otherCharacter) const
 Compares the value of this character to the value of another character and tests whether the two character values are the different. More...
 
bool operator!= (const Utf8Char &character) const
 Compares the value of this character to the value of a UTF-8 character and tests whether the two character Unicode values are the different. More...
 
bool operator!= (const Utf16Char &character) const
 Compares the value of this character to the value of a UTF-16 character and tests whether the two character Unicode values are the different. More...
 
bool operator!= (const UnicodeCharReference &characterReference) const
 Compares the value of this character to the value of a character reference and tests whether the two character values are the different. More...
 
bool operator!= (const Utf8CharReference &characterReference) const
 Compares the value of this character to the value of a UTF-8 character reference and tests whether the two character Unicode values are the different. More...
 
bool operator!= (const Utf16CharReference &characterReference) const
 Compares the value of this character to the value of a UTF-16 character reference and tests whether the two character Unicode values are the different. More...
 
UnicodeCharoperator= (const UnicodeChar &character)
 Assigns the contents of a UnicodeChar object to this object. More...
 
UnicodeCharoperator= (const Utf8Char &character)
 Assigns the contents of a Utf8Char object to this object. More...
 
UnicodeCharoperator= (const Utf16Char &character)
 Assigns the contents of a Utf16Char object to this object. More...
 
UnicodeCharoperator= (const Utf8CharReference &characterReference)
 Assigns the contents of a Utf8CharReference object to this object. More...
 
UnicodeCharoperator= (const Utf16CharReference &characterReference)
 Assigns the contents of a Utf16CharReference object to this object. More...
 
 operator Utf16Char () const
 Converts this object to a Utf16Char object. More...
 
 operator Utf8Char () const
 Converts this object to a Utf8Char object. More...
 
void clear ()
 Clears the contents of the character, making it an empty character.
 
bool empty () const
 Indicates whether this character is an empty character. More...
 
bool is_valid () const
 Indicates whether this character is a valid Unicode character. More...
 
const UtfEncoding internal_encoding () const
 Indicates the internal encoding used by this character. More...
 
UInt32 to_utf_32 () const
 Converts this character to a UTF-32 code point. More...
 

Detailed Description

Represents a Unicode character in an encoding-neutral way.

The class acts as a thin wrapper that can contain a UTF-8 or UTF-16 character to facilitate an easier handling of characters when dealing with characters in an encoding-neutral fashion.

Since this is an encoding-neutral class, code units cannot be accessed directly. In order to access the individual code units, an instance of this class must be cast to an encoding- specific class, such as Utf8Char or Utf16Char. An instance of this class holds a copy of a character. Changing the value of an instance of this class will not cause anything to be changed anywhere else.

This object can be freely assigned and converted to or from a number of encoding-specific data types. Since a Unicode character must be encoded in some form or another in order to be stored. We could always store the character one particular encoding, but in order avoid the inefficiency of multiple encoding conversions (original character is UTF-16 -> stored as UTF-8 -> converted back to UTF-16), this class will store the character in its original encoding. If you wish to avoid unnecessary encoding conversions, you get the internal encoding by calling GetInternalEncoding().

Constructor & Destructor Documentation

UtfString::UnicodeChar::UnicodeChar ( const UnicodeChar character)

Initializes an instance of UnicodeChar using another instance of UnicodeChar.

This is a copy constructor, and sets the constructed instance to be the same as the UnicodeChar instance passed in as a parameter

Parameters
[in]characterA character to use in initializing this character
UtfString::UnicodeChar::UnicodeChar ( const Utf16Char character)

Initializes an instance of UnicodeChar using an instance of Utf16Char.

Parameters
[in]characterA character to use in initializing this character
UtfString::UnicodeChar::UnicodeChar ( const Utf8Char character)

Initializes an instance of UnicodeChar using an instance of Utf8Char.

Parameters
[in]characterA character to use in initializing this character
virtual UtfString::UnicodeChar::~UnicodeChar ( )
virtual

The destructor.

The destructor will clean up the encoding-specific string contained within this object

Member Function Documentation

bool UtfString::UnicodeChar::empty ( ) const

Indicates whether this character is an empty character.

An empty character is one that doesn't contain any encoding-specific character data. This happens when an instance is not initialized with character data or clear() is called.

const UtfEncoding UtfString::UnicodeChar::internal_encoding ( ) const

Indicates the internal encoding used by this character.

The internal encoding of a UnicodeChar depends on what data is used to initialize the character or what data is assigned to the character when it is empty. If a UnicodeChar is initialized with a UTF-8 character, the internal encoding will be UTF-8. The opposite is the case when a UnicodeCharacter is initialized with a UTF-16 character. This is done to keep encoding conversions to a minimum. If an application is dealing primarily with one encoding, and a character in that encoding is put in a UnicodeString, we avoid the conversion to a specific internal encoding and then the conversion back to the original encoding.

See Also
UnicodeChar::empty()
bool UtfString::UnicodeChar::is_valid ( ) const

Indicates whether this character is a valid Unicode character.

If this object is able to convert the code units given to it during initialization to a Unicode character, this character will be considered valid.

If this character is an empty character, false will be returned.

Returns
true if the code points in this character represent a valid Unicode character, otherwise false
See Also
UnicodeChar::empty()
UtfString::UnicodeChar::operator Utf16Char ( ) const

Converts this object to a Utf16Char object.

This operator assumes that if this character is non-empty, it is a valid Unicode character.

If this object does not contain a character, an empty Utf16Char will be returned

See Also
UnicodeChar::is_valid()
UnicodeChar::empty()
UtfString::UnicodeChar::operator Utf8Char ( ) const

Converts this object to a Utf8Char object.

This operator assumes that if this character is non-empty, it is a valid Unicode character.

If this object does not contain a character, an empty Utf8Char will be returned

See Also
UnicodeChar::is_valid()
UnicodeChar::empty()
bool UtfString::UnicodeChar::operator!= ( const UnicodeChar otherCharacter) const

Compares the value of this character to the value of another character and tests whether the two character values are the different.

Parameters
[in]otherCharacterThe character to be compared with this character
Returns
true if the two character values are different, otherwise false
bool UtfString::UnicodeChar::operator!= ( const Utf8Char character) const

Compares the value of this character to the value of a UTF-8 character and tests whether the two character Unicode values are the different.

Parameters
[in]characterThe UTF-8 character to be compared with this character
Returns
true if the two character Unicode values are different, otherwise false
bool UtfString::UnicodeChar::operator!= ( const Utf16Char character) const

Compares the value of this character to the value of a UTF-16 character and tests whether the two character Unicode values are the different.

Parameters
[in]characterThe UTF-16 character to be compared with this character
Returns
true if the two character Unicode values are different, otherwise false
bool UtfString::UnicodeChar::operator!= ( const UnicodeCharReference characterReference) const

Compares the value of this character to the value of a character reference and tests whether the two character values are the different.

Parameters
[in]characterReferenceThe character reference to be compared with this character reference
Returns
true if the two character values are the different, otherwise false
bool UtfString::UnicodeChar::operator!= ( const Utf8CharReference characterReference) const

Compares the value of this character to the value of a UTF-8 character reference and tests whether the two character Unicode values are the different.

Parameters
[in]characterReferenceThe UTF-8 character reference to be compared with this character
Returns
true if the two character Unicode values are different, otherwise false
bool UtfString::UnicodeChar::operator!= ( const Utf16CharReference characterReference) const

Compares the value of this character to the value of a UTF-16 character reference and tests whether the two character Unicode values are the different.

Parameters
[in]characterReferenceThe UTF-16 character reference to be compared with this character
Returns
true if the two character Unicode values are different, otherwise false
UnicodeChar& UtfString::UnicodeChar::operator= ( const UnicodeChar character)

Assigns the contents of a UnicodeChar object to this object.

The contents of the other UnicodeChar object are copied to this object: they are not shared.

Parameters
[in]characterThe UnicodeChar object whose contents are to be assigned to this object
Returns
A reference to this object
UnicodeChar& UtfString::UnicodeChar::operator= ( const Utf8Char character)

Assigns the contents of a Utf8Char object to this object.

Parameters
[in]characterThe Utf8Char object whose contents are to be assigned to this object
Returns
A reference to this object
UnicodeChar& UtfString::UnicodeChar::operator= ( const Utf16Char character)

Assigns the contents of a Utf16Char object to this object.

Parameters
[in]characterThe Utf16Char object whose contents are to be assigned to this object
Returns
A reference to this object
UnicodeChar& UtfString::UnicodeChar::operator= ( const Utf8CharReference characterReference)

Assigns the contents of a Utf8CharReference object to this object.

Parameters
[in]characterReferenceThe Utf8CharReference object whose contents are to be assigned to this object
Returns
A reference to this object
UnicodeChar& UtfString::UnicodeChar::operator= ( const Utf16CharReference characterReference)

Assigns the contents of a Utf16CharReference object to this object.

Parameters
[in]characterReferenceThe Utf16CharReference object whose contents are to be assigned to this object
Returns
A reference to this object
bool UtfString::UnicodeChar::operator== ( const UnicodeChar otherCharacter) const

Compares the value of this character to the value of another character and tests whether the two character values are the same.

Parameters
[in]otherCharacterThe character to be compared with this character
Returns
true if the two character values are the same, otherwise false
bool UtfString::UnicodeChar::operator== ( const Utf8Char character) const

Compares the value of this character to the value of a UTF-8 character and tests whether the two character Unicode values are the same.

Parameters
[in]characterThe UTF-8 character to be compared with this character
Returns
true if the two character Unicode values are the same, otherwise false
bool UtfString::UnicodeChar::operator== ( const Utf16Char character) const

Compares the value of this character to the value of a UTF-16 character and tests whether the two character Unicode values are the same.

Parameters
[in]characterThe UTF-16 character reference to be compared with this character
Returns
true if the two character Unicode values are the same, otherwise false
bool UtfString::UnicodeChar::operator== ( const UnicodeCharReference characterReference) const

Compares the value of this character to the value of a character reference and tests whether the two character values are the same.

Parameters
[in]characterReferenceThe character reference to be compared with this character reference
Returns
true if the two character values are the same, otherwise false
bool UtfString::UnicodeChar::operator== ( const Utf8CharReference characterReference) const

Compares the value of this character to the value of a UTF-8 character reference and tests whether the two character Unicode values are the same.

Parameters
[in]characterReferenceThe UTF-8 character reference to be compared with this character
Returns
true if the two character Unicode values are the same, otherwise false
bool UtfString::UnicodeChar::operator== ( const Utf16CharReference characterReference) const

Compares the value of this character to the value of a UTF-16 character reference and tests whether the two character Unicode values are the same.

Parameters
[in]characterReferenceThe UTF-16 character reference to be compared with this character
Returns
true if the two character Unicode values are the same, otherwise false
UInt32 UtfString::UnicodeChar::to_utf_32 ( ) const

Converts this character to a UTF-32 code point.

This function assumes that is_valid() is true. If empty() is true, this function will return a value of 0xFFFFFFFF.

Returns
This character as a UTF-32 code unit

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