HPS::UTF8 Class Reference

#include <hps.h>

Public Member Functions

UTF8Assign (UTF8 &&in_utf8)
 
UTF8Assign (UTF8 const &in_utf8)
 
char At (size_t in_index) const
 
void Clear ()
 Reset all string data.
 
bool Empty () const
 
char const * GetBytes () const
 
size_t GetHash () const
 
size_t GetLength () const
 
size_t GetWStrLength () const
 
bool IsValid () const
 
 operator char const * () const
 
bool operator!= (UTF8 const &in_utf8) const
 
bool operator!= (char const *in_utf8) const
 
UTF8 operator+ (UTF8 const &in_utf8) const
 
UTF8 operator+ (char const *in_utf8) const
 
UTF8operator+= (UTF8 const &in_utf8)
 
UTF8operator+= (char const *in_utf8)
 
UTF8operator= (UTF8 &&in_utf8)
 
UTF8operator= (UTF8 const &in_utf8)
 
bool operator== (UTF8 const &in_utf8) const
 
bool operator== (char const *in_utf8) const
 
void Reset ()
 
size_t ToWStr (wchar_t *out_wide_string) const
 
size_t ToWStr (WCharArray &out_wide_string) const
 
 UTF8 ()
 The default constructor creates an empty UTF8 string.
 
 UTF8 (char const *in_string, char const *in_locale=0)
 
 UTF8 (wchar_t const *in_string)
 
 UTF8 (UTF8 const &in_that)
 
 UTF8 (UTF8 &&in_that)
 
 ~UTF8 ()
 A destructor for a UTF8 string.
 

Friends

class HPSI::String
 
bool operator!= (char const *in_left, UTF8 const &in_right)
 
bool operator!= (wchar_t const *in_left, UTF8 const &in_right)
 
UTF8 operator+ (char const *in_left, UTF8 const &in_right)
 
UTF8 operator+ (wchar_t const *in_left, UTF8 const &in_right)
 
bool operator== (char const *in_left, UTF8 const &in_right)
 
bool operator== (wchar_t const *in_left, UTF8 const &in_right)
 

Detailed Description

The UTF8 class encapsulates a utf8 encoded array of characters and allows for easy encoding and decoding.

Constructor & Destructor Documentation

◆ UTF8() [1/4]

HPS::UTF8::UTF8 ( char const *  in_string,
char const *  in_locale = 0 
)

This constructor can be used to encode a string from any known locale to utf8. Be careful not to re-encode a string that's already utf8 encoded.

Parameters
in_stringThe string to be encoded.
in_localeA string identifying the source locale of in_string. If none is specified, the default locale on the local machine will be used. If in_string is already utf8 encoded, specify the locale as "utf8" to prevent re-encoding.

◆ UTF8() [2/4]

HPS::UTF8::UTF8 ( wchar_t const *  in_string)

This constructor can be used to encode a wide character string to utf8.

Parameters
in_stringThe string to be encoded.

◆ UTF8() [3/4]

HPS::UTF8::UTF8 ( UTF8 const &  in_that)

The copy constructor copies the source utf8 string.

Parameters
in_thatthe source to be copied.

◆ UTF8() [4/4]

HPS::UTF8::UTF8 ( UTF8 &&  in_that)

The move constructor takes control of the underlying data from the source utf8 string.

Parameters
thesource of the move.

Member Function Documentation

◆ Assign() [1/2]

UTF8& HPS::UTF8::Assign ( UTF8 &&  in_utf8)

Moves the source UTF8 object to this object. This method is functionally equivalent to the overloaded assignment operator.

Parameters
in_utf8The source of the move.
Returns
A reference to this object.

◆ Assign() [2/2]

UTF8& HPS::UTF8::Assign ( UTF8 const &  in_utf8)

Copies the source UTF8 object to this object. This method is functionally equivalent to the overloaded assignment operator.

Parameters
in_utf8The source of the copy.
Returns
A reference to this object.

◆ At()

char HPS::UTF8::At ( size_t  in_index) const
inline

Retrieves the utf8 encoded character at the specified index. This method may split up individual code points.

Returns
The utf8 encoded character array.

◆ Empty()

bool HPS::UTF8::Empty ( ) const
inline

Indicates whether this utf8 string is empty.

Returns
true if the UTF8 string is empty, false otherwise.

◆ GetBytes()

char const* HPS::UTF8::GetBytes ( ) const
inline

Retrieves the raw, utf8 encoded character array.

Returns
The utf8 encoded character array.

◆ GetHash()

size_t HPS::UTF8::GetHash ( ) const

Returns a hash code for the utf8 encoded characters.

Returns
The size_t hash code.

◆ GetLength()

size_t HPS::UTF8::GetLength ( ) const
inline

Retrieves the number of bytes in the utf8 encoded string up to but not including the null terminator. This will return 0 if the utf8 object is uninitialized.

Returns
The number of bytes.

◆ GetWStrLength()

size_t HPS::UTF8::GetWStrLength ( ) const
inline

Retrieves the number of wide characters in the wchar_t string up to but not including the null terminator. This will return 0 if the utf8 object is uninitialized.

Returns
The number of wide characters.

◆ IsValid()

bool HPS::UTF8::IsValid ( ) const
inline

Indicates whether this utf8 string has been initialized.

Returns
true if the UTF8 string has been initialized, false otherwise.

◆ operator char const *()

HPS::UTF8::operator char const * ( ) const
inline

Allows typecasting to const char * by retrieves the raw, utf8 encoded character array.

Returns
The utf8 encoded character array.

◆ operator!=() [1/2]

bool HPS::UTF8::operator!= ( UTF8 const &  in_utf8) const
inline

This function is used to check an object for equivalence to this.

Parameters
in_utf8The object to compare to this.
Returns
true if the objects are not equivalent, false otherwise.

◆ operator!=() [2/2]

bool HPS::UTF8::operator!= ( char const *  in_utf8) const
inline

This function is used to check a utf8-encoded character string for equivalence to this.

Parameters
in_utf8The object to compare to this.
Returns
true if the objects are not equivalent, false otherwise.

◆ operator+() [1/2]

UTF8 HPS::UTF8::operator+ ( UTF8 const &  in_utf8) const

Creates a new UTF8 object by appending a UTF8 object to the end of this object.

Parameters
in_utf8The tail end of the new string.
Returns
A new UTF8 object representing the concatenation of 2 strings.

◆ operator+() [2/2]

UTF8 HPS::UTF8::operator+ ( char const *  in_utf8) const

Creates a new UTF8 object by appending a utf8 encoded string to the end of this object.

Parameters
in_utf8A string, assumed to be utf8 encoded, used as the tail end of the new string.
Returns
A new UTF8 object representing the concatenation of 2 strings.

◆ operator+=() [1/2]

UTF8& HPS::UTF8::operator+= ( UTF8 const &  in_utf8)

Appends a UTF8 object to the end of this object.

Parameters
in_utf8The tail end of the new string.
Returns
A reference to this object.

◆ operator+=() [2/2]

UTF8& HPS::UTF8::operator+= ( char const *  in_utf8)

Appends a utf8 encoded string to the end of this object.

Parameters
in_utf8A string, assumed to be utf8 encoded, used as the tail end of the new string.
Returns
A reference to this object.

◆ operator=() [1/2]

UTF8& HPS::UTF8::operator= ( UTF8 &&  in_utf8)
inline

The move assignment operator takes control of the underlying data from the source utf8 string.

Parameters
thesource of the move.

◆ operator=() [2/2]

UTF8& HPS::UTF8::operator= ( UTF8 const &  in_utf8)
inline

Copies the source UTF8 object to this object.

Parameters
in_utf8The source of the copy.
Returns
A reference to this object.

◆ operator==() [1/2]

bool HPS::UTF8::operator== ( UTF8 const &  in_utf8) const

This function is used to check an object for equivalence to this.

Parameters
in_utf8The object to compare to this.
Returns
true if the objects are equivalent, false otherwise.

◆ operator==() [2/2]

bool HPS::UTF8::operator== ( char const *  in_utf8) const

This function is used to check a utf8-encoded character string for equivalence to this.

Parameters
in_utf8The object to compare to this.
Returns
true if the objects are equivalent, false otherwise.

◆ Reset()

void HPS::UTF8::Reset ( )
inline

Resets this object to its initial, uninitialized state.

◆ ToWStr() [1/2]

size_t HPS::UTF8::ToWStr ( wchar_t *  out_wide_string) const

Decode a utf8 encoded string into a wide character buffer

Parameters
out_wide_string
Returns
the number of wide characters (code points) in the wide string.

◆ ToWStr() [2/2]

size_t HPS::UTF8::ToWStr ( WCharArray out_wide_string) const

Decode a utf8 encoded string into a wide character buffer

Returns
The number of wide characters (code points) in the wide string.

Friends And Related Function Documentation

◆ operator!= [1/2]

bool operator!= ( char const *  in_left,
UTF8 const &  in_right 
)
friend

This function is used to check a utf8-encoded character string for equivalence to a UTF8 object.

Parameters
in_leftA utf8-encoded character string.
in_rightA UTF8 object.
Returns
true if the objects are not equivalent, false otherwise.

◆ operator!= [2/2]

bool operator!= ( wchar_t const *  in_left,
UTF8 const &  in_right 
)
friend

This function is used to check a wide character string for equivalence to a UTF8 object.

Parameters
in_leftA wide character string.
in_rightA UTF8 object.
Returns
true if the objects are not equivalent, false otherwise.

◆ operator+ [1/2]

UTF8 operator+ ( char const *  in_left,
UTF8 const &  in_right 
)
friend

Creates a new UTF8 object by appending a UTF8 object to the end of a utf8-encoded character string.

Parameters
in_leftA string, assumed to be utf8 encoded, used as the head end of the new string.
in_rightA UTF8 object used as the tail end of the new string.
Returns
A new UTF8 object representing the concatenation of 2 strings.

◆ operator+ [2/2]

UTF8 operator+ ( wchar_t const *  in_left,
UTF8 const &  in_right 
)
friend

Creates a new UTF8 object by appending a UTF8 object to the end of a wide character string.

Parameters
in_leftA wide character string used as the head end of the new string.
in_rightA UTF8 object used as the tail end of the new string.
Returns
A new UTF8 object representing the concatenation of 2 strings.

◆ operator== [1/2]

bool operator== ( char const *  in_left,
UTF8 const &  in_right 
)
friend

This function is used to check a utf8-encoded character string for equivalence to a UTF8 object.

Parameters
in_leftA utf8-encoded character string.
in_rightA UTF8 object.
Returns
true if the objects are equivalent, false otherwise.

◆ operator== [2/2]

bool operator== ( wchar_t const *  in_left,
UTF8 const &  in_right 
)
friend

This function is used to check a wide character string for equivalence to a UTF8 object.

Parameters
in_leftA wide character string.
in_rightA UTF8 object.
Returns
true if the objects are equivalent, false otherwise.

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