Hoops Visualize HPS  version 2018-SP2
Hoops Visualize HPS 3D Rendering Engine
Looking for a senior C++ dev?
I'm looking for work. Hire me!
HPS::UTF8 Class Reference

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

#include <hps.h>

Collaboration diagram for HPS::UTF8:

Public Member Functions

 UTF8 ()
 The default constructor creates an empty UTF8 string. More...
 
 ~UTF8 ()
 A destructor for a UTF8 string. More...
 
 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. More...
 
 UTF8 (wchar_t const *in_string)
 This constructor can be used to encode a wide character string to utf8. More...
 
 UTF8 (UTF8 const &in_that)
 The copy constructor copies the source utf8 string. More...
 
 UTF8 (UTF8 &&in_that)
 The move constructor takes control of the underlying data from the source utf8 string. More...
 
UTF8Assign (UTF8 &&in_utf8)
 Moves the source UTF8 object to this object. More...
 
UTF8operator= (UTF8 &&in_utf8)
 The move assignment operator takes control of the underlying data from the source utf8 string. More...
 
size_t ToWStr (wchar_t *out_wide_string) const
 Decode a utf8 encoded string into a wide character buffer. More...
 
size_t ToWStr (WCharArray &out_wide_string) const
 Decode a utf8 encoded string into a wide character buffer. More...
 
bool IsValid () const
 Indicates whether this utf8 string has been initialized. More...
 
bool Empty () const
 Indicates whether this utf8 string is empty. More...
 
void Clear ()
 Reset all string data. More...
 
void Reset ()
 Resets this object to its initial, uninitialized state. More...
 
size_t GetLength () const
 Retrieves the number of bytes in the utf8 encoded string up to but not including the null terminator. More...
 
size_t GetWStrLength () const
 Retrieves the number of wide characters in the wchar_t string up to but not including the null terminator. More...
 
char const * GetBytes () const
 Retrieves the raw, utf8 encoded character array. More...
 
 operator char const * () const
 Allows typecasting to const char * by retrieves the raw, utf8 encoded character array. More...
 
char At (size_t in_index) const
 Retrieves the utf8 encoded character at the specified index. More...
 
UTF8Assign (UTF8 const &in_utf8)
 Copies the source UTF8 object to this object. More...
 
UTF8operator= (UTF8 const &in_utf8)
 Copies the source UTF8 object to this object. More...
 
UTF8operator+= (UTF8 const &in_utf8)
 Appends a UTF8 object to the end of this object. More...
 
UTF8operator+= (char const *in_utf8)
 Appends a utf8 encoded string to the end of this object. More...
 
UTF8 operator+ (UTF8 const &in_utf8) const
 Creates a new UTF8 object by appending a UTF8 object to the end of this object. More...
 
UTF8 operator+ (char const *in_utf8) const
 Creates a new UTF8 object by appending a utf8 encoded string to the end of this object. More...
 
bool operator== (UTF8 const &in_utf8) const
 This function is used to check an object for equivalence to this. More...
 
bool operator!= (UTF8 const &in_utf8) const
 This function is used to check an object for equivalence to this. More...
 
bool operator== (char const *in_utf8) const
 This function is used to check a utf8-encoded character string for equivalence to this. More...
 
bool operator!= (char const *in_utf8) const
 This function is used to check a utf8-encoded character string for equivalence to this. More...
 
size_t GetHash () const
 Returns a hash code for the utf8 encoded characters. More...
 

Private Member Functions

size_t internal_encode (wchar_t const *in_wide_string)
 
size_t internal_decode (wchar_t *out_wide_string) const
 

Static Private Member Functions

static size_t internal_decode (size_t in_length, const char *in_utf8_string, wchar_t *out_wide_string)
 

Private Attributes

char * _text
 
size_t _length
 
size_t _hash_key
 
char _buffer [_buffer_size]
 

Static Private Attributes

static const size_t _buffer_size = 64 - sizeof(const char *) - 2 * sizeof(size_t)
 

Friends

class HPSI::String
 
bool operator== (char const *in_left, UTF8 const &in_right)
 This function is used to check a utf8-encoded character string for equivalence to a UTF8 object. More...
 
bool operator!= (char const *in_left, UTF8 const &in_right)
 This function is used to check a utf8-encoded character string for equivalence to a UTF8 object. More...
 
bool operator== (wchar_t const *in_left, UTF8 const &in_right)
 This function is used to check a wide character string for equivalence to a UTF8 object. More...
 
bool operator!= (wchar_t const *in_left, UTF8 const &in_right)
 This function is used to check a wide character string for equivalence to a UTF8 object. More...
 
UTF8 operator+ (char const *in_left, UTF8 const &in_right)
 Creates a new UTF8 object by appending a UTF8 object to the end of a utf8-encoded character string. More...
 
UTF8 operator+ (wchar_t const *in_left, UTF8 const &in_right)
 Creates a new UTF8 object by appending a UTF8 object to the end of a wide character string. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ UTF8() [1/5]

HPS::UTF8::UTF8 ( )

The default constructor creates an empty UTF8 string.

◆ ~UTF8()

HPS::UTF8::~UTF8 ( )

A destructor for a UTF8 string.

◆ UTF8() [2/5]

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() [3/5]

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() [4/5]

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

The copy constructor copies the source utf8 string.

Parameters
in_thatthe source to be copied.

◆ UTF8() [5/5]

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.

◆ Clear()

void HPS::UTF8::Clear ( )

Reset all string data.

◆ 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.
Here is the caller graph for this function:

◆ 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.

◆ internal_decode() [1/2]

static size_t HPS::UTF8::internal_decode ( size_t  in_length,
const char *  in_utf8_string,
wchar_t *  out_wide_string 
)
staticprivate

◆ internal_decode() [2/2]

size_t HPS::UTF8::internal_decode ( wchar_t *  out_wide_string) const
private

◆ internal_encode()

size_t HPS::UTF8::internal_encode ( wchar_t const *  in_wide_string)
private

◆ 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.
Here is the call graph for this function:

◆ 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.
Here is the call graph for this function:

◆ 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

◆ HPSI::String

friend class HPSI::String
friend

◆ 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.

Member Data Documentation

◆ _buffer

char HPS::UTF8::_buffer[_buffer_size]
private

◆ _buffer_size

const size_t HPS::UTF8::_buffer_size = 64 - sizeof(const char *) - 2 * sizeof(size_t)
staticprivate

◆ _hash_key

size_t HPS::UTF8::_hash_key
mutableprivate

◆ _length

size_t HPS::UTF8::_length
private

◆ _text

char* HPS::UTF8::_text
private

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