PixelLightAPI  .
Public Types | Public Member Functions | Static Public Member Functions | Friends
PLCore::String Class Reference

String class. More...

#include <String.h>

List of all members.

Public Types

enum  EFormat { ASCII = 0, Unicode = 1, UTF8 = 2 }
 Internal string format. More...

Public Member Functions

 String ()
 Default constructor.
PLCORE_API String (char nValue)
 Character constructor.
PLCORE_API String (wchar_t nValue)
PLCORE_API String (const char *pszString, bool bCopy=true, int nLength=-1)
 Constructor.
PLCORE_API String (const wchar_t *pszString, bool bCopy=true, int nLength=-1)
PLCORE_API String (const String &sString)
 Copy constructor.
 String (bool bValue)
 Number constructor.
PLCORE_API String (int nValue)
 String (int64 nValue)
 String (uint8 nValue)
 String (uint32 nValue)
 String (uint64 nValue)
 String (float fValue)
 String (double fValue)
 String (void *pValue)
 Pointer constructor.
 String (StringBuffer *pStringBuffer)
 Internal copy constructor.
 ~String ()
 Destructor.
uint32 GetLength () const
 Returns the length of the string.
EFormat GetFormat () const
 Returns the internal string format.
PLCORE_API uint32 GetNumOfBytes (EFormat nFormat) const
 Returns the number of bytes the string is using in a specified format (ASCII, Unicode, UTF8)
char operator[] (uint32 nIndex) const
 Get a ASCII character of the string.
const char * GetASCII () const
 Returns the character string as ASCII.
 operator const char * () const
 Returns the character string as ASCII.
const wchar_t * GetUnicode () const
 Returns the character string as Unicode.
 operator const wchar_t * () const
 Returns the character string as Unicode.
Stringoperator= (const String &sString)
 Copy operator.
PLCORE_API Stringoperator= (const char *pszString)
 Copy operator.
PLCORE_API Stringoperator= (const wchar_t *pszString)
PLCORE_API String operator+ (const String &sString) const
 Concatenate strings.
PLCORE_API String operator+ (const char *pszString) const
 Concatenate strings.
PLCORE_API String operator+ (const wchar_t *pszString) const
PLCORE_API Stringoperator+= (const String &sString)
 Concatenate strings.
PLCORE_API Stringoperator+= (const char *pszString)
 Concatenate strings.
PLCORE_API Stringoperator+= (const wchar_t *pszString)
PLCORE_API bool operator< (const String &sString) const
 Compares this string and the given one lexicographically.
PLCORE_API bool operator< (const char *pszString) const
 Compares this string and the given one lexicographically.
PLCORE_API bool operator< (const wchar_t *pszString) const
PLCORE_API bool operator> (const String &sString) const
 Compares this string and the given one lexicographically.
PLCORE_API bool operator> (const char *pszString) const
 Compares this string and the given one lexicographically.
PLCORE_API bool operator> (const wchar_t *pszString) const
bool operator== (const String &sString) const
 Compare operator (case sensitive)
bool operator== (const char *pszString) const
 Compare operator (case sensitive)
bool operator== (const wchar_t *pszString) const
bool operator!= (const String &sString) const
 Compare operator (case sensitive)
bool operator!= (const char *pszString) const
 Compare operator (case sensitive)
bool operator!= (const wchar_t *pszString) const
PLCORE_API bool Compare (const String &sString, uint32 nPos=0, int nCount=-1) const
 Compare function (case sensitive)
PLCORE_API bool Compare (const char *pszString, uint32 nPos=0, int nCount=-1) const
 Compare function (case sensitive)
PLCORE_API bool Compare (const wchar_t *pszString, uint32 nPos=0, int nCount=-1) const
PLCORE_API bool CompareNoCase (const String &sString, uint32 nPos=0, int nCount=-1) const
 Compare function (case insensitive)
PLCORE_API bool CompareNoCase (const char *pszString, uint32 nPos=0, int nCount=-1) const
 Compare function (case insensitive)
PLCORE_API bool CompareNoCase (const wchar_t *pszString, uint32 nPos=0, int nCount=-1) const
bool IsAlphabetic () const
 Determines whether the string is alphabetic or not.
bool IsAlphaNumeric () const
 Determines whether the string is alpha-numeric or not.
bool IsNumeric () const
 Determines whether the string is numeric.
PLCORE_API bool IsSubstring (const String &sString) const
 Checks whether the given string is a substring of this string or not.
PLCORE_API bool IsSubstring (const char *pszString) const
 Checks whether the given string is a substring of this string or not.
PLCORE_API bool IsSubstring (const wchar_t *pszString) const
PLCORE_API int IndexOf (const String &sString, uint32 nPos=0) const
 Returns the index of the substring if contained in this string.
PLCORE_API int IndexOf (const char *pszString, uint32 nPos=0) const
 Returns the index of the substring if contained in this string.
PLCORE_API int IndexOf (const wchar_t *pszString, uint32 nPos=0) const
PLCORE_API int LastIndexOf (const String &sString, int nPos=-1) const
 Searches from backwards for the index of the substring within this string.
PLCORE_API int LastIndexOf (const char *pszString, int nPos=-1) const
 Searches from backwards for the index of the substring within this string.
PLCORE_API int LastIndexOf (const wchar_t *pszString, int nPos=-1) const
PLCORE_API String GetSubstring (uint32 nPos, int nCount=-1) const
 Get a substring from the string.
StringToLower ()
 Change all characters to lower case.
StringToUpper ()
 Change all characters to upper case.
PLCORE_API StringDelete (uint32 nPos=0, int nCount=-1)
 Delete a substring.
StringInsert (char nCharacter, uint32 nPos=0)
 Insert a character at a given location.
StringInsert (wchar_t nCharacter, uint32 nPos=0)
PLCORE_API StringInsert (const String &sString, uint32 nPos=0, int nCount=-1)
 Insert a string at a given location.
PLCORE_API StringInsert (const char *pszString, uint32 nPos=0, int nCount=-1)
 Insert a string at a given location.
PLCORE_API StringInsert (const wchar_t *pszString, uint32 nPos=0, int nCount=-1)
PLCORE_API StringCopy (const char *pszString, int nCount=-1)
 Copies a string.
PLCORE_API StringCopy (const wchar_t *pszString, int nCount=-1)
PLCORE_API uint32 Replace (char nOld, char nNew)
 Replaces all occurrences of a character by another character.
PLCORE_API uint32 Replace (wchar_t nOld, wchar_t nNew)
PLCORE_API uint32 Replace (const String &sOld, const String &sNew)
 Replaces all occurrences of a substring by another string.
PLCORE_API uint32 Replace (const char *pszOld, const char *pszNew)
 Replaces all occurrences of a substring by another string.
PLCORE_API uint32 Replace (const wchar_t *pszOld, const wchar_t *pszNew)
PLCORE_API bool SetCharacter (uint32 nIndex, char nCharacter)
 Sets a character at the given index.
PLCORE_API bool SetCharacter (uint32 nIndex, wchar_t nCharacter)
StringTrimLeading ()
 Removes all whitespace (tabs and spaces) at the beginning of the string.
StringTrimTrailing ()
 Removes all whitespace (tabs and spaces) at the end of the string.
PLCORE_API StringTrim ()
 Removes all whitespace (tabs and spaces) at the beginning and the end of the string.
StringRemoveLineEndings ()
 Removes line endings ("\r" or "\n") at the end of the string.
const char * GetUTF8 () const
 Returns the character string as UTF8.
PLCORE_API bool IsValidInteger () const
PLCORE_API bool IsValidFloat () const
PLCORE_API bool GetBool () const
PLCORE_API char GetChar () const
PLCORE_API wchar_t GetWideChar () const
PLCORE_API int GetInt () const
PLCORE_API int64 GetInt64 () const
PLCORE_API uint8 GetUInt8 () const
PLCORE_API uint16 GetUInt16 () const
PLCORE_API uint32 GetUInt32 () const
PLCORE_API uint64 GetUInt64 () const
uint_ptr GetUIntPtr () const
PLCORE_API float GetFloat () const
PLCORE_API double GetDouble () const
Stringoperator= (bool bValue)
PLCORE_API Stringoperator= (char nValue)
PLCORE_API Stringoperator= (wchar_t nValue)
PLCORE_API Stringoperator= (int nValue)
PLCORE_API Stringoperator= (int64 nValue)
PLCORE_API Stringoperator= (uint8 nValue)
PLCORE_API Stringoperator= (uint32 nValue)
PLCORE_API Stringoperator= (uint64 nValue)
PLCORE_API Stringoperator= (float fValue)
PLCORE_API Stringoperator= (double dValue)
PLCORE_API String operator+ (bool bValue) const
PLCORE_API String operator+ (char nValue) const
PLCORE_API String operator+ (wchar_t nValue) const
PLCORE_API String operator+ (int nValue) const
String operator+ (int64 nValue) const
String operator+ (uint8 nValue) const
String operator+ (uint32 nValue) const
String operator+ (uint64 nValue) const
String operator+ (float fValue) const
String operator+ (double dValue) const
PLCORE_API Stringoperator+= (bool bValue)
PLCORE_API Stringoperator+= (char nValue)
PLCORE_API Stringoperator+= (wchar_t nValue)
Stringoperator+= (int nValue)
Stringoperator+= (int64 nValue)
Stringoperator+= (uint8 nValue)
Stringoperator+= (uint32 nValue)
Stringoperator+= (uint64 nValue)
Stringoperator+= (float fValue)
Stringoperator+= (double dValue)

Static Public Member Functions

static PLCORE_API String Format (const char *pszFormat,...)
 Creates a new formatted string (like sprintf)
static PLCORE_API String Format (const wchar_t *pszFormat,...)
static PLCORE_API String FromUTF8 (const char *pszUTF8, int nLength=-1, uint32 nNumOfBytes=0)
 Sets the character string as UTF8.

Friends

PLCORE_API friend String operator+ (const char *pszString, const String &sString)
 Concatenate strings.
PLCORE_API friend String operator+ (const wchar_t *pszString, const String &sString)
PLCORE_API friend String operator+ (bool bValue, const String &sString)
PLCORE_API friend String operator+ (char nValue, const String &sString)
PLCORE_API friend String operator+ (wchar_t nValue, const String &sString)
String operator+ (int nValue, const String &sString)
String operator+ (int64 nValue, const String &sString)
String operator+ (uint8 nValue, const String &sString)
String operator+ (uint32 nValue, const String &sString)
String operator+ (uint64 nValue, const String &sString)
String operator+ (float fValue, const String &sString)
String operator+ (double dValue, const String &sString)

Detailed Description

String class.

Remarks:
Because strings are quite fundamental, there are several optimizations in place to make dealing with strings as fast as possible. The string class uses a 'copy on change' technique - therefore copying one string into another is quite performant because the internal string buffer is shared as long as a string doesn't change. As result comparing strings 'can' also be very fast and the internal string buffer can be ASCII OR Unicode in a quite flexible way. To enhance the string performance, the internal string buffers are managed by a string buffer manager to avoid to many memory allocations/deallocations. For an additional performance improvement, memory is traded for speed, meaning that additional characters are allocated within the internal string buffer manager for future use. This way, appending new characters to a string is usually quite fast.

As long as you don't save your source codes in an UTF8 format you can also use the ASCII extension Ansi, meaning characters between 128-256. But with an UTF8 format, this may cause serious problems and you should use Unicode instead ASCII for characters above 128 (using codepage based ASCII is not recommended) to avoid encoding troubles!

For best compatibility with other string techniques, this class is using pointers instead of [] references, so a null pointer is a valid parameter.

*    Usage example:
*    String sS;                        // Test string instance
*    sS = "Mini";                      // Set string to 'Mini' as ASCII
*    sS += " Me";                      // Concatenate 'Me' (ASCII) to string
*    const char *pS = sS.GetASCII();   // Get pointer to ASCII string content
*    const char *pS = sS;              // Get pointer to ASCII string content (same as above)
*    sS = L"Mini";                     // Set string to 'Mini' as Unicode
*    sS = L"\u65e5\u672c\u8a9e";       // Set string to 'nihon' (= Japanese) as Unicode
*    sS = String::FromUTF8("Mini");    // Set string to 'Mini' as UTF8
*  
Note:
  • With 'length' we mean the 'number of characters' and not the 'number of bytes'
  • Don't forget that wchar_t does not have the same number of bytes on every OS, so DO NOT use wchar_t for serialization, use UTF8 for that!
  • PixelLight is using the compiler option "wchar_t is treated as built-in type", while other libraries like Qt are not - so you may want to use UTF8 for string exchange between different libraries...
  • If you care about best possible performance (even if nearly not measurable), use character string methods when dealing with characters - for example, write "String sS = 'A';" instead of "String sS = "A";", this way, the string method already knows that you provided just a single character and don't need to count characters internally
  • Implementation of the bridge design pattern (with a pinch of the proxy design pattern for the copy-on-write/change), this class is the abstraction

Member Enumeration Documentation

Internal string format.

Enumerator:
ASCII 

ASCII, 1 byte per character (American Standard Code for Information Interchange, 0-128 defined, above undefined)

Unicode 

Unicode, (sometimes called 'multi-byte' or 'wide character') normally two bytes (UTF-16) on Microsoft Windows per character, four bytes long on UNIX systems (UTF-32)

UTF8 

UTF8, only used internally


Constructor & Destructor Documentation

PLCore::String::String ( ) [inline]

Default constructor.

PLCORE_API PLCore::String::String ( char  nValue)

Character constructor.

Parameters:
[in]nValueSingle character to put into the string
PLCORE_API PLCore::String::String ( wchar_t  nValue)
PLCORE_API PLCore::String::String ( const char *  pszString,
bool  bCopy = true,
int  nLength = -1 
)

Constructor.

Parameters:
[in]pszStringString to save, can be a null pointer
[in]bCopyCopy the given string or use this one directly? Do ONLY set bCopy to 'false' if you are sure there can't go anything wrong - the string class will take over control of the string buffer and also destroy it
[in]nLengthLength of the given string, (excluding the terminating zero) if negative, the length is calculated automatically
PLCORE_API PLCore::String::String ( const wchar_t *  pszString,
bool  bCopy = true,
int  nLength = -1 
)
PLCORE_API PLCore::String::String ( const String sString)

Copy constructor.

Parameters:
[in]sStringString
PLCore::String::String ( bool  bValue) [inline]

Number constructor.

Parameters:
[in]nValueNumber to put into the string
PLCORE_API PLCore::String::String ( int  nValue)
PLCore::String::String ( int64  nValue) [inline]
PLCore::String::String ( uint8  nValue) [inline]
PLCore::String::String ( uint32  nValue) [inline]
PLCore::String::String ( uint64  nValue) [inline]
PLCore::String::String ( float  fValue) [inline]
PLCore::String::String ( double  fValue) [inline]
PLCore::String::String ( void *  pValue) [inline]

Pointer constructor.

Parameters:
[in]pValuePointer to put into the string
PLCore::String::String ( StringBuffer pStringBuffer)

Internal copy constructor.

Parameters:
[in]pStringBufferString buffer to use, can be a null pointer
Note:
  • This constructor is ONLY used inside PLCore and therefore it's not exported and usable from 'outside'

Destructor.


Member Function Documentation

static PLCORE_API String PLCore::String::Format ( const char *  pszFormat,
  ... 
) [static]

Creates a new formatted string (like sprintf)

Parameters:
[in]pszFormatThe format string ... -> The variable arguments (can be a null pointer)
Returns:
New string
Remarks:
If possible, try to avoid to use this method because it's usually considered to be "slow" due to it's internal complexity. Therefore, write something like String sMyString = String("The number ") + 42 + " is fantastic!"; instead of String sMyString = String::Format("The number %d is fantastic!", 42);
static PLCORE_API String PLCore::String::Format ( const wchar_t *  pszFormat,
  ... 
) [static]
static PLCORE_API String PLCore::String::FromUTF8 ( const char *  pszUTF8,
int  nLength = -1,
uint32  nNumOfBytes = 0 
) [static]

Sets the character string as UTF8.

Parameters:
[in]pszUTF8Pointer to the character string as UTF8, can be a null pointer
[in]nLengthLength of the given string, (excluding the terminating zero) if negative, the length is calculated automatically
[in]nNumOfBytesNumber of bytes of the string buffer (excluding the terminating zero, MUST be valid if not 0!)
Returns:
New UTF8 string
uint32 PLCore::String::GetLength ( ) const [inline]

Returns the length of the string.

Returns:
Length of the string (excluding the terminating zero)

Returns the internal string format.

Returns:
Internal string format
PLCORE_API uint32 PLCore::String::GetNumOfBytes ( EFormat  nFormat) const

Returns the number of bytes the string is using in a specified format (ASCII, Unicode, UTF8)

Parameters:
[in]nFormatThe internal string format
Returns:
The number of bytes the string is using in the specified format (excluding the terminating zero)
char PLCore::String::operator[] ( uint32  nIndex) const [inline]

Get a ASCII character of the string.

Parameters:
[in]nIndexPosition of the ASCII character to retrieve
Returns:
ASCII character at the given position within the string, terminating zero (\0) on error
const char * PLCore::String::GetASCII ( ) const [inline]

Returns the character string as ASCII.

Returns:
Pointer to the character string as ASCII, never a null pointer
Remarks:
If the internal format of this string doesn't match the requested format, an internal temp string of the requested format is created and backuped until this original string is manipulated. Then, the internal backup get's dirty/invalid - so, do NEVER backup the returned pointer by self!
Note:
  • Do NOT manipulate or even mess up the memory by writing outside the given buffer!
PLCore::String::operator const char * ( ) const [inline]

Returns the character string as ASCII.

Returns the ASCII character string.

Returns:
Pointer to the character string as ASCII, never a null pointer
See also:
const wchar_t * PLCore::String::GetUnicode ( ) const [inline]

Returns the character string as Unicode.

Returns:
Pointer to the character string as Unicode, never a null pointer
See also:
PLCore::String::operator const wchar_t * ( ) const [inline]

Returns the character string as Unicode.

Returns the Unicode character string.

Returns:
Pointer to the character string as Unicode, never a null pointer
See also:
String & PLCore::String::operator= ( const String sString) [inline]

Copy operator.

Parameters:
[in]sStringString to copy
Returns:
Reference to this string
PLCORE_API String& PLCore::String::operator= ( const char *  pszString)

Copy operator.

Parameters:
[in]pszStringString to copy, can be a null pointer
Returns:
Reference to this string
PLCORE_API String& PLCore::String::operator= ( const wchar_t *  pszString)
PLCORE_API String PLCore::String::operator+ ( const String sString) const

Concatenate strings.

Parameters:
[in]sStringString to add
Returns:
Reference to the new string
PLCORE_API String PLCore::String::operator+ ( const char *  pszString) const

Concatenate strings.

Parameters:
[in]pszStringString to add, can be a null pointer
Returns:
Reference to the new string
PLCORE_API String PLCore::String::operator+ ( const wchar_t *  pszString) const
PLCORE_API String& PLCore::String::operator+= ( const String sString)

Concatenate strings.

Parameters:
[in]sStringString to add
Returns:
Reference to this string
PLCORE_API String& PLCore::String::operator+= ( const char *  pszString)

Concatenate strings.

Parameters:
[in]pszStringString to add, can be a null pointer
Returns:
Reference to this string
PLCORE_API String& PLCore::String::operator+= ( const wchar_t *  pszString)
PLCORE_API bool PLCore::String::operator< ( const String sString) const

Compares this string and the given one lexicographically.

Parameters:
[in]sStringString to compare with
Returns:
'true' if this string is less than the given one
PLCORE_API bool PLCore::String::operator< ( const char *  pszString) const

Compares this string and the given one lexicographically.

Parameters:
[in]pszStringString to compare with, can be a null pointer
Returns:
'true' if this string is less than the given one
PLCORE_API bool PLCore::String::operator< ( const wchar_t *  pszString) const
PLCORE_API bool PLCore::String::operator> ( const String sString) const

Compares this string and the given one lexicographically.

Parameters:
[in]sStringString to compare with
Returns:
'true' if this string is greater than the given one
PLCORE_API bool PLCore::String::operator> ( const char *  pszString) const

Compares this string and the given one lexicographically.

Parameters:
[in]pszStringString to compare with, can be a null pointer
Returns:
'true' if this string is greater than the given one
PLCORE_API bool PLCore::String::operator> ( const wchar_t *  pszString) const
bool PLCore::String::operator== ( const String sString) const [inline]

Compare operator (case sensitive)

Parameters:
[in]sStringString to compare with
Returns:
'true' if the two strings are identical, else 'false'
bool PLCore::String::operator== ( const char *  pszString) const [inline]

Compare operator (case sensitive)

Parameters:
[in]pszStringString to compare with, can be a null pointer
Returns:
'true' if the two strings are identical, else 'false'
bool PLCore::String::operator== ( const wchar_t *  pszString) const [inline]
bool PLCore::String::operator!= ( const String sString) const [inline]

Compare operator (case sensitive)

Parameters:
[in]sStringString to compare with
Returns:
'true' if the two strings are different, else 'false'
bool PLCore::String::operator!= ( const char *  pszString) const [inline]

Compare operator (case sensitive)

Parameters:
[in]pszStringString to compare with, can be a null pointer
Returns:
'true' if the two strings are different, else 'false'
bool PLCore::String::operator!= ( const wchar_t *  pszString) const [inline]
PLCORE_API bool PLCore::String::Compare ( const String sString,
uint32  nPos = 0,
int  nCount = -1 
) const

Compare function (case sensitive)

Parameters:
[in]sStringString to compare with
[in]nPosStart position within this string
[in]nCountNumber of characters to compare, if negative compare all characters, if 0 the result is "true"
Returns:
'true' if the two strings are identical, else 'false'
PLCORE_API bool PLCore::String::Compare ( const char *  pszString,
uint32  nPos = 0,
int  nCount = -1 
) const

Compare function (case sensitive)

Parameters:
[in]pszStringString to compare with, can be a null pointer
[in]nPosStart position within this string
[in]nCountNumber of characters to compare, if negative compare all characters, if 0 the result is "true"
Returns:
'true' if the two strings are identical, else 'false'
PLCORE_API bool PLCore::String::Compare ( const wchar_t *  pszString,
uint32  nPos = 0,
int  nCount = -1 
) const
PLCORE_API bool PLCore::String::CompareNoCase ( const String sString,
uint32  nPos = 0,
int  nCount = -1 
) const

Compare function (case insensitive)

Parameters:
[in]sStringString to compare with
[in]nPosStart position within this string
[in]nCountNumber of characters to compare, if negative compare all characters, if 0 the result is "true"
Returns:
'true' if the two strings are identical, else 'false'
PLCORE_API bool PLCore::String::CompareNoCase ( const char *  pszString,
uint32  nPos = 0,
int  nCount = -1 
) const

Compare function (case insensitive)

Parameters:
[in]pszStringString to compare with, can be a null pointer
[in]nPosStart position within this string
[in]nCountNumber of characters to compare, if negative compare all characters, if 0 the result is "true"
Returns:
'true' if the two strings are identical, else 'false'
PLCORE_API bool PLCore::String::CompareNoCase ( const wchar_t *  pszString,
uint32  nPos = 0,
int  nCount = -1 
) const
bool PLCore::String::IsAlphabetic ( ) const [inline]

Determines whether the string is alphabetic or not.

Returns:
'true' if the string is alphabetic, else 'false' (maybe the string is empty?)
Note:
  • Examples: 'abc' is alphabetic while 'abc12' or 'ab-c' are not
bool PLCore::String::IsAlphaNumeric ( ) const [inline]

Determines whether the string is alpha-numeric or not.

Returns:
'true' if the string is alpha-numeric, else 'false' (maybe the string is empty?)
Note:
  • Examples: 'abc', '12' or 'abc12' are alpha-numeric while 'abc-12' is not
bool PLCore::String::IsNumeric ( ) const [inline]

Determines whether the string is numeric.

Determines whether the string is numeric or not.

Returns:
'true' if the string is numeric, else 'false' (maybe the string is empty?)
Note:
  • Examples: '5' or '0' are numeric, while '5.1', '.', 'AD', '3D', '5,5', '5.2.8' are not
PLCORE_API bool PLCore::String::IsSubstring ( const String sString) const

Checks whether the given string is a substring of this string or not.

Parameters:
[in]sStringString to check, if empty string, 'true' will be returned
Returns:
'true', if the given string is a substring of this string, (or both are empty) else 'false'
PLCORE_API bool PLCore::String::IsSubstring ( const char *  pszString) const

Checks whether the given string is a substring of this string or not.

Parameters:
[in]pszStringString to check, if a null pointer or empty, 'true' will be returned
Returns:
'true', if the given string is a substring of this string, (or both are empty) else 'false' else 'false'
PLCORE_API bool PLCore::String::IsSubstring ( const wchar_t *  pszString) const
PLCORE_API int PLCore::String::IndexOf ( const String sString,
uint32  nPos = 0 
) const

Returns the index of the substring if contained in this string.

Parameters:
[in]sStringString to check, if empty string, < 0 will be returned
[in]nPosStart position within this string
Returns:
Index of the substring if found within this string, < 0 on error (maybe the given position is invalid) or if both strings are empty
PLCORE_API int PLCore::String::IndexOf ( const char *  pszString,
uint32  nPos = 0 
) const

Returns the index of the substring if contained in this string.

Parameters:
[in]pszStringString to check, if a null pointer or empty, < 0 will be returned
[in]nPosStart position within this string
Returns:
Index of the substring if found within this string, < 0 on error (maybe the given position is invalid) or if both strings are empty
PLCORE_API int PLCore::String::IndexOf ( const wchar_t *  pszString,
uint32  nPos = 0 
) const
PLCORE_API int PLCore::String::LastIndexOf ( const String sString,
int  nPos = -1 
) const

Searches from backwards for the index of the substring within this string.

Parameters:
[in]sStringString to check, if empty string, < 0 will be returned
[in]nPosStart position within this string, if < 0 start at the last character
Returns:
Index of the substring if found within this string, < 0 on error (maybe the given position is invalid) or if both strings are empty
PLCORE_API int PLCore::String::LastIndexOf ( const char *  pszString,
int  nPos = -1 
) const

Searches from backwards for the index of the substring within this string.

Parameters:
[in]pszStringString to check, if a null pointer or empty, < 0 will be returned
[in]nPosStart position within this string, if < 0 start at the last character
Returns:
Index of the substring if found within this string, < 0 on error (maybe the given position is invalid) or if both strings are empty
PLCORE_API int PLCore::String::LastIndexOf ( const wchar_t *  pszString,
int  nPos = -1 
) const
PLCORE_API String PLCore::String::GetSubstring ( uint32  nPos,
int  nCount = -1 
) const

Get a substring from the string.

Parameters:
[in]nPosStart position
[in]nCountNumber of characters to copy, negative for everything from nPos to the end of the string
Returns:
The substring

Change all characters to lower case.

Returns:
Reference to this string

Change all characters to upper case.

Returns:
Reference to this string
PLCORE_API String& PLCore::String::Delete ( uint32  nPos = 0,
int  nCount = -1 
)

Delete a substring.

Parameters:
[in]nPosStart position of deletion
[in]nCountNumber of characters to delete, if negative delete all characters
Returns:
Reference to this string
String & PLCore::String::Insert ( char  nCharacter,
uint32  nPos = 0 
) [inline]

Insert a character at a given location.

Parameters:
[in]nCharacterCharacter to insert
[in]nPosPosition at which to insert the character
Returns:
Reference to this string
Note:
  • In case you just want to append a character, you may want to use the faster "+="-operator instead
String & PLCore::String::Insert ( wchar_t  nCharacter,
uint32  nPos = 0 
) [inline]
PLCORE_API String& PLCore::String::Insert ( const String sString,
uint32  nPos = 0,
int  nCount = -1 
)

Insert a string at a given location.

Parameters:
[in]sStringString to insert
[in]nPosPosition at which to insert the string
[in]nCountNumber of characters to add, if negative insert the whole string
Returns:
Reference to this string
Note:
  • In case you just want to append a string, you may want to use the faster "+="-operator instead
PLCORE_API String& PLCore::String::Insert ( const char *  pszString,
uint32  nPos = 0,
int  nCount = -1 
)

Insert a string at a given location.

Parameters:
[in]pszStringString to insert, can be a null pointer
[in]nPosPosition at which to insert the string
[in]nCountNumber of characters to add, if negative insert the whole string
Returns:
Reference to this string
Note:
  • In case you just want to append a string, you may want to use the faster "+="-operator instead
PLCORE_API String& PLCore::String::Insert ( const wchar_t *  pszString,
uint32  nPos = 0,
int  nCount = -1 
)
PLCORE_API String& PLCore::String::Copy ( const char *  pszString,
int  nCount = -1 
)

Copies a string.

Parameters:
[in]pszStringString to copy, can be a null pointer
[in]nCountNumber of characters to copy, if negative copy the whole string
Returns:
Reference to this string
PLCORE_API String& PLCore::String::Copy ( const wchar_t *  pszString,
int  nCount = -1 
)
PLCORE_API uint32 PLCore::String::Replace ( char  nOld,
char  nNew 
)

Replaces all occurrences of a character by another character.

Parameters:
[in]nOldCharacter to be replaced
[in]nNewCharacter to replace with
Returns:
Number of replaced characters (0 if new = old)
PLCORE_API uint32 PLCore::String::Replace ( wchar_t  nOld,
wchar_t  nNew 
)
PLCORE_API uint32 PLCore::String::Replace ( const String sOld,
const String sNew 
)

Replaces all occurrences of a substring by another string.

Parameters:
[in]sOldSubstring to be replaced
[in]sNewString to replace with
Returns:
Number of replaced substrings (0 if sNew = sOld or sOld is empty)
PLCORE_API uint32 PLCore::String::Replace ( const char *  pszOld,
const char *  pszNew 
)

Replaces all occurrences of a substring by another string.

Parameters:
[in]pszOldSubstring to be replaced, can be a null pointer
[in]pszNewString to replace with, can be a null pointer
Returns:
Number of replaced substrings (0 if pszNew = pszOld or pszOld is a null pointer or empty)
PLCORE_API uint32 PLCore::String::Replace ( const wchar_t *  pszOld,
const wchar_t *  pszNew 
)
PLCORE_API bool PLCore::String::SetCharacter ( uint32  nIndex,
char  nCharacter 
)

Sets a character at the given index.

Parameters:
[in]nIndexCharacter index
[in]nCharacterCharacter to set at the given index
Returns:
'true' if all went fine, else 'false'
PLCORE_API bool PLCore::String::SetCharacter ( uint32  nIndex,
wchar_t  nCharacter 
)

Removes all whitespace (tabs and spaces) at the beginning of the string.

Returns:
Reference to this string

Removes all whitespace (tabs and spaces) at the end of the string.

Returns:
Reference to this string
PLCORE_API String& PLCore::String::Trim ( )

Removes all whitespace (tabs and spaces) at the beginning and the end of the string.

Returns:
Reference to this string

Removes line endings ("\r" or "\n") at the end of the string.

Returns:
Reference to this string
Note:
  • Carriage return = CR = '' = 0x0D = 13 in decimal
  • Line feed = LF = '
    ' = 0x0A = 10 in decimal
const char * PLCore::String::GetUTF8 ( ) const [inline]

Returns the character string as UTF8.

Returns:
Pointer to the character string as UTF8, never a null pointer - do NOT destroy the returned memory, it's owned by this string instance!
See also:
PLCORE_API bool PLCore::String::IsValidInteger ( ) const
PLCORE_API bool PLCore::String::IsValidFloat ( ) const
PLCORE_API bool PLCore::String::GetBool ( ) const
PLCORE_API char PLCore::String::GetChar ( ) const
PLCORE_API wchar_t PLCore::String::GetWideChar ( ) const
PLCORE_API int PLCore::String::GetInt ( ) const
PLCORE_API int64 PLCore::String::GetInt64 ( ) const
PLCORE_API uint8 PLCore::String::GetUInt8 ( ) const
PLCORE_API uint16 PLCore::String::GetUInt16 ( ) const
PLCORE_API uint32 PLCore::String::GetUInt32 ( ) const
PLCORE_API uint64 PLCore::String::GetUInt64 ( ) const
uint_ptr PLCore::String::GetUIntPtr ( ) const [inline]
PLCORE_API float PLCore::String::GetFloat ( ) const
PLCORE_API double PLCore::String::GetDouble ( ) const
String & PLCore::String::operator= ( bool  bValue) [inline]
PLCORE_API String& PLCore::String::operator= ( char  nValue)
PLCORE_API String& PLCore::String::operator= ( wchar_t  nValue)
PLCORE_API String& PLCore::String::operator= ( int  nValue)
String & PLCore::String::operator= ( int64  nValue) [inline]
String & PLCore::String::operator= ( uint8  nValue) [inline]
String & PLCore::String::operator= ( uint32  nValue) [inline]
String & PLCore::String::operator= ( uint64  nValue) [inline]
String & PLCore::String::operator= ( float  fValue) [inline]
String & PLCore::String::operator= ( double  dValue) [inline]
PLCORE_API String PLCore::String::operator+ ( bool  bValue) const
PLCORE_API String PLCore::String::operator+ ( char  nValue) const
PLCORE_API String PLCore::String::operator+ ( wchar_t  nValue) const
String PLCore::String::operator+ ( int  nValue) const [inline]
String PLCore::String::operator+ ( int64  nValue) const [inline]
String PLCore::String::operator+ ( uint8  nValue) const [inline]
String PLCore::String::operator+ ( uint32  nValue) const [inline]
String PLCore::String::operator+ ( uint64  nValue) const [inline]
String PLCore::String::operator+ ( float  fValue) const [inline]
String PLCore::String::operator+ ( double  dValue) const [inline]
PLCORE_API String& PLCore::String::operator+= ( bool  bValue)
PLCORE_API String& PLCore::String::operator+= ( char  nValue)
PLCORE_API String& PLCore::String::operator+= ( wchar_t  nValue)
String & PLCore::String::operator+= ( int  nValue) [inline]
String & PLCore::String::operator+= ( int64  nValue) [inline]
String & PLCore::String::operator+= ( uint8  nValue) [inline]
String & PLCore::String::operator+= ( uint32  nValue) [inline]
String & PLCore::String::operator+= ( uint64  nValue) [inline]
String & PLCore::String::operator+= ( float  fValue) [inline]
String & PLCore::String::operator+= ( double  dValue) [inline]

Friends And Related Function Documentation

PLCORE_API friend String operator+ ( const char *  pszString,
const String sString 
) [friend]

Concatenate strings.

Parameters:
[in]pszStringString to add, can be a null pointer
[in]sStringString to add
Returns:
Reference to the new string
PLCORE_API friend String operator+ ( const wchar_t *  pszString,
const String sString 
) [friend]
PLCORE_API friend String operator+ ( bool  bValue,
const String sString 
) [friend]
PLCORE_API friend String operator+ ( char  nValue,
const String sString 
) [friend]
PLCORE_API friend String operator+ ( wchar_t  nValue,
const String sString 
) [friend]
String operator+ ( int  nValue,
const String sString 
) [friend]
String operator+ ( int64  nValue,
const String sString 
) [friend]
String operator+ ( uint8  nValue,
const String sString 
) [friend]
String operator+ ( uint32  nValue,
const String sString 
) [friend]
String operator+ ( uint64  nValue,
const String sString 
) [friend]
String operator+ ( float  fValue,
const String sString 
) [friend]
String operator+ ( double  dValue,
const String sString 
) [friend]

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


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:27
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported