Polycode
Polycode::String Class Reference

Unicode-friendly string. More...

List of all members.

Public Member Functions

 String ()
 Default constructor.
 String (const wchar_t *str)
 Initializes the string from a pointer to wide character buffer.
 String (const char *str, size_t n)
 Initializes the string from a pointer to regular character buffer of a certain size.
 String (const char *str)
 Initializes the string from a regular character buffer.
 String (const std::string &str)
 Initializes the string from an STL string.
 String (const std::wstring &str)
 Initializes the string from an STL wstring.
size_t size () const
 Return the length of the string.
size_t length () const
 Return the length of the string.
const std::string & getSTLString () const
 Return the string and an STL string.
String substr (size_t pos=0, size_t n=std::wstring::npos) const
 Returns the substring of the string.
size_t rfind (const String &str, size_t pos=std::wstring::npos) const
 Find last occurrence of content in string.
size_t find (const String &str, size_t pos=0) const
 Find content in string.
size_t find_last_of (const String &str, size_t pos=std::wstring::npos)
 Find character in string from the end.
String toLowerCase () const
 Returns the lowercase version of the string.
String toUpperCase () const
 Returns the uppercase version of the string.
std::vector< Stringsplit (const String &delim) const
 Splits the string by the specified delimeter.
String replace (const String &what, const String &withWhat) const
 Replaces parts of the string with another string.
const char * c_str () const
 Pointer to char data.
const char * getDataWithEncoding (int encoding) const
 Returns data with the specified encoding.
size_t getDataSizeWithEncoding (int encoding) const
 Returns the size of the data with the specified encoding.
void setDataWithEncoding (char *data, int encoding)
 Sets the data for the string using specified encoding.

Static Public Member Functions

static String NumberToString (Number value)
 Convert a Number to a String.
static String IntToString (int value)
 Convert an integer to a String.

Public Attributes

std::string contents
 STL string version of the string.

Static Public Attributes

static const int ENCODING_UTF8 = 0
 UTF-8 encoding.

Detailed Description

Unicode-friendly string.

The Polycode String class wraps around STL wstring to support Unicode text in the engine. You can request data from it in different encodings (currently only UTF-8) or plain char data. It is mostly just a wrapper around STL created for easier Unicode support, LUA bindings and convenience methods.


Member Function Documentation

const char * String::c_str ( ) const

Pointer to char data.

Returns:
A pointer to char data.
size_t Polycode::String::find ( const String str,
size_t  pos = 0 
) const [inline]

Find content in string.

Parameters:
strString to be searched for in the object.
posPosition of the first character in the string to be taken into consideration for possible matches. The default value indicates that the entire string is searched.
Returns:
The position of the first occurrence in the string of the searched content
size_t Polycode::String::find_last_of ( const String str,
size_t  pos = std::wstring::npos 
) [inline]

Find character in string from the end.

Searches the string from the end for any of the characters that are part of the passed string.

Parameters:
strString containing the characters to search for.
posPosition of the last character in the string to be taken into consideration for possible matches. The default value indicates that the entire string is searched.
Returns:
The position of the last occurrence in the string of any of the characters searched for.
size_t String::getDataSizeWithEncoding ( int  encoding) const

Returns the size of the data with the specified encoding.

Currently the only supported encoding is String::ENCODING_UTF8

Parameters:
encodingThe encoding to use.
Returns:
The size the data would take up if returned with this encoding.
See also:
getDataWithEncoding()
const char * String::getDataWithEncoding ( int  encoding) const

Returns data with the specified encoding.

Currently the only supported encoding is String::ENCODING_UTF8

Parameters:
encodingThe encoding to use.
Returns:
A pointer to the data using specified encoding.
See also:
getDataSizeWithEncoding()
String String::IntToString ( int  value) [static]

Convert an integer to a String.

Parameters:
valueInteger to convert.
Returns:
A string converted from the integer.
String String::NumberToString ( Number  value) [static]

Convert a Number to a String.

Parameters:
valueNumber to convert.
Returns:
A string converted from the Number.
String String::replace ( const String what,
const String withWhat 
) const

Replaces parts of the string with another string.

Parameters:
whatOcurrences of which string to replace in this string.
withWhatWhat to replace them with.
Returns:
A new string with the specified matches replaced with the specified string.
size_t Polycode::String::rfind ( const String str,
size_t  pos = std::wstring::npos 
) const [inline]

Find last occurrence of content in string.

Parameters:
strString to be searched for in the object.
posPosition of the last character in the string to be taken into consideration for possible matches. The default value indicates that the entire string is searched.
Returns:
The position of the last occurrence in the string of the searched content
void String::setDataWithEncoding ( char *  data,
int  encoding 
)

Sets the data for the string using specified encoding.

Parameters:
dataData to set the string with.
encodingThe encoding to use.
vector< String > String::split ( const String delim) const

Splits the string by the specified delimeter.

Parameters:
delimThe delimeter to split by.
Returns:
An STL vector of the split parts of the string.
String Polycode::String::substr ( size_t  pos = 0,
size_t  n = std::wstring::npos 
) const [inline]

Returns the substring of the string.

Parameters:
posPosition of a character in the current string object to be used as starting character for the substring.
nLength of the substring.
Returns:
A string object containing a substring of the current object.
String String::toLowerCase ( ) const

Returns the lowercase version of the string.

Returns:
Lowercase version of the stirng.
String String::toUpperCase ( ) const

Returns the uppercase version of the string.

Returns:
Uppercase version of the stirng.