Nebula
Loading...
Searching...
No Matches
Util::String Class Reference

#include <string.h>

Detailed Description

Nebula's universal string class.

An empty string object is always 32 bytes big. The string class tries to avoid costly heap allocations with the following tactics:

  • a local embedded buffer is used if the string is short enough
  • if a heap buffer must be allocated, care is taken to reuse an existing buffer instead of allocating a new buffer if possible (usually if an assigned string fits into the existing buffer, the buffer is reused and not re-allocated)

Heap allocations are performed through a local heap which should be faster then going through the process heap.

Besides the usual string manipulation methods, the String class also offers methods to convert basic Nebula datatypes from and to string, and a group of methods which manipulate filename strings.

Public Member Functions

 String ()
 constructor
 
 String (const String &rhs)
 copy constructor
 
 String (String &&rhs) noexcept
 move constructor
 
 String (const char *cStr)
 construct from C string
 
 String (const char *cStr, size_t len)
 construct from C string
 
 ~String ()
 destructor
 
void operator= (const String &rhs)
 assignment operator
 
void operator= (String &&rhs) noexcept
 move operator
 
void operator= (const char *cStr)
 assign from const char*
 
void operator+= (const String &rhs)
 += operator
 
char operator[] (IndexT i) const
 read-only index operator
 
char & operator[] (IndexT i)
 read/write index operator
 
void Reserve (SizeT newSize)
 reserve internal buffer size to prevent heap allocs
 
SizeT Length () const
 return length of string
 
void Clear ()
 clear the string
 
bool IsEmpty () const
 return true if string object is empty
 
bool IsValid () const
 return true if string object is not empty
 
bool CopyToBuffer (char *buf, SizeT bufSize) const
 copy to char buffer (return false if buffer is too small)
 
void Append (const String &str)
 append string
 
void Append (const char *str)
 append c-string
 
void AppendRange (const char *str, SizeT numChars)
 append a range of characters
 
void ToLower ()
 convert string to lower case
 
void ToUpper ()
 convert string to upper case
 
void Capitalize ()
 convert first char of string to upper case
 
void CamelCaseToWords ()
 insert spaces before each capital letter in the string.
 
SizeT Tokenize (const String &whiteSpace, Array< String > &outTokens) const
 tokenize string into a provided String array (faster if tokens array can be reused)
 
Array< StringTokenize (const String &whiteSpace) const
 tokenize string into a provided String array, SLOW since new array will be constructed
 
SizeT Tokenize (const String &whiteSpace, char fence, Array< String > &outTokens) const
 tokenize string, keep strings within fence characters intact (faster if tokens array can be reused)
 
Array< StringTokenize (const String &whiteSpace, char fence) const
 tokenize string, keep strings within fence characters intact, SLOW since new array will be constructed
 
String ExtractRange (IndexT fromIndex, SizeT numChars) const
 extract substring
 
String ExtractToEnd (IndexT fromIndex) const
 extract substring to end of this string
 
void Strip (const String &charSet)
 terminate string at first occurence of character in set
 
IndexT FindStringIndex (const String &s, IndexT startIndex=0) const
 return start index of substring, or InvalidIndex if not found
 
IndexT FindCharIndex (char c, IndexT startIndex=0) const
 return index of character in string, or InvalidIndex if not found
 
bool BeginsWithString (const String &s) const
 returns true if string begins with string
 
bool EndsWithString (const String &s) const
 returns true if string ends with string
 
void TerminateAtIndex (IndexT index)
 terminate string at given index
 
bool ContainsCharFromSet (const String &charSet) const
 returns true if string contains any character from set
 
void TrimLeft (const String &charSet)
 delete characters from charset at left side of string
 
void TrimRight (const String &charSet)
 delete characters from charset at right side of string
 
void Trim (const String &charSet)
 trim characters from charset at both sides of string
 
void SubstituteString (const String &str, const String &substStr)
 substitute every occurance of a string with another string
 
void SubstituteChar (char c, char subst)
 substitute every occurance of a character with another character
 
void __cdecl Format (const char *fmtString,...)
 format string printf-style
 
void __cdecl FormatArgList (const char *fmtString, va_list argList)
 format string printf-style with varargs list
 
bool CheckValidCharSet (const String &charSet) const
 return true if string only contains characters from charSet argument
 
void ReplaceChars (const String &charSet, char replacement)
 replace any char set character within a string with the replacement character
 
uint32_t HashCode () const
 return a 32-bit hash code for the string
 
void SetCharPtr (const char *s)
 set content to char ptr
 
void Set (const char *ptr, SizeT length)
 set as char ptr, with explicit length
 
void Set (const char *ptr, size_t length)
 set as char ptr, with explicit length. will assert if size_t exceeds 2^32
 
void SetByte (byte val)
 set as byte value
 
void SetUByte (ubyte val)
 set as ubyte value
 
void SetShort (short val)
 set as short value
 
void SetUShort (ushort val)
 set as ushort value
 
void SetInt (int val)
 set as int value
 
void SetUInt (uint val)
 set as uint value
 
void SetLong (long val)
 set as long value
 
void SetSizeT (size_t val)
 set as long value
 
void SetLongLong (long long val)
 set as long long value
 
void SetFloat (float val)
 set as float value
 
void SetDouble (double val)
 set as double value
 
void SetBool (bool val)
 set as bool value
 
void Fill (SizeT length, unsigned char character)
 set string length and fill all characters with arg
 
void SetVec2 (const Math::vec2 &v)
 set as vec2 value
 
void SetVec3 (const Math::vec3 &v)
 set as vec3 value
 
void SetVec4 (const Math::vec4 &v)
 set as vec4 value
 
void SetFloat2 (const Math::float2 &v)
 set as vec2 value
 
void SetFloat3 (const Math::float3 &v)
 set as vec3 value
 
void SetFloat4 (const Math::float4 &v)
 set as vec4 value
 
void SetQuaternion (const Math::quat &v)
 set as quaternion
 
void SetMat4 (const Math::mat4 &v)
 set as mat4 value
 
void SetTransform44 (const Math::transform44 &v)
 set as transform44 value
 
template<typename T >
void Set (const T &t)
 generic setter
 
void AppendChar (char val)
 append character
 
void AppendInt (int val)
 append int value
 
void AppendByte (byte val)
 append byte value
 
void AppendUByte (ubyte val)
 append unsigned byte value
 
void AppendFloat (float val)
 append float value
 
void AppendBool (bool val)
 append bool value
 
void AppendVec2 (const Math::vec2 &v)
 append vec2 value
 
void AppendVec3 (const Math::vec3 &v)
 append vec3 value
 
void AppendVec4 (const Math::vec4 &v)
 append vec4 value
 
void AppendMat4 (const Math::mat4 &v)
 append mat4 value
 
template<typename T >
void Append (const T &t)
 generic append
 
const char * AsCharPtr () const
 return contents as character pointer
 
const char * Get () const
 *** OBSOLETE *** only Nebula2 compatibility
 
int AsInt () const
 return contents as integer
 
long long AsLongLong () const
 return contents as long long
 
float AsFloat () const
 return contents as float
 
bool AsBool () const
 return contents as bool
 
Math::vec2 AsVec2 () const
 return contents as vec2
 
Math::vec3 AsVec3 () const
 return contents as vec3
 
Math::vec4 AsVec4 () const
 return contents as vec4
 
Math::float2 AsFloat2 () const
 return contents as vec2
 
Math::float3 AsFloat3 () const
 return contents as vec3
 
Math::float4 AsFloat4 () const
 return contents as vec4
 
Math::mat4 AsMat4 () const
 return contents as mat4
 
Math::transform44 AsTransform44 () const
 return contents as transform44
 
Util::Blob AsBlob () const
 return contents as blob
 
Util::String AsBase64 () const
 return contents as base64 string
 
template<typename T >
As () const
 convert to "anything"
 
bool IsValidInt () const
 return true if the content is a valid integer
 
bool IsValidFloat () const
 return true if the content is a valid float
 
bool IsValidBool () const
 return true if the content is a valid bool
 
bool IsValidVec2 () const
 return true if the content is a valid vec2
 
bool IsValidVec4 () const
 return true if the content is a valid vec4
 
bool IsValidMat4 () const
 return true if content is a valid mat4
 
bool IsValidTransform44 () const
 return true if content is a valid transform44
 
template<typename T >
bool IsValid () const
 generic valid checker
 
String GetFileExtension () const
 get filename extension without dot
 
bool CheckFileExtension (const String &ext) const
 check file extension
 
void ConvertBackslashes ()
 convert backslashes to slashes
 
void StripFileExtension ()
 remove file extension
 
void ChangeFileExtension (const Util::String &newExt)
 change file extension
 
void StripAssignPrefix ()
 remove assign prefix (for example tex:)
 
void ChangeAssignPrefix (const Util::String &newPref)
 change assign prefix
 
String ExtractFileName () const
 extract the part after the last directory separator
 
String ExtractLastDirName () const
 extract the last directory of the path
 
String ExtractDirName () const
 extract the part before the last directory separator
 
String ExtractToLastSlash () const
 extract path until last slash
 
void ReplaceIllegalFilenameChars (char replacement)
 replace illegal filename characters
 
const char * c_str () const
 helpers to interface with libraries that expect std::string like apis
 
size_t length () const
 
bool empty () const
 

Static Public Member Functions

static String Sprintf (const char *fmtString,...)
 static constructor for string using printf
 
static String Concatenate (const Array< String > &strArray, const String &whiteSpace)
 concatenate array of strings into new string
 
static bool MatchPattern (const String &str, const String &pattern)
 pattern matching
 
static String FromByte (byte i)
 construct a string from a byte
 
static String FromUByte (ubyte i)
 construct a string from a ubyte
 
static String FromShort (short i)
 construct a string from a short
 
static String FromUShort (ushort i)
 construct a string from a ushort
 
static String FromInt (int i)
 construct a string from an int
 
static String FromUInt (uint i)
 construct a string from a uint
 
static String FromLong (long i)
 construct a string from a long
 
static String FromSize (size_t i)
 construct a string from a size_t
 
static String FromLongLong (long long i)
 construct a string from a long long
 
static String FromFloat (float f)
 construct a string from a float
 
static String FromDouble (double f)
 construct a string from a double
 
static String FromBool (bool b)
 construct a string from a bool
 
static String FromVec2 (const Math::vec2 &v)
 construct a string from vec2
 
static String FromVec3 (const Math::vec3 &v)
 construct a string from vec3
 
static String FromVec4 (const Math::vec4 &v)
 construct a string from vec4
 
static String FromFloat2 (const Math::float2 &v)
 construct a string from float2
 
static String FromFloat3 (const Math::float3 &v)
 construct a string from float2
 
static String FromFloat4 (const Math::float4 &v)
 construct a string from float2
 
static String FromQuat (const Math::quat &q)
 construct a string from quat
 
static String FromMat4 (const Math::mat4 &m)
 construct a string from mat4
 
static String FromTransform44 (const Math::transform44 &m)
 construct a string from transform44
 
static String FromBlob (const Util::Blob &b)
 create from blob
 
static String FromBase64 (const String &)
 create from base64
 
template<typename T >
static String From (const T &t)
 convert from "anything"
 
static constexpr uint Hash (const char *c, std::size_t s)
 Hash a string.
 
template<typename INTEGER >
static String Hex (INTEGER i)
 construct a hex string from an int
 
static bool IsDigit (char c)
 test if provided character is a digit (0..9)
 
static bool IsAlpha (char c)
 test if provided character is an alphabet character (A..Z, a..z)
 
static bool IsAlNum (char c)
 test if provided character is an alpha-numeric character (A..Z,a..z,0..9)
 
static bool IsLower (char c)
 test if provided character is a lower case character
 
static bool IsUpper (char c)
 test if provided character is an upper-case character
 
static int StrCmp (const char *str0, const char *str1)
 lowlevel string compare wrapper function
 
static int StrLen (const char *str)
 lowlevel string length function
 
static const char * StrChr (const char *str, int c)
 find character in string
 
static Dictionary< String, StringParseKeyValuePairs (const String &str)
 parse key/value pair string ("key0=value0 key1=value1")
 

Public Attributes

string heap
 
fixed char local [20]
 
int strLen
 
int heapBufferSize
 

Private Types

enum  { LocalStringSize = 16 }
 

Private Member Functions

void Delete ()
 delete contents
 
char * GetLastSlash () const
 get pointer to last directory separator
 
void Alloc (SizeT size)
 allocate the string buffer (discards old content)
 
void Realloc (SizeT newSize)
 (re-)allocate the string buffer (copies old content)
 

Private Attributes

char * heapBuffer
 
char localBuffer [LocalStringSize]
 
SizeT strLen
 
SizeT heapBufferSize
 

Friends

bool operator== (const String &a, const String &b)
 equality operator
 
bool operator== (const String &a, const char *cStr)
 shortcut equality operator
 
bool operator== (const char *cStr, const String &a)
 shortcut equality operator
 
bool operator== (const String &a, std::nullptr_t)
 empty string operator
 
bool operator!= (const String &a, const String &b)
 inequality operator
 
bool operator< (const String &a, const String &b)
 less-then operator
 
bool operator> (const String &a, const String &b)
 greater-then operator
 
bool operator<= (const String &a, const String &b)
 less-or-equal operator
 
bool operator>= (const String &a, const String &b)
 greater-then operator
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
LocalStringSize 

Constructor & Destructor Documentation

◆ String() [1/5]

Util::String::String ( )
inline

constructor

◆ String() [2/5]

Util::String::String ( const String & rhs)
inline

copy constructor

◆ String() [3/5]

Util::String::String ( String && rhs)
inlinenoexcept

move constructor

◆ String() [4/5]

Util::String::String ( const char * cStr)
inline

construct from C string

◆ String() [5/5]

Util::String::String ( const char * cStr,
size_t len )
inline

construct from C string

◆ ~String()

Util::String::~String ( )
inline

destructor

Member Function Documentation

◆ Alloc()

void Util::String::Alloc ( SizeT size)
private

allocate the string buffer (discards old content)

Allocate a new heap buffer, discards old contents.

◆ Append() [1/3]

void Util::String::Append ( const char * str)

append c-string

◆ Append() [2/3]

void Util::String::Append ( const String & str)
inline

append string

◆ Append() [3/3]

template<typename T >
void Util::String::Append ( const T & t)

generic append

◆ AppendBool()

void Util::String::AppendBool ( bool val)
inline

append bool value

◆ AppendByte()

void Util::String::AppendByte ( byte val)
inline

append byte value

◆ AppendChar()

void Util::String::AppendChar ( char val)
inline

append character

◆ AppendFloat()

void Util::String::AppendFloat ( float val)
inline

append float value

◆ AppendInt()

void Util::String::AppendInt ( int val)
inline

append int value

◆ AppendMat4()

void Util::String::AppendMat4 ( const Math::mat4 & v)
inline

append mat4 value

◆ AppendRange()

void Util::String::AppendRange ( const char * str,
SizeT numChars )

append a range of characters

◆ AppendUByte()

void Util::String::AppendUByte ( ubyte val)
inline

append unsigned byte value

◆ AppendVec2()

void Util::String::AppendVec2 ( const Math::vec2 & v)
inline

append vec2 value

◆ AppendVec3()

void Util::String::AppendVec3 ( const Math::vec3 & v)
inline

append vec3 value

◆ AppendVec4()

void Util::String::AppendVec4 ( const Math::vec4 & v)
inline

append vec4 value

◆ As()

template<typename T >
T Util::String::As ( ) const

convert to "anything"

◆ AsBase64()

Util::String Util::String::AsBase64 ( ) const

return contents as base64 string

◆ AsBlob()

Util::Blob Util::String::AsBlob ( ) const

return contents as blob

◆ AsBool()

bool Util::String::AsBool ( ) const

return contents as bool

◆ AsCharPtr()

const char * Util::String::AsCharPtr ( ) const
inline

return contents as character pointer

◆ AsFloat()

float Util::String::AsFloat ( ) const

return contents as float

Returns content as float.

Note: this method doesn't check whether the contents is actually a valid float. Use the IsValidInt() method for this!

◆ AsFloat2()

Math::float2 Util::String::AsFloat2 ( ) const

return contents as vec2

◆ AsFloat3()

Math::float3 Util::String::AsFloat3 ( ) const

return contents as vec3

◆ AsFloat4()

Math::float4 Util::String::AsFloat4 ( ) const

return contents as vec4

◆ AsInt()

int Util::String::AsInt ( ) const

return contents as integer

Returns content as integer.

Note: this method doesn't check whether the contents is actually a valid integer. Use the IsValidInteger() method for this!

◆ AsLongLong()

long long Util::String::AsLongLong ( ) const

return contents as long long

Returns content as integer.

Note: this method doesn't check whether the contents is actually a valid integer. Use the IsValidInteger() method for this!

◆ AsMat4()

Math::mat4 Util::String::AsMat4 ( ) const

return contents as mat4

Returns content as mat4.

Note: this method doesn't check whether the contents is actually a valid mat4. Use the IsValidMat4() method for this!

◆ AsTransform44()

Math::transform44 Util::String::AsTransform44 ( ) const

return contents as transform44

◆ AsVec2()

Math::vec2 Util::String::AsVec2 ( ) const

return contents as vec2

Returns content as vec2.

Note: this method doesn't check whether the contents is actually a valid vec4. Use the IsValidFloat2() method for this!

◆ AsVec3()

Math::vec3 Util::String::AsVec3 ( ) const

return contents as vec3

◆ AsVec4()

Math::vec4 Util::String::AsVec4 ( ) const

return contents as vec4

Returns content as vec4.

Note: this method doesn't check whether the contents is actually a valid vec4. Use the IsValidVec4() method for this!

◆ BeginsWithString()

bool Util::String::BeginsWithString ( const String & s) const

returns true if string begins with string

◆ c_str()

const char * Util::String::c_str ( ) const
inline

helpers to interface with libraries that expect std::string like apis

◆ CamelCaseToWords()

void Util::String::CamelCaseToWords ( )

insert spaces before each capital letter in the string.

◆ Capitalize()

void Util::String::Capitalize ( )

convert first char of string to upper case

◆ ChangeAssignPrefix()

void Util::String::ChangeAssignPrefix ( const Util::String & newPref)

change assign prefix

◆ ChangeFileExtension()

void Util::String::ChangeFileExtension ( const Util::String & newExt)

change file extension

◆ CheckFileExtension()

bool Util::String::CheckFileExtension ( const String & ext) const
inline

check file extension

◆ CheckValidCharSet()

bool Util::String::CheckValidCharSet ( const String & charSet) const
inline

return true if string only contains characters from charSet argument

Return true if the string only contains characters which are in the defined character set.

◆ Clear()

void Util::String::Clear ( )
inline

clear the string

◆ Concatenate()

String Util::String::Concatenate ( const Array< String > & strArray,
const String & whiteSpace )
static

concatenate array of strings into new string

◆ ContainsCharFromSet()

bool Util::String::ContainsCharFromSet ( const String & charSet) const

returns true if string contains any character from set

Returns true if string contains one of the characters from charset.

◆ ConvertBackslashes()

void Util::String::ConvertBackslashes ( )
inline

convert backslashes to slashes

Converts backslashes to slashes.

◆ CopyToBuffer()

bool Util::String::CopyToBuffer ( char * buf,
SizeT bufSize ) const

copy to char buffer (return false if buffer is too small)

◆ Delete()

void Util::String::Delete ( )
inlineprivate

delete contents

◆ empty()

bool Util::String::empty ( ) const
inline

◆ EndsWithString()

bool Util::String::EndsWithString ( const String & s) const

returns true if string ends with string

◆ ExtractDirName()

String Util::String::ExtractDirName ( ) const

extract the part before the last directory separator

Return a String object containing the part before the last directory separator.

NOTE: I left my fix in that returns the last slash (or colon), this was necessary to tell if a dirname is a normal directory or an assign.

  • 17-Feb-04 floh fixed a bug when the path ended with a slash

◆ ExtractFileName()

String Util::String::ExtractFileName ( ) const
inline

extract the part after the last directory separator

Return a String object containing the part after the last path separator.

◆ ExtractLastDirName()

String Util::String::ExtractLastDirName ( ) const

extract the last directory of the path

Return a String object containing the last directory of the path, i.e.

a category.

  • 17-Feb-04 floh fixed a bug when the path ended with a slash

◆ ExtractRange()

String Util::String::ExtractRange ( IndexT fromIndex,
SizeT numChars ) const

extract substring

Extract a substring range.

◆ ExtractToEnd()

String Util::String::ExtractToEnd ( IndexT fromIndex) const

extract substring to end of this string

Extract a substring until the end of the original string.

◆ ExtractToLastSlash()

String Util::String::ExtractToLastSlash ( ) const
inline

extract path until last slash

Return a path string object which contains of the complete path up to the last slash.

Returns an empty string if there is no slash in the path.

◆ Fill()

void Util::String::Fill ( SizeT length,
unsigned char character )

set string length and fill all characters with arg

◆ FindCharIndex()

IndexT Util::String::FindCharIndex ( char c,
IndexT startIndex = 0 ) const

return index of character in string, or InvalidIndex if not found

Return index of character in string, or InvalidIndex if not found.

◆ FindStringIndex()

IndexT Util::String::FindStringIndex ( const String & s,
IndexT startIndex = 0 ) const

return start index of substring, or InvalidIndex if not found

Return the index of a substring, or InvalidIndex if not found.

◆ Format()

void __cdecl Util::String::Format ( const char * fmtString,
... )

format string printf-style

◆ FormatArgList()

void __cdecl Util::String::FormatArgList ( const char * fmtString,
va_list argList )

format string printf-style with varargs list

◆ From()

template<typename T >
static String Util::String::From ( const T & t)
static

convert from "anything"

◆ FromBase64()

Util::String Util::String::FromBase64 ( const String & in)
static

create from base64

◆ FromBlob()

String Util::String::FromBlob ( const Util::Blob & b)
static

create from blob

◆ FromBool()

String Util::String::FromBool ( bool b)
inlinestatic

construct a string from a bool

◆ FromByte()

String Util::String::FromByte ( byte i)
inlinestatic

construct a string from a byte

◆ FromDouble()

String Util::String::FromDouble ( double f)
inlinestatic

construct a string from a double

◆ FromFloat()

String Util::String::FromFloat ( float f)
inlinestatic

construct a string from a float

◆ FromFloat2()

String Util::String::FromFloat2 ( const Math::float2 & v)
inlinestatic

construct a string from float2

◆ FromFloat3()

String Util::String::FromFloat3 ( const Math::float3 & v)
inlinestatic

construct a string from float2

◆ FromFloat4()

String Util::String::FromFloat4 ( const Math::float4 & v)
inlinestatic

construct a string from float2

◆ FromInt()

String Util::String::FromInt ( int i)
inlinestatic

construct a string from an int

◆ FromLong()

String Util::String::FromLong ( long i)
inlinestatic

construct a string from a long

◆ FromLongLong()

Util::String Util::String::FromLongLong ( long long i)
inlinestatic

construct a string from a long long

◆ FromMat4()

String Util::String::FromMat4 ( const Math::mat4 & m)
inlinestatic

construct a string from mat4

◆ FromQuat()

String Util::String::FromQuat ( const Math::quat & q)
inlinestatic

construct a string from quat

◆ FromShort()

String Util::String::FromShort ( short i)
inlinestatic

construct a string from a short

◆ FromSize()

String Util::String::FromSize ( size_t i)
inlinestatic

construct a string from a size_t

◆ FromTransform44()

String Util::String::FromTransform44 ( const Math::transform44 & m)
inlinestatic

construct a string from transform44

◆ FromUByte()

String Util::String::FromUByte ( ubyte i)
inlinestatic

construct a string from a ubyte

◆ FromUInt()

String Util::String::FromUInt ( uint i)
inlinestatic

construct a string from a uint

◆ FromUShort()

String Util::String::FromUShort ( ushort i)
inlinestatic

construct a string from a ushort

◆ FromVec2()

String Util::String::FromVec2 ( const Math::vec2 & v)
inlinestatic

construct a string from vec2

◆ FromVec3()

String Util::String::FromVec3 ( const Math::vec3 & v)
inlinestatic

construct a string from vec3

◆ FromVec4()

String Util::String::FromVec4 ( const Math::vec4 & v)
inlinestatic

construct a string from vec4

◆ Get()

const char * Util::String::Get ( ) const
inline

*** OBSOLETE *** only Nebula2 compatibility

◆ GetFileExtension()

String Util::String::GetFileExtension ( ) const

get filename extension without dot

Returns
string representing the filename extension (maybe empty)

◆ GetLastSlash()

char * Util::String::GetLastSlash ( ) const
private

get pointer to last directory separator

Get a pointer to the last directory separator.

◆ Hash()

uint Util::String::Hash ( const char * c,
std::size_t s )
staticconstexpr

Hash a string.

◆ HashCode()

uint32_t Util::String::HashCode ( ) const
inline

return a 32-bit hash code for the string

This method computes a hash code for the string.

The method is compatible with the Util::HashTable class.

◆ Hex()

template<typename INTEGER >
String Util::String::Hex ( INTEGER i)
inlinestatic

construct a hex string from an int

◆ IsAlNum()

bool Util::String::IsAlNum ( char c)
static

test if provided character is an alpha-numeric character (A..Z,a..z,0..9)

◆ IsAlpha()

bool Util::String::IsAlpha ( char c)
static

test if provided character is an alphabet character (A..Z, a..z)

◆ IsDigit()

bool Util::String::IsDigit ( char c)
static

test if provided character is a digit (0..9)

◆ IsEmpty()

bool Util::String::IsEmpty ( ) const
inline

return true if string object is empty

◆ IsLower()

bool Util::String::IsLower ( char c)
static

test if provided character is a lower case character

◆ IsUpper()

bool Util::String::IsUpper ( char c)
static

test if provided character is an upper-case character

◆ IsValid() [1/2]

bool Util::String::IsValid ( ) const
inline

return true if string object is not empty

◆ IsValid() [2/2]

template<typename T >
bool Util::String::IsValid ( ) const

generic valid checker

◆ IsValidBool()

bool Util::String::IsValidBool ( ) const

return true if the content is a valid bool

◆ IsValidFloat()

bool Util::String::IsValidFloat ( ) const
inline

return true if the content is a valid float

Note: this method is not 100% correct, it just checks for invalid characters.

◆ IsValidInt()

bool Util::String::IsValidInt ( ) const
inline

return true if the content is a valid integer

◆ IsValidMat4()

bool Util::String::IsValidMat4 ( ) const

return true if content is a valid mat4

Note: this method is not 100% correct, it just checks for invalid characters.

◆ IsValidTransform44()

bool Util::String::IsValidTransform44 ( ) const

return true if content is a valid transform44

Note: this method is not 100% correct, it just checks for invalid characters.

◆ IsValidVec2()

bool Util::String::IsValidVec2 ( ) const

return true if the content is a valid vec2

Note: this method is not 100% correct, it just checks for invalid characters.

◆ IsValidVec4()

bool Util::String::IsValidVec4 ( ) const

return true if the content is a valid vec4

Note: this method is not 100% correct, it just checks for invalid characters.

◆ Length()

SizeT Util::String::Length ( ) const
inline

return length of string

◆ length()

size_t Util::String::length ( ) const
inline

◆ MatchPattern()

bool Util::String::MatchPattern ( const String & str,
const String & pattern )
static

pattern matching

Pattern-matching, TCL-style.

◆ operator+=()

void Util::String::operator+= ( const String & rhs)
inline

+= operator

◆ operator=() [1/3]

void Util::String::operator= ( const char * cStr)
inline

assign from const char*

◆ operator=() [2/3]

void Util::String::operator= ( const String & rhs)
inline

assignment operator

◆ operator=() [3/3]

void Util::String::operator= ( String && rhs)
inlinenoexcept

move operator

◆ operator[]() [1/2]

char & Util::String::operator[] ( IndexT i)
inline

read/write index operator

NOTE: unlike the read-only indexer, the terminating 0 is NOT a valid part of the string because it may not be overwritten!!!

◆ operator[]() [2/2]

char Util::String::operator[] ( IndexT i) const
inline

read-only index operator

◆ ParseKeyValuePairs()

Dictionary< String, String > Util::String::ParseKeyValuePairs ( const String & str)
static

parse key/value pair string ("key0=value0 key1=value1")

◆ Realloc()

void Util::String::Realloc ( SizeT newSize)
private

(re-)allocate the string buffer (copies old content)

(Re-)allocate external buffer and copy existing string contents there.

◆ ReplaceChars()

void Util::String::ReplaceChars ( const String & charSet,
char replacement )

replace any char set character within a string with the replacement character

◆ ReplaceIllegalFilenameChars()

void Util::String::ReplaceIllegalFilenameChars ( char replacement)
inline

replace illegal filename characters

◆ Reserve()

void Util::String::Reserve ( SizeT newSize)

reserve internal buffer size to prevent heap allocs

Reserves internal space to prevent excessive heap re-allocations.

If you plan to do many Append() operations this may help alot.

◆ Set() [1/3]

void Util::String::Set ( const char * ptr,
size_t length )

set as char ptr, with explicit length. will assert if size_t exceeds 2^32

◆ Set() [2/3]

void Util::String::Set ( const char * str,
SizeT length )

set as char ptr, with explicit length

Sets a new string content.

This will handle all special cases and try to minimize heap allocations as much as possible.

◆ Set() [3/3]

template<typename T >
void Util::String::Set ( const T & t)

generic setter

◆ SetBool()

void Util::String::SetBool ( bool val)

set as bool value

◆ SetByte()

void Util::String::SetByte ( byte val)

set as byte value

◆ SetCharPtr()

void Util::String::SetCharPtr ( const char * s)

set content to char ptr

◆ SetDouble()

void Util::String::SetDouble ( double val)

set as double value

◆ SetFloat()

void Util::String::SetFloat ( float val)

set as float value

◆ SetFloat2()

void Util::String::SetFloat2 ( const Math::float2 & v)

set as vec2 value

◆ SetFloat3()

void Util::String::SetFloat3 ( const Math::float3 & v)

set as vec3 value

◆ SetFloat4()

void Util::String::SetFloat4 ( const Math::float4 & v)

set as vec4 value

◆ SetInt()

void Util::String::SetInt ( int val)

set as int value

◆ SetLong()

void Util::String::SetLong ( long val)

set as long value

◆ SetLongLong()

void Util::String::SetLongLong ( long long val)

set as long long value

◆ SetMat4()

void Util::String::SetMat4 ( const Math::mat4 & v)

set as mat4 value

◆ SetQuaternion()

void Util::String::SetQuaternion ( const Math::quat & v)

set as quaternion

◆ SetShort()

void Util::String::SetShort ( short val)

set as short value

◆ SetSizeT()

void Util::String::SetSizeT ( size_t val)

set as long value

◆ SetTransform44()

void Util::String::SetTransform44 ( const Math::transform44 & v)

set as transform44 value

◆ SetUByte()

void Util::String::SetUByte ( ubyte val)

set as ubyte value

◆ SetUInt()

void Util::String::SetUInt ( uint val)

set as uint value

◆ SetUShort()

void Util::String::SetUShort ( ushort val)

set as ushort value

◆ SetVec2()

void Util::String::SetVec2 ( const Math::vec2 & v)

set as vec2 value

◆ SetVec3()

void Util::String::SetVec3 ( const Math::vec3 & v)

set as vec3 value

◆ SetVec4()

void Util::String::SetVec4 ( const Math::vec4 & v)

set as vec4 value

◆ Sprintf()

String Util::String::Sprintf ( const char * fmtString,
... )
static

static constructor for string using printf

◆ StrChr()

const char * Util::String::StrChr ( const char * str,
int c )
static

find character in string

◆ StrCmp()

int Util::String::StrCmp ( const char * str0,
const char * str1 )
static

lowlevel string compare wrapper function

◆ Strip()

void Util::String::Strip ( const String & charSet)

terminate string at first occurence of character in set

Terminates the string at the first occurance of one of the characters in charSet.

◆ StripAssignPrefix()

void Util::String::StripAssignPrefix ( )

remove assign prefix (for example tex:)

◆ StripFileExtension()

void Util::String::StripFileExtension ( )

remove file extension

Remove the file extension.

◆ StrLen()

int Util::String::StrLen ( const char * str)
static

lowlevel string length function

◆ SubstituteChar()

void Util::String::SubstituteChar ( char c,
char subst )
inline

substitute every occurance of a character with another character

Replace character with another.

◆ SubstituteString()

void Util::String::SubstituteString ( const String & str,
const String & substStr )

substitute every occurance of a string with another string

Substitute every occurance of origStr with substStr.

◆ TerminateAtIndex()

void Util::String::TerminateAtIndex ( IndexT index)

terminate string at given index

Terminates the string at the given index.

◆ Tokenize() [1/4]

Array< String > Util::String::Tokenize ( const String & whiteSpace) const

tokenize string into a provided String array, SLOW since new array will be constructed

This is the slow-but-convenient Tokenize() method.

Slow since the returned string array will be constructed anew with every method call. Consider the Tokenize() method which takes a string array as input, since this may allow reusing of the array, reducing heap allocations.

◆ Tokenize() [2/4]

SizeT Util::String::Tokenize ( const String & whiteSpace,
Array< String > & outTokens ) const

tokenize string into a provided String array (faster if tokens array can be reused)

Tokenize the string into a String array.

Parameters
whiteSpacea string containing the whitespace characters
Returns
a string array of tokens

◆ Tokenize() [3/4]

Array< String > Util::String::Tokenize ( const String & whiteSpace,
char fence ) const

tokenize string, keep strings within fence characters intact, SLOW since new array will be constructed

Slow version of Tokenize() with fence character.

See above Tokenize() for details.

◆ Tokenize() [4/4]

SizeT Util::String::Tokenize ( const String & whiteSpace,
char fence,
Array< String > & outTokens ) const

tokenize string, keep strings within fence characters intact (faster if tokens array can be reused)

Tokenize a string, but keeps the string within the fence-character intact.

For instance for the sentence:

He said: "I don't know."

A Tokenize(" ", '"', tokens) would return:

token 0: He token 1: said: token 2: I don't know.

◆ ToLower()

void Util::String::ToLower ( )

convert string to lower case

◆ ToUpper()

void Util::String::ToUpper ( )

convert string to upper case

◆ Trim()

void Util::String::Trim ( const String & charSet)

trim characters from charset at both sides of string

Trim both sides of a string.

◆ TrimLeft()

void Util::String::TrimLeft ( const String & charSet)

delete characters from charset at left side of string

Removes all characters in charSet from the left side of the string.

◆ TrimRight()

void Util::String::TrimRight ( const String & charSet)

delete characters from charset at right side of string

Removes all characters in charSet from the right side of the string.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const String & a,
const String & b )
friend

inequality operator

◆ operator<

bool operator< ( const String & a,
const String & b )
friend

less-then operator

◆ operator<=

bool operator<= ( const String & a,
const String & b )
friend

less-or-equal operator

◆ operator== [1/4]

bool operator== ( const char * cStr,
const String & a )
friend

shortcut equality operator

◆ operator== [2/4]

bool operator== ( const String & a,
const char * cStr )
friend

shortcut equality operator

◆ operator== [3/4]

bool operator== ( const String & a,
const String & b )
friend

equality operator

◆ operator== [4/4]

bool operator== ( const String & a,
std::nullptr_t  )
friend

empty string operator

◆ operator>

bool operator> ( const String & a,
const String & b )
friend

greater-then operator

◆ operator>=

bool operator>= ( const String & a,
const String & b )
friend

greater-then operator

Member Data Documentation

◆ heap

string Util.String.heap

◆ heapBuffer

char* Util::String::heapBuffer
private

◆ heapBufferSize [1/2]

int Util.String.heapBufferSize

◆ heapBufferSize [2/2]

SizeT Util::String::heapBufferSize
private

◆ local

fixed char Util.String.local[20]

◆ localBuffer

char Util::String::localBuffer[LocalStringSize]
private

◆ strLen [1/2]

int Util.String.strLen

◆ strLen [2/2]

SizeT Util::String::strLen
private

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