class GString: protected GP<GStringRep>

General purpose character string.

Inheritance:


Public Methods

[more] GString( void )
Null constructor.
[more] GString(const GString &gs)
Copy constructor. Constructs a string by copying the string gs.
[more] GString(const char dat)
Constructs a string from a character.
[more] GString(const char *dat)
Constructs a string from a null terminated character array.
[more] GString(const char *dat, unsigned int len)
Constructs a string from a character array.
[more] GString(const GString &gs, int from, unsigned int len)
Construct a string by copying a sub-string.
[more] GString(const int number)
Constructs a string with a human-readable representation of integer number.
[more] GString(const double number)
Constructs a string with a human-readable representation of floating point number number.
[more]GString& operator= (const GString &gs)
Copy operator.
[more]GString& operator= (const char *str)
Copy a null terminated character array.
[more] operator const char* ( void ) const
Converts a string into a constant null terminated character array.
[more]unsigned int length( void ) const
Returns the string length.
[more]int operator! ( void ) const
Returns true if and only if the string contains zero characters.
[more]char operator[] (int n) const
Returns the character at position n.
[more]void setat(int n, char ch)
Set the character at position n to value ch.
[more]bool is_int(void) const
Returns TRUE if the string contains an integer number.
[more]bool is_float(void) const
Returns TRUE if the string contains a float number.
[more]GString substr(int from, unsigned int len=1) const
Returns a sub-string.
[more]GString upcase( void ) const
Returns an upper case copy of this string.
[more]GString downcase( void ) const
Returns an lower case copy of this string.
[more]GString toEscaped(void ) const
Returns a copy of this string with characters used in XML with '<' to "&lt;", '>' to "&gt;", '&' to "&amp;" '\'' to "&apos;", and '\"' to "&quot;".
[more]GString fromEscaped( void ) const
Converts strings containing HTML/XML escaped characters (eg, "&lt;" for "<") into their unescaped forms.
[more]GString fromEscaped( const GMap<GString, GString> ConvMap ) const
Converts strings containing HTML/XML escaped characters (eg, "&lt;" for "<") into their unescaped forms.
[more]void empty( void )
Reinitializes a string with the null string.
[more]char* getbuf(int n = -1)
Provides a direct access to the string buffer.
[more]void format(const char *fmt, ... )
Initializes a string with a formatted string (as in printf).
[more]void format(const char *fmt, va_list args)
Initializes a string with a formatted string (as in vprintf).
[more]int search(char c, int from=0) const
Searches character c in the string, starting at position from and scanning forward until reaching the end of the string.
[more]int search(const char *str, int from=0) const
Searches sub-string str in the string, starting at position from and scanning forward until reaching the end of the string.
[more]int rsearch(char c, int from=-1) const
Searches character c in the string, starting at position from and scanning backwards until reaching the beginning of the string.
[more]int rsearch(const char *str, int from=-1) const
Searches sub-string str in the string, starting at position from and scanning backwards until reaching the beginning of the string.
[more]GString& operator+= (char ch)
Appends character ch to the string.
[more]GString& operator+= (const char *str)
Appends the null terminated character array str to the string.
[more]friend GString operator+(const GString &s1, const GString &s2)
Concatenates strings.
[more]friend int operator==(const GString &s1, const GString &s2)
String comparison.
[more]friend int operator!=(const GString &s1, const GString &s2)
String comparison.
[more]friend int operator>=(const GString &s1, const GString &s2)
String comparison.
[more]friend int operator> (const GString &s1, const GString &s2)
String comparison.
[more]friend int operator<=(const GString &s1, const GString &s2)
String comparison.
[more]friend int operator< (const GString &s1, const GString &s2)
String comparison.
[more]friend unsigned int hash(const GString &ref)
Returns a hash code for the string.


Inherited from GP:

Public Methods

o operator TYPE* () const
oTYPE* operator->() const
oTYPE& operator*() const
oint operator== (TYPE *nptr) const
oint operator!= (TYPE *nptr) const


Inherited from GPBase:

Public Methods

oGPEnabled* get() const
oGPBase& assign(const GPBase &sptr)
oGPBase& assign(GPEnabled *nptr)
oGPBase& operator=(const GPBase & obj)

Protected Fields

oGPEnabled* ptr


Documentation

General purpose character string. Each instance of class GString represents a character string. Overloaded operators provide a value semantic to GString objects. Conversion operators and constructors transparently convert between GString objects and const char* pointers.

Functions taking strings as arguments should declare their arguments as "const char*". Such functions will work equally well with GString objects since there is a fast conversion operator from GString to "const char*". Functions returning strings should return GString objects because the class will automatically manage the necessary memory.

Characters in the string can be identified by their position. The first character of a string is numbered zero. Negative positions represent characters relative to the end of the string (i.e. position -1 accesses the last character of the string, position -2 represents the second last character, etc.)

o GString( void )
Null constructor. Constructs an empty string.

o GString(const GString &gs)
Copy constructor. Constructs a string by copying the string gs.

o GString(const char dat)
Constructs a string from a character.

o GString(const char *dat)
Constructs a string from a null terminated character array.

o GString(const char *dat, unsigned int len)
Constructs a string from a character array. Elements of the character array dat are added into the string until the string length reaches len or until encountering a null character (whichever comes first).

o GString(const GString &gs, int from, unsigned int len)
Construct a string by copying a sub-string. The string will be initialized with at most len characters from string gs starting at position from. The length of the constructed string may be smaller than len if the specified range is too large.

o GString(const int number)
Constructs a string with a human-readable representation of integer number. The format is similar to format "%d" in function printf.

o GString(const double number)
Constructs a string with a human-readable representation of floating point number number. The format is similar to format "%f" in function printf.

oGString& operator= (const GString &gs)
Copy operator. Resets this string with the value of the string gs. This operation is efficient because string memory is allocated using a "copy-on-write" strategy. Both strings will share the same segment of memory until one of the strings is modified.

oGString& operator= (const char *str)
Copy a null terminated character array. Resets this string with the character string contained in the null terminated character array str.

o operator const char* ( void ) const
Converts a string into a constant null terminated character array. This conversion operator is very efficient because it simply returns a pointer to the internal string data. The returned pointer remains valid as long as the string is unmodified.

ounsigned int length( void ) const
Returns the string length.

oint operator! ( void ) const
Returns true if and only if the string contains zero characters. This operator is useful for conditional expression in control structures.
         if (! str) { ... }
         while (!! str) { ... }  -- Note the double operator!
      
Class GString does not to support syntax " the required conversion operator introduces dangerous ambiguities with certain compilers.

ochar operator[] (int n) const
Returns the character at position n. An exception GException is thrown if number n is not in range -len to len-1, where len is the length of the string. The first character of a string is numbered zero. Negative positions represent characters relative to the end of the string.

ovoid setat(int n, char ch)
Set the character at position n to value ch. An exception GException is thrown if number n is not in range -len to len, where len is the length of the string. If character ch is zero, the string is truncated at position n. The first character of a string is numbered zero. Negative positions represent characters relative to the end of the string. If position n is equal to the length of the string, this function appends character ch to the end of the string.

obool is_int(void) const
Returns TRUE if the string contains an integer number.

obool is_float(void) const
Returns TRUE if the string contains a float number.

oGString substr(int from, unsigned int len=1) const
Returns a sub-string. The sub-string is composed by copying len characters starting at position from in this string. The length of the resulting string may be smaller than len if the specified range is too large.

oGString upcase( void ) const
Returns an upper case copy of this string. The returned string contains a copy of the current string with all letters turned into upper case letters.

oGString downcase( void ) const
Returns an lower case copy of this string. The returned string contains a copy of the current string with all letters turned into lower case letters.

oGString toEscaped(void ) const
Returns a copy of this string with characters used in XML with '<' to "&lt;", '>' to "&gt;", '&' to "&amp;" '\'' to "&apos;", and '\"' to "&quot;". Characters 0x01 through 0x1f are also escaped.

oGString fromEscaped( void ) const
Converts strings containing HTML/XML escaped characters (eg, "&lt;" for "<") into their unescaped forms. The conversion is partially defined by the ConvMap argument which specifies the conversion strings to be recognized. The default BasicMap inverts the actions of toEscaped(). Numeric representation of characters (e.g., "&38;" or "&x26;" for "*") are always converted.

oGString fromEscaped( const GMap<GString, GString> ConvMap ) const
Converts strings containing HTML/XML escaped characters (eg, "&lt;" for "<") into their unescaped forms. The conversion is partially defined by the ConvMap argument which specifies the conversion strings to be recognized. The default BasicMap inverts the actions of toEscaped(). Numeric representation of characters (e.g., "&38;" or "&x26;" for "*") are always converted.

ovoid empty( void )
Reinitializes a string with the null string.

ochar* getbuf(int n = -1)
Provides a direct access to the string buffer. Returns a pointer for directly accessing the string buffer. This pointer valid remains valid as long as the string is not modified by other means. Positive values for argument n represent the length of the returned buffer. The returned string buffer will be large enough to hold at least n characters plus a null character. If n is positive but smaller than the string length, the string will be truncated to n characters.

ovoid format(const char *fmt, ... )
Initializes a string with a formatted string (as in printf). The string is re-initialized with the characters generated according to the specified format fmt and using the optional arguments. See the Ansi-C function printf() for more information. The current implementation will cause a segmentation violation if the resulting string is longer than 32768 characters.

ovoid format(const char *fmt, va_list args)
Initializes a string with a formatted string (as in vprintf). The string is re-initialized with the characters generated according to the specified format fmt and using the optional arguments. See the Ansi-C function vprintf() for more information. The current implementation will cause a segmentation violation if the resulting string is longer than 32768 characters.

oint search(char c, int from=0) const
Searches character c in the string, starting at position from and scanning forward until reaching the end of the string. This function returns the position of the matching character. It returns -1 if character c cannot be found.

oint search(const char *str, int from=0) const
Searches sub-string str in the string, starting at position from and scanning forward until reaching the end of the string. This function returns the position of the first matching character of the sub-string. It returns -1 if string str cannot be found.

oint rsearch(char c, int from=-1) const
Searches character c in the string, starting at position from and scanning backwards until reaching the beginning of the string. This function returns the position of the matching character. It returns -1 if character c cannot be found.

oint rsearch(const char *str, int from=-1) const
Searches sub-string str in the string, starting at position from and scanning backwards until reaching the beginning of the string. This function returns the position of the first matching character of the sub-string. It returns -1 if string str cannot be found.

oGString& operator+= (char ch)
Appends character ch to the string.

oGString& operator+= (const char *str)
Appends the null terminated character array str to the string.

ofriend GString operator+(const GString &s1, const GString &s2)
Concatenates strings. Returns a string composed by concatenating the characters of strings s1 and s2.

ofriend int operator==(const GString &s1, const GString &s2)
String comparison. Returns true if and only if character strings s1 and s2 are equal (as with strcmp.)

ofriend int operator!=(const GString &s1, const GString &s2)
String comparison. Returns true if and only if character strings s1 and s2 are not equal (as with strcmp.)

ofriend int operator>=(const GString &s1, const GString &s2)
String comparison. Returns true if and only if character strings s1 is lexicographically greater than or equal to string s2 (as with strcmp.)

ofriend int operator> (const GString &s1, const GString &s2)
String comparison. Returns true if and only if character strings s1 is lexicographically greater than string s2 (as with strcmp.)

ofriend int operator<=(const GString &s1, const GString &s2)
String comparison. Returns true if and only if character strings s1 is lexicographically less than or equal to string s2 (as with strcmp.)

ofriend int operator< (const GString &s1, const GString &s2)
String comparison. Returns true if and only if character strings s1 is lexicographically less than string s2 (as with strcmp.)

ofriend unsigned int hash(const GString &ref)
Returns a hash code for the string. This hashing function helps when creating associative maps with string keys (see GMap). This hash code may be reduced to an arbitrary range by computing its remainder modulo the upper bound of the range.


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java


DjVu is a trademark of LizardTech, Inc.
All other products mentioned are registered trademarks or trademarks of their respective companies.