Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Public Member Functions | Static Public Member Functions | List of all members
HFCore::UString Class Reference

Interface for unicode string class UString. More...

#include <UString.h>

Public Member Functions

 UString ()
 Constructor.
 
 UString (const wchar_t *str)
 Constructor. More...
 
 UString (const int8_hf *utf8)
 Constructor. More...
 
 UString (const UString &ustr)
 Constructor. More...
 
virtual ~UString ()
 Destructor.
 
int32_hf length () const
 Get the length of the string. More...
 
const int8_hftoUtf8 () const
 Get the utf8 encoded string. More...
 
int32_hf fromUtf8 (const int8_hf *utf8)
 Create string from utf8 encoded string. More...
 
const wchar_t * wc_str () const
 Get the unicode widechar string. More...
 
UString substr (int32_hf offset, int32_hf charCount=-1) const
 Get a substring from offset to charCount. More...
 
int32_hf findChar (wchar_t ch, int32_hf start=0, bool respectEscapeChars=false) const
 Find a char and return it's index if found or -1 if not. More...
 
int32_hf findChar (const UString &str, int32_hf start=0, bool respectEscapeChars=false) const
 Find a char from str and return the index of the first found character or -1 if not found. More...
 
int32_hf find (const UString &str, int32_hf start=0) const
 Find first index matching str or -1 if not found. More...
 
void append (const UString &str)
 Append str to internal string. More...
 
void insert (int32_hf offset, const UString &str)
 Insert str at offset position. More...
 
void insert (int32_hf offset, wchar_t ch)
 Insert ch at offset position. More...
 
void erase (int32_hf offset, int32_hf count)
 Erase count character/s at offset position. More...
 
void clear ()
 Clear string and free memory used internally.
 
bool isAsciiOnly ()
 Determine if string has Ascii only characters. More...
 
void collapseEscapes ()
 Collapse / remove ESCAPE CHAR's ("\\").
 
UString trim ()
 Trim string left and right. More...
 
fp32_hf toFloat () const
 Convert string to float. More...
 
wchar_t operator[] (int32_hf index) const
 Overload of subscript operator []. More...
 
UStringoperator= (const UString &ustr)
 Overload of binary operator =. More...
 
bool operator== (const UString &ustr) const
 Overload of binary operator ==. More...
 
bool operator!= (const UString &ustr) const
 Overload of binary operator !=. More...
 
bool operator< (const UString &ustr) const
 Overload of operator < (less than). More...
 

Static Public Member Functions

static UString format (const int8_hf *utf8format,...)
 Format a string. More...
 

Detailed Description

Interface for unicode string class UString.

Definition at line 35 of file UString.h.

Constructor & Destructor Documentation

◆ UString() [1/3]

UString::UString ( const wchar_t *  str)

Constructor.

Parameters
strunicode widechar string.

Definition at line 70 of file UString.cpp.

◆ UString() [2/3]

UString::UString ( const int8_hf utf8)

Constructor.

Parameters
utf8utf8 encoded string.

Definition at line 57 of file UString.cpp.

◆ UString() [3/3]

UString::UString ( const UString ustr)

Constructor.

Parameters
ustrUString string.

Definition at line 62 of file UString.cpp.

Member Function Documentation

◆ append()

void UString::append ( const UString str)

Append str to internal string.

HFCore::UString str = "TransformationOfMan";
// str will be "TransformationOfMan_Appended":
str.append("_Appended");
Parameters
strUString string to append.

Definition at line 365 of file UString.cpp.

◆ erase()

void UString::erase ( int32_hf  offset,
int32_hf  count 
)

Erase count character/s at offset position.

HFCore::UString str = "CupTea";
// str will be "Cup":
str.erase(3, 3);
Parameters
offsetOffset position.
countNumber of characters to erase.

Definition at line 533 of file UString.cpp.

◆ find()

int32_hf UString::find ( const UString str,
int32_hf  start = 0 
) const

Find first index matching str or -1 if not found.

HFCore::UString str = "TransformationOfMan";
// chIdx will be 16: ("Man" is found in str and "M" is at
// index 16).
int32_hf chIdx = str.find("Man");
Parameters
strUString string to find.
startStart index to use in find loop.
Returns
First index matching str or -1 if not found.

Definition at line 519 of file UString.cpp.

◆ findChar() [1/2]

int32_hf UString::findChar ( wchar_t  ch,
int32_hf  start = 0,
bool  respectEscapeChars = false 
) const

Find a char and return it's index if found or -1 if not.

HFCore::UString str = "TransformationOfMan";
// chIdx will be 5:
int32_hf chIdx = str.findChar(L'f');
Parameters
chunicode widechar to find.
startStart index to use in find loop.
respectEscapeCharstrue to respect ESCAPE char ("\\"), false otherwise.
Returns
Index of found ch or -1 if not found.

Definition at line 469 of file UString.cpp.

◆ findChar() [2/2]

int32_hf UString::findChar ( const UString str,
int32_hf  start = 0,
bool  respectEscapeChars = false 
) const

Find a char from str and return the index of the first found character or -1 if not found.

HFCore::UString str = "TransformationOfMan";
// chIdx will be 2 as it finds 'a' before 'n':
int32_hf chIdx = str.findChar("na");
Parameters
strUString string to find first character index from.
startStart index to use in find loop.
respectEscapeCharstrue to respect ESCAPE char ("\\"), false otherwise.
Returns
Index of first found ch from str or -1 if not found.

Definition at line 494 of file UString.cpp.

◆ format()

UString UString::format ( const int8_hf utf8format,
  ... 
)
static

Format a string.

HFCore::UString str = "TransformationOfMan";
HFCore::UString formattedStr =
HFCore::UString::format("str: %s, str len: %d",
str.toUtf8(), str.length());
envDebugLog("formattedStr '%s'.\r\n", formattedStr.toUtf8());
Parameters
utf8formatFormat string (example: "string: %s int: %d" etc).
...Parameter list (0-n based on format string).
Returns
Formatted UString accourding to format string.

Definition at line 94 of file UString.cpp.

◆ fromUtf8()

int32_hf UString::fromUtf8 ( const int8_hf utf8)

Create string from utf8 encoded string.

Parameters
utf8utf8 encoded string.
Returns
Length of string created.

Definition at line 138 of file UString.cpp.

◆ insert() [1/2]

void UString::insert ( int32_hf  offset,
const UString str 
)

Insert str at offset position.

HFCore::UString str = "CupTea";
// str will be "CupOfTea":
str.insert(3, "Of");
Parameters
offsetOffset position.
strUString string to insert.

Definition at line 396 of file UString.cpp.

◆ insert() [2/2]

void UString::insert ( int32_hf  offset,
wchar_t  ch 
)

Insert ch at offset position.

HFCore::UString str = "CupTea";
// str will be "CupTeas":
str.insert(6, L's');
Parameters
offsetOffset position.
chwchar_t character to insert.

Definition at line 439 of file UString.cpp.

◆ isAsciiOnly()

bool UString::isAsciiOnly ( )

Determine if string has Ascii only characters.

Returns
true if string has Ascii only characters, else false.

Definition at line 731 of file UString.cpp.

◆ length()

int32_hf UString::length ( ) const

Get the length of the string.

Returns
Length of the string.

Definition at line 178 of file UString.cpp.

◆ operator!=()

bool UString::operator!= ( const UString ustr) const

Overload of binary operator !=.

This operator compares strict difference between two UString's.

Parameters
ustrUString to compare against *this.
Returns
true if not equal, else false.

Definition at line 331 of file UString.cpp.

◆ operator<()

bool UString::operator< ( const UString ustr) const

Overload of operator < (less than).

This operator compares two UString's and returns true if *this < ustr per character or in length.

Parameters
ustrUString to compare against *this.
Returns
true if *this < ustr per character or in length.

Definition at line 347 of file UString.cpp.

◆ operator=()

UString & UString::operator= ( const UString ustr)

Overload of binary operator =.

This operator assign *this the value of ustr.

Parameters
ustrUString to assign to *this.
Returns
*this assigned the value of ustr.

Definition at line 301 of file UString.cpp.

◆ operator==()

bool UString::operator== ( const UString ustr) const

Overload of binary operator ==.

This operator compares strict equality between two UString's.

Parameters
ustrUString to compare against *this.
Returns
true if equal, else false.

Definition at line 337 of file UString.cpp.

◆ operator[]()

wchar_t UString::operator[] ( int32_hf  index) const

Overload of subscript operator [].

This operator returns wchar_t character at given index.

Parameters
indexSubscript index.
Returns
wchar_t character at current index.

Definition at line 209 of file UString.cpp.

◆ substr()

UString UString::substr ( int32_hf  offset,
int32_hf  charCount = -1 
) const

Get a substring from offset to charCount.

HFCore::UString str = "TransformationOfMan";
HFCore::UString subStr = str.substr(16);
// subStr = "Man":
envDebugLog("subStr is '%s'.\r\n", subStr.toUtf8());
Parameters
offsetOffset for substring.
charCountChar count from offset (-1 means get the rest of the string from offset).
Returns
Substring from offset to charcount.

Definition at line 183 of file UString.cpp.

◆ toFloat()

fp32_hf UString::toFloat ( ) const

Convert string to float.

Returns
Converted string to float.

Definition at line 569 of file UString.cpp.

◆ toUtf8()

const int8_hf * UString::toUtf8 ( ) const

Get the utf8 encoded string.

Returns
utf8 encoded string.

Definition at line 574 of file UString.cpp.

◆ trim()

UString UString::trim ( )

Trim string left and right.

HFCore::UString str = " CupTea ";
// strTrimmed will be "CupTea":
HFCore::UString strTrimmed = str.trim();
Returns
Trimmed string.

Definition at line 736 of file UString.cpp.

◆ wc_str()

const wchar_t * UString::wc_str ( ) const

Get the unicode widechar string.

Returns
Unicode widechar string.
Note
May return NULL for empty strings.

Definition at line 579 of file UString.cpp.


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