Gizmo3D

gzString Class Reference

Provides a generic string management class. More...

#include <gzBase.h>

Inheritance diagram for gzString:

gzRefData< gzString > gzUniqueString List of all members.

Public Member Functions

 gzString ()
 Default constructor of a gzString.
 gzString (const char *str)
 Create a gzString from a C string.
 gzString (const char *str, gzUShort len)
 gzString (const gzString &str)
virtual ~gzString ()
 gzString (const gzWideChar *widestr)
 gzString (const gzWideChar *widestr, gzUShort len, gzBool isPlain=FALSE)
 gzString (gzLongLong number, gzUByte radix, gzULong minLen=0)
 gzString (gzDouble number, const gzString &format="")
gzUShort length () const
gzVoid clear ()
const char * getString () const
gzLongLong num () const
gzDouble real (gzUShort decimalToken='.') const
gzDouble sortval () const
gzBool contains (const gzString &substr, gzUShort startindex=0, gzBool caseSensitive=TRUE, gzUShort *index=NULL) const
 Search for substring.
gzString rightOf (const gzString &substr, gzBool searchFromEnd=TRUE, gzBool caseSensitive=TRUE) const
 Extract substring.
gzString leftOf (const gzString &substr, gzBool searchFromStart=TRUE, gzBool caseSensitive=TRUE) const
 Extract substring.
gzString toLower () const
 Convert to lower ascii representation. Does not work with WIDE strings.
gzString toUpper () const
 Convert to upper ascii representation. Does not work with WIDE strings.
gzString left (gzULong count, gzBool inverse=FALSE) const
gzString right (gzULong count, gzBool inverse=FALSE) const
gzString strip (char c, gzBool left=TRUE, gzBool right=TRUE) const
gzString stripWhiteSpace (gzBool left=TRUE, gzBool right=TRUE) const
gzVoid reverse ()
 Reverse the string contents. Does not work with WIDE strings.
gzULong hash () const
 Return a rather unique number that represents the string.
gzBool isEmpty () const
 Check for empty string.
gzBool isFirst (const gzString &str, gzBool caseSensitive=TRUE) const
 Check prefix character.
gzBool isFirst (const char ch, gzBool caseSensitive=TRUE) const
 Check prefix character.
gzBool isLast (const gzString &str, gzBool caseSensitive=TRUE) const
 Check postfix character.
gzBool isLast (const char ch, gzBool caseSensitive=TRUE) const
 Check postfix character.
gzStringformat (const gzString &format, ARG_DECL_LIST)
 Recreate the string based on a formatting sequence.
gzStringidentifier (gzLongLong number)
gzUShort getWideStringLength () const
 Get The length of the wide string representation.
gzUShort getWideString (gzWideChar *buffer, gzBool appendZero=TRUE) const
 Get the wide string data into a buffer.
gzBool hasEscapedUTF8Chars () const
 Tell you if the string has possible escaped UTF8 chars.
gzBool isAsciiString () const
 Tell you if you have a ascii sequence that is no UTF8 valid sequence.
gzString convertAsciiToUTF8 () const
 Convert from Ascii to UTF8.
gzString convertUTF8ToAscii () const
 Convert from UTF8 to Ascii.
gzString convertUTF8ToNumList (const gzString &format="0x%02x", const gzString &separator=",") const
gzString convertNumListToUTF8 () const
gzString convertTextToCtrl () const
gzString convertCtrlToText () const
const gzWideChargetWideString (gzUShort knownLength=0) const
 Get a pointer to a null terminated gzWideChar buffer.
gzArray< gzUBytegetBSTR () const
 Get a BSTR that contains the length in the first byte. No appended zero in the end.
gzArray< gzWideChargetWideBSTR () const
 Get a Wide BSTR that contains the length in the first gzWideChar. No appended zero in the end.
gzStringscramble (gzULong code)
 Scrambles the string with the code value.
gzLongLong dotValue (gzULong base=256, gzULong *groups=NULL) const
 Get the dot value e.g. "255.234.245.23".
gzUShort substitute (char from, char to)
 Changes character from into a to character.
gzBool yesNo ()
 returns True if string contains "yes"
gzBool isUnique () const
gzUShort getUniqueID () const
gzBool makeUnique (gzUShort uniqueID=0)
gzBool checkUnique () const
 operator gzLongLong () const
 operator gzDouble () const
gzStringoperator= (const char *str)
 operator const char * () const
gzStringoperator= (const gzString &str)
gzStringoperator+= (const char *str)
gzString operator+ (const char *str) const
gzString operator+ (const gzString &str) const
gzStringoperator+= (const gzString &str)
gzStringoperator+= (const char c)
gzStringoperator+= (const gzWideChar wc)
gzString operator+ (const char c) const
gzString operator+ (const gzWideChar wc) const
gzBool operator! () const
char & operator() (const gzUShort index)
gzString operator() (const gzUShort index, const gzUShort len) const

Static Public Member Functions

static gzULong hash (const char *s, gzULong size=0)
 Calcualtes the hash value of the buffer s with size.
static gzString spaces (gzUShort count, const char fillChar=' ')

Public Attributes

 GZ_DECLARE_TYPE_INTERFACE

Friends

gzBool operator== (const gzString &str, const char *s)
gzBool operator== (const char *s, const gzString &str)
gzBool operator== (const gzString &str1, const gzString &str2)
gzBool operator!= (const gzString &str, const char *s)
gzBool operator!= (const char *s, const gzString &str)
gzBool operator!= (const gzString &str1, const gzString &str2)
gzBool operator< (const gzString &str, const char *s)
gzBool operator< (const char *s, const gzString &str)
gzBool operator< (const gzString &str1, const gzString &str2)
gzBool operator> (const gzString &str, const char *s)
gzBool operator> (const char *s, const gzString &str)
gzBool operator> (const gzString &str1, const gzString &str2)
gzBool operator<= (const gzString &str, const char *s)
gzBool operator<= (const char *s, const gzString &str)
gzBool operator<= (const gzString &str1, const gzString &str2)
gzBool operator>= (const gzString &str, const char *s)
gzBool operator>= (const char *s, const gzString &str)
gzBool operator>= (const gzString &str1, const gzString &str2)

Detailed Description

Provides a generic string management class.

The gzString class is Gizmo3D generic class for string management. It encapsulates C strings (null terminated) and provides methods for comparing, sub string search etc.

Examples:

dbviewer.cpp, lod.cpp, materialDemo.cpp, mirror.cpp, node.cpp, shaders.cpp, skybox.cpp, and tree.cpp.

Definition at line 91 of file gzBase.h.


Constructor & Destructor Documentation

gzString::gzString  )  [inline]
 

Default constructor of a gzString.

Creates an empty string. No allocation of "string" memory is done. However a (cast) to a const char * returns a pointer to a zero terminated empty C string.

Definition at line 104 of file gzBase.h.

gzString::gzString const char *  str  )  [inline]
 

Create a gzString from a C string.

Creates a gzString from a C string pointer. Remember to have a zero terminated string as input !!

Parameters:
str A null terminated C string

Definition at line 109 of file gzBase.h.

gzString::gzString const char *  str,
gzUShort  len
 

gzString::gzString const gzString str  ) 
 

virtual gzString::~gzString  )  [virtual]
 

gzString::gzString const gzWideChar widestr  ) 
 

Creates a gzString from a WIDE string pointer. The gzString will be encoded into UTF8 if the character values are greater than 0x7f

Parameters:
widestr A NULL terminated WIDE string
See also:
getWideString

gzString::gzString const gzWideChar widestr,
gzUShort  len,
gzBool  isPlain = FALSE
 

gzString::gzString gzLongLong  number,
gzUByte  radix,
gzULong  minLen = 0
 

Creates a string representation of the number. Use radix=10 to create normal decimal number, Use radix=16 to create Hex.

Parameters:
number The number to be converted into a string representation.
radix The base radix of the number conversion.
minLen The minimum length.

gzString::gzString gzDouble  number,
const gzString format = ""
 

creates a string representation of the gzDouble number. You can provide formatting (printf) sequence to customize output

Parameters:
number The number (gzDouble) to be converted
format A (printf) formatting sequence. Defaults to "%f"


Member Function Documentation

gzBool gzString::checkUnique  )  const
 

gzVoid gzString::clear  ) 
 

Clears the contents of the string

gzBool gzString::contains const gzString substr,
gzUShort  startindex = 0,
gzBool  caseSensitive = TRUE,
gzUShort index = NULL
const
 

Search for substring.

Returns TRUE if substr is found withing the string. FALSE if not.

Parameters:
substr The string to search for
startindex The character position to start searching for the substr.
caseSensitive Set to TRUE if the search should be case sensitive
index A pointer to a gzULong to get the actual position of the substr

gzString gzString::convertAsciiToUTF8  )  const
 

Convert from Ascii to UTF8.

Sometimes you have ascii data with e.g. едц characters that are not valid UTF8 characters and therefor you can not convert between UTF8 and gzWideChar. This method casts Ascii to UTF8

gzString gzString::convertCtrlToText  )  const
 

gzString gzString::convertNumListToUTF8  )  const
 

gzString gzString::convertTextToCtrl  )  const
 

gzString gzString::convertUTF8ToAscii  )  const
 

Convert from UTF8 to Ascii.

Sometimes you want tp have have ascii data with e.g. едц characters that are not valid UTF8 characters and therefor you can not convert between UTF8 and Ascii. This method casts UTF8 to Ascii

gzString gzString::convertUTF8ToNumList const gzString format = "0x%02x",
const gzString separator = ","
const
 

gzLongLong gzString::dotValue gzULong  base = 256,
gzULong groups = NULL
const
 

Get the dot value e.g. "255.234.245.23".

Use this to convert Ip adresses etc into a large number

gzString& gzString::format const gzString format,
ARG_DECL_LIST 
 

Recreate the string based on a formatting sequence.

The method works like a sprintf method to create a string out of a format sequence. The ARG_DECL_LIST is a type specified ecliptic argument that can hold 10 values e.g.

    
    gzString a;

    a.format("%f",10.27);

Creates a string "10.27"

    formats: %<pos><flags><width><precision><size><type>

    <pos>
    number$ uses number to get argument at position 1 to 16. Number is ended by $
    *$      takes argument and uses that value as argument position 1-16

    <flags>
    -       left align within width field. Default is to right align
    +       prefix width sign if output is number type
    0       insert 0 if number value and no + prefix
    ' ' (blank) prefix with a space, ignore if + prefix 

    <precision>
    .number for type 's' or 'S' number specifies the number of characters in string.
            for type 'f' number specifies the number of decimals
            

    <type>
    c       takes a number n and insert wide char token with value n in string
    s       takes pointer to null terminated ansi string or ansii gzString and inserts ansii string
    S       takes pointer to null terminated unicode string or utf8 gzString and inserts unicode string
    f       takes number and inserts plain number [-]ddd.ddd in string
    e       takes number and insert exponential number [-]d.dddd e [sign]dd in string
    E       takes number and insert exponential number [-]d.dddd E [sign]dd in string
    g       takes number and insers most compact format of f or e
    G       takes number and insers most compact format of f or E
    d       takes signed integer and inserts integer value in string
    u       takes unsigned integer and inserts unsigned integer value in string
    x       takes unsigned integer and inserts hex lower case value in string 
    X       takes unsigned integer and inserts hex upper case value in string
    b       takes unsigned integer and inserts binary lower case value in string
    B       takes unsigned integer and inserts binary upper case value in string
    o       takes unsigned integer and inserts octal lower case value in string
    O       takes unsigned integer and inserts octal upper case value in string

gzArray<gzUByte> gzString::getBSTR  )  const
 

Get a BSTR that contains the length in the first byte. No appended zero in the end.

const char* gzString::getString  )  const
 

Returns a C string representation of the gzString. The buffer is terminated by a ZERO

gzUShort gzString::getUniqueID  )  const
 

gzArray<gzWideChar> gzString::getWideBSTR  )  const
 

Get a Wide BSTR that contains the length in the first gzWideChar. No appended zero in the end.

const gzWideChar* gzString::getWideString gzUShort  knownLength = 0  )  const
 

Get a pointer to a null terminated gzWideChar buffer.

gzUShort gzString::getWideString gzWideChar buffer,
gzBool  appendZero = TRUE
const
 

Get the wide string data into a buffer.

The buffer need to have the appropriate size so the buffer doesn't get overflowed. Use the getWideStringLength() to create a buffer and remember to append a zero slot at the end of you want a NULL terminated wide string

gzUShort gzString::getWideStringLength  )  const
 

Get The length of the wide string representation.

gzBool gzString::hasEscapedUTF8Chars  )  const
 

Tell you if the string has possible escaped UTF8 chars.

static gzULong gzString::hash const char *  s,
gzULong  size = 0
[static]
 

Calcualtes the hash value of the buffer s with size.

gzULong gzString::hash  )  const [inline]
 

Return a rather unique number that represents the string.

Definition at line 200 of file gzBase.h.

gzString& gzString::identifier gzLongLong  number  ) 
 

gzBool gzString::isAsciiString  )  const
 

Tell you if you have a ascii sequence that is no UTF8 valid sequence.

gzBool gzString::isEmpty  )  const [inline]
 

Check for empty string.

Definition at line 203 of file gzBase.h.

gzBool gzString::isFirst const char  ch,
gzBool  caseSensitive = TRUE
const
 

Check prefix character.

gzBool gzString::isFirst const gzString str,
gzBool  caseSensitive = TRUE
const
 

Check prefix character.

gzBool gzString::isLast const char  ch,
gzBool  caseSensitive = TRUE
const
 

Check postfix character.

gzBool gzString::isLast const gzString str,
gzBool  caseSensitive = TRUE
const
 

Check postfix character.

gzBool gzString::isUnique  )  const
 

gzString gzString::left gzULong  count,
gzBool  inverse = FALSE
const
 

gzString gzString::leftOf const gzString substr,
gzBool  searchFromStart = TRUE,
gzBool  caseSensitive = TRUE
const
 

Extract substring.

Extracts the contents of the gzString on the left side of the substr.

Parameters:
substr The substring to mark the end where to find the left side substring
searchFromStart TRUE if the search for the substr is to be done from the start
caseSensitive TRUE if the substring match is case sensitive

gzUShort gzString::length  )  const [inline]
 

Returns the number of UTF8 characters in the string. Remember to use getWideStringLength for WIDE strings.

Definition at line 139 of file gzBase.h.

gzBool gzString::makeUnique gzUShort  uniqueID = 0  ) 
 

gzLongLong gzString::num  )  const
 

Return a gzLongLong representation of the string

gzString::operator const char *  )  const
 

gzString::operator gzDouble  )  const [inline]
 

Definition at line 342 of file gzBase.h.

gzString::operator gzLongLong  )  const [inline]
 

Definition at line 340 of file gzBase.h.

gzBool gzString::operator!  )  const [inline]
 

Definition at line 367 of file gzBase.h.

References NULL, and TRUE.

gzString gzString::operator() const gzUShort  index,
const gzUShort  len
const
 

char& gzString::operator() const gzUShort  index  ) 
 

gzString gzString::operator+ const gzWideChar  wc  )  const
 

gzString gzString::operator+ const char  c  )  const
 

gzString gzString::operator+ const gzString str  )  const
 

gzString gzString::operator+ const char *  str  )  const
 

gzString& gzString::operator+= const gzWideChar  wc  ) 
 

gzString& gzString::operator+= const char  c  ) 
 

gzString& gzString::operator+= const gzString str  ) 
 

gzString& gzString::operator+= const char *  str  ) 
 

gzString& gzString::operator= const gzString str  ) 
 

gzString& gzString::operator= const char *  str  ) 
 

gzDouble gzString::real gzUShort  decimalToken = '.'  )  const
 

Return a gzDouble representation of the string

gzVoid gzString::reverse  ) 
 

Reverse the string contents. Does not work with WIDE strings.

gzString gzString::right gzULong  count,
gzBool  inverse = FALSE
const
 

gzString gzString::rightOf const gzString substr,
gzBool  searchFromEnd = TRUE,
gzBool  caseSensitive = TRUE
const
 

Extract substring.

Extracts the contents of the gzString on the right side of the substr.

Parameters:
substr The substring to mark the start where to find the right side substring
searchFromEnd TRUE if the search for the substr is to be done from the end
caseSensitive TRUE if the substring match is case sensitive

gzString& gzString::scramble gzULong  code  ) 
 

Scrambles the string with the code value.

gzDouble gzString::sortval  )  const
 

static gzString gzString::spaces gzUShort  count,
const char  fillChar = ' '
[static]
 

gzString gzString::strip char  c,
gzBool  left = TRUE,
gzBool  right = TRUE
const
 

Remove characters from start and end of string.

Parameters:
c the character number to strip
left TRUE if to strip from the left
right TRUE if to strip from the right

gzString gzString::stripWhiteSpace gzBool  left = TRUE,
gzBool  right = TRUE
const
 

gzUShort gzString::substitute char  from,
char