WoopsiGfx 1.4
Nintendo DS 2D Graphics Library
|
#include <libwoopsigfx/include/woopsistring.h>
Public Member Functions | |
WoopsiString () | |
WoopsiString (const char *text) | |
WoopsiString (const u32 letter) | |
WoopsiString (const WoopsiString &string) | |
WoopsiString (const WoopsiString &string, const s32 startIndex) | |
WoopsiString (const WoopsiString &string, const s32 startIndex, const s32 length) | |
virtual | ~WoopsiString () |
StringIterator * | newStringIterator () const |
virtual void | copyToCharArray (char *buffer) const |
virtual void | setText (const WoopsiString &text, const s32 startIndex, const s32 length) |
virtual void | setText (const WoopsiString &text) |
virtual void | setText (const char *text) |
virtual void | setText (const u32 text) |
virtual void | append (const WoopsiString &text) |
virtual void | insert (const WoopsiString &text, const s32 index) |
virtual void | remove (const s32 startIndex) |
virtual void | remove (const s32 startIndex, const s32 count) |
virtual const s32 | getLength () const |
virtual const s32 | getByteCount () const |
virtual const u32 | getCharAt (s32 index) const |
const s32 | indexOf (u32 letter) const |
const s32 | indexOf (u32 letter, s32 startIndex) const |
virtual const s32 | indexOf (u32 letter, s32 startIndex, s32 count) const |
const s32 | lastIndexOf (u32 letter) const |
const s32 | lastIndexOf (u32 letter, s32 startIndex) const |
virtual const s32 | lastIndexOf (u32 letter, s32 startIndex, s32 count) const |
WoopsiString | subString (s32 startIndex) const |
WoopsiString | subString (s32 startIndex, s32 length) const |
WoopsiString & | operator= (const WoopsiString &string) |
WoopsiString & | operator= (const char *string) |
WoopsiString & | operator= (u32 letter) |
WoopsiString | operator+ (const WoopsiString &string) |
WoopsiString & | operator+= (const WoopsiString &string) |
bool | operator== (const WoopsiString &string) |
bool | operator!= (const WoopsiString &string) |
virtual s8 | compareTo (const WoopsiString &string, bool caseSensitive=false) const |
s32 | indexOf (const char *text) const |
s32 | indexOf (const char *text, s32 startIndex) const |
s32 | indexOf (const WoopsiString &text, s32 startIndex, s32 count) const |
s32 | lastIndexOf (const char *text) const |
s32 | lastIndexOf (const char *text, s32 startIndex) const |
s32 | lastIndexOf (const WoopsiString &text, s32 startIndex, s32 count) const |
void | format (const char *format,...) |
void | format (const char *format, va_list args) |
void | replace (const WoopsiString &oldText, const WoopsiString &newText) |
void | replace (const WoopsiString &oldText, const WoopsiString &newText, const s32 startIndex) |
void | replace (const s32 startIndex, const s32 count, const WoopsiString &newText) |
void | replace (const WoopsiString &oldText, const WoopsiString &newText, const s32 startIndex, const s32 replaceCount) |
void | split (const WoopsiString &separator, WoopsiArray< WoopsiString > &result) const |
void | split (const WoopsiString &separator, bool allowEmptyEntries, WoopsiArray< WoopsiString > &result) const |
Protected Member Functions | |
virtual void | init () |
virtual void | allocateMemory (s32 chars, bool preserve) |
virtual bool | hasData () const |
virtual s32 | getAllocatedSize () const |
s32 | filterString (char *dest, const char *src, s32 sourceBytes, s32 *totalUnicodeChars) const |
virtual const char * | getCharArray () const |
virtual char * | getToken (const s32 index) const |
u32 | getCodePoint (const char *string, u8 *numChars=NULL) const |
Protected Attributes | |
char * | _text |
Friends | |
class | StringIterator |
Unicode mutable string class. Uses UTF-8 encoding. For optimal performance, use the StringIterator class to iterate over a WoopsiString instance.
Where possible, the string avoids allocating memory each time the string grows or shrinks. This means that the string may consume more memory than the number of chars would seem to dictate if the object previously contained a large string that has subsequently been truncated. It also means that increasing the length of such a string is a cheaper operation as memory does not need to allocated and copied.
Additionally, the string increases its array size by _growAmount every time it needs to allocate extra memory, potentially reducing the number of reallocs needed.
The string is not null-terminated. Instead, it uses a _stringLength member that stores the number of characters in the string. This saves a byte and makes calls to getLength() run in O(1) time instead of O(n).
WoopsiString::WoopsiString | ( | ) |
Constructor to create a blank string.
WoopsiString::WoopsiString | ( | const char * | text | ) |
Constructor to create a string from a char array.
text | Pointer to a char array to use as the basis of the string. |
WoopsiString::WoopsiString | ( | const u32 | letter | ) |
Constructor to create a string from a single character.
letter | Single character to use as the basis of the string. |
WoopsiString::WoopsiString | ( | const WoopsiString & | string | ) |
Copy constructor.
string | WoopsiString object to create a copy of. |
WoopsiString::WoopsiString | ( | const WoopsiString & | string, |
const s32 | startIndex | ||
) |
Constructor that creates a copy of the supplied string from startIndex onwards (ie. it creates a substring).
string | WoopsiString object to create a copy of. |
startIndex | The index to copy from. |
WoopsiString::WoopsiString | ( | const WoopsiString & | string, |
const s32 | startIndex, | ||
const s32 | length | ||
) |
Constructor that creates a copy of the supplied string from startIndex until startIndex + count (ie. it creates a substring).
string | WoopsiString object to create a copy of. |
startIndex | The index to copy from. |
length | The number of characters to copy. |
virtual WoopsiGfx::WoopsiString::~WoopsiString | ( | ) | [inline, virtual] |
Destructor.
void WoopsiString::allocateMemory | ( | s32 | chars, |
bool | preserve | ||
) | [protected, virtual] |
Allocate memory for the string.
chars | Number of chars to allocate. |
preserve | If true, the data in the existing memory will be preserved if new memory must be allocated |
void WoopsiString::append | ( | const WoopsiString & | text | ) | [virtual] |
Append text to the end of the string.
text | String to append. |
s8 WoopsiString::compareTo | ( | const WoopsiString & | string, |
bool | caseSensitive = false |
||
) | const [virtual] |
Compares this string to the argument.
string | String to compare to. |
caseSensitive | Performs a case-sensitive compare if this is set to true. |
void WoopsiString::copyToCharArray | ( | char * | buffer | ) | const [virtual] |
Copy the internal array to the supplied buffer. The buffer must be large enough to contain the full text in the string. The getByteCount() method can be used to obtain the length of the string. Unlike the WoopsiString class, the char array is null-terminated. The buffer must be (getByteCount() + 1) bytes long, in order to accommodate the terminator.
buffer | Buffer to copy the internal char array to. |
s32 WoopsiString::filterString | ( | char * | dest, |
const char * | src, | ||
s32 | sourceBytes, | ||
s32 * | totalUnicodeChars | ||
) | const [protected] |
Copies the valid utf-8 tokens of the string src into string dest and returns the number of bytes in the filtered string.
dest | Destination string. |
src | Source string. |
sourceBytes | Number of bytes in the source string. |
totalUnicodeChars | Output parameter populated with the total number of unicode characters in the filtered string. |
void WoopsiString::format | ( | const char * | format, |
va_list | args | ||
) |
Formats the supplied char array using standard printf() syntax. The formatted text replaces the contents of the current string object. Note that va_start() must be called before this method is used, and va_end() must be called when it finishes.
Note that the compiler message regarding va_list mangling changes in GCC 4.4 are not problems with Woopsi's code. They are the result of the GCC team bizarrely deciding to include news items in compiler messages: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42748
format | The format to use. |
args | The formatting arguments. |
void WoopsiString::format | ( | const char * | format, |
... | |||
) |
Formats the supplied char array using standard printf() syntax. The formatted text replaces the contents of the current string object.
format | The format to use. |
... | The formatting arguments. |
virtual s32 WoopsiGfx::WoopsiString::getAllocatedSize | ( | ) | const [inline, protected, virtual] |
Get the amount of allocated memory.
virtual const s32 WoopsiGfx::WoopsiString::getByteCount | ( | ) | const [inline, virtual] |
Get the of number of bytes in the string.
virtual const char* WoopsiGfx::WoopsiString::getCharArray | ( | ) | const [inline, protected, virtual] |
Returns a pointer to the raw char array data.
const u32 WoopsiString::getCharAt | ( | s32 | index | ) | const [virtual] |
Get the character at the specified index. This function is useful for finding the occasional character at an index, but for iterating over strings it is exceptionally slow. The newStringIterator() method should be used to retrieve an iterator object that can iterate over the string efficiently.
index | The index of the character to retrieve. |
u32 WoopsiString::getCodePoint | ( | const char * | string, |
u8 * | numChars = NULL |
||
) | const [protected] |
Get the number of chars read in the UTF-8 token and its codepoint. In the case of an invalid codepoint, the value returned will be 0.
string | String to analyse. |
numChars | Pointer to a u8 that will hold the number of chars in the codepoint once the method ends. |
virtual const s32 WoopsiGfx::WoopsiString::getLength | ( | ) | const [inline, virtual] |
Get the of number of UTF-8 tokens (ie. the length) of the string.
char * WoopsiString::getToken | ( | const s32 | index | ) | const [protected, virtual] |
Return a pointer to the specified UTF-8 token.
index | Index of the UTF-8 token to retrieve. |
virtual bool WoopsiGfx::WoopsiString::hasData | ( | ) | const [inline, protected, virtual] |
Check if we've got any string data stored or not.
s32 WoopsiString::indexOf | ( | const WoopsiString & | text, |
s32 | startIndex, | ||
s32 | count | ||
) | const |
Gets the character index of the first occurence of the supplied string within the bounds of the current string between startIndex and startIndex + count. If the string is not found, the method will return -1.
text | The char array to find. |
startIndex | The index to start searching from. |
count | The number of characters to examine. |
const s32 WoopsiString::indexOf | ( | u32 | letter, |
s32 | startIndex, | ||
s32 | count | ||
) | const [virtual] |
Returns the first index of the specified letter within the string. Will return -1 if the letter is not found. Scans through the string from "startIndex" until it has examined all letters within the range "count".
letter | Letter to find. |
startIndex | The index to start searching from. |
count | The number of characters to examine. |
const s32 WoopsiString::indexOf | ( | u32 | letter | ) | const |
Returns the first index of the specified letter within the string. Will return -1 if the letter is not found.
letter | Letter to find. |
const s32 WoopsiString::indexOf | ( | u32 | letter, |
s32 | startIndex | ||
) | const |
Returns the first index of the specified letter within the string. Will return -1 if the letter is not found. Scans through the string from "startIndex" until it has examined all subsequent letters.
letter | Letter to find. |
startIndex | The index to start searching from. |
s32 WoopsiString::indexOf | ( | const char * | text | ) | const |
Gets the character index of the first occurence of the supplied char array within the string. If the char array is not found, the method will return -1.
text | The char array to find. |
s32 WoopsiString::indexOf | ( | const char * | text, |
s32 | startIndex | ||
) | const |
Gets the character index of the first occurence after startIndex of the supplied char array within the string. If the char array is not found, the method will return -1.
text | The char array to find. |
startIndex | The index to start searching from. |
void WoopsiString::init | ( | ) | [protected, virtual] |
Initialise the string's default state; called by constructors.
void WoopsiString::insert | ( | const WoopsiString & | text, |
const s32 | index | ||
) | [virtual] |
Insert text at the specified character index.
text | The text to insert. |
index | The index at which to insert the text. |
const s32 WoopsiString::lastIndexOf | ( | u32 | letter | ) | const |
Returns the last index of the specified letter within the string. Will return -1 if the letter is not found.
letter | Letter to find. |
s32 WoopsiString::lastIndexOf | ( | const char * | text | ) | const |
Gets the character index of the last occurence of the supplied char array within the string. If the char array is not found, the method will return -1.
text | The char array to find. |
s32 WoopsiString::lastIndexOf | ( | const char * | text, |
s32 | startIndex | ||
) | const |
Gets the character index of the last occurence after startIndex of the supplied char array within the string. If the char array is not found, the method will return -1.
text | The char array to find. |
startIndex | The index to start searching from. |
const s32 WoopsiString::lastIndexOf | ( | u32 | letter, |
s32 | startIndex | ||
) | const |
Returns the last index of the specified letter within the string. Will return -1 if the letter is not found. Scans through the string backwards from "startIndex" until it has examined all preceding letters within the string.
letter | Letter to find. |
startIndex | The index to start searching from. |
const s32 WoopsiString::lastIndexOf | ( | u32 | letter, |
s32 | startIndex, | ||
s32 | count | ||
) | const [virtual] |
Returns the last index of the specified letter within the string. Will return -1 if the letter is not found. Scans through the string backwards from "startIndex" until it has examined all letters within the range "count".
letter | Letter to find. |
startIndex | The index to start searching from. |
count | The number of characters to examine. |
s32 WoopsiString::lastIndexOf | ( | const WoopsiString & | text, |
s32 | startIndex, | ||
s32 | count | ||
) | const |
Gets the character index of the last occurence of the supplied string within the bounds of the current string between startIndex and startIndex - count. If the string is not found, the method will return -1.
text | The char array to find. |
startIndex | The index to start searching from. |
count | The number of characters to examine. |
StringIterator * WoopsiString::newStringIterator | ( | ) | const |
Creates and returns a new StringIterator object that will iterate over this string. The object must be manually deleted once it is no longer needed.
bool WoopsiGfx::WoopsiString::operator!= | ( | const WoopsiString & | string | ) | [inline] |
Overloaded inequality operator. Checks if this string and the supplied argument are not equal.
string | The string to compare with. |
WoopsiString WoopsiString::operator+ | ( | const WoopsiString & | string | ) |
Overloaded addition operator. Creates a copy of the current string, appends the parameter string, and returns the updated copy.
string | The string to append. |
WoopsiString & WoopsiString::operator+= | ( | const WoopsiString & | string | ) |
Overloaded compound addition/assignment operator. Appends the parameter string to the current string.
string | The string to append. |
WoopsiString & WoopsiString::operator= | ( | u32 | letter | ) |
Overloaded assignment operator. Copies the data from the argument char to this string.
letter | The char to copy. |
WoopsiString & WoopsiString::operator= | ( | const WoopsiString & | string | ) |
Overloaded assignment operator. Copies the data within the argument string to this string.
string | The string to copy. |
WoopsiString & WoopsiString::operator= | ( | const char * | string | ) |
Overloaded assignment operator. Copies the data within the argument char array to this string.
string | The string to copy. |
bool WoopsiGfx::WoopsiString::operator== | ( | const WoopsiString & | string | ) | [inline] |
Overloaded equality operator. Checks if this string and the supplied argument are equal.
string | The string to compare with. |
void WoopsiString::remove | ( | const s32 | startIndex, |
const s32 | count | ||
) | [virtual] |
Remove specified number of characters from the string from the start index onwards.
startIndex | Index to remove from. |
count | Number of characters to remove. |
void WoopsiString::remove | ( | const s32 | startIndex | ) | [virtual] |
Remove all characters from the string from the start index onwards.
startIndex | Index to remove from. |
void WoopsiString::replace | ( | const WoopsiString & | oldText, |
const WoopsiString & | newText | ||
) |
Replace all instances of oldText within the current string with newText.
oldText | The text to search for and replace. |
newText | The new text that will appear in place of the old. |
void WoopsiString::replace | ( | const s32 | startIndex, |
const s32 | count, | ||
const WoopsiString & | newText | ||
) |
Replace the text between the bounds defined by startIndex and startIndex + count with newText.
startIndex | The index to start replacing from. |
count | The number of characters to replace. |
newText | The new text that will appear in place of the old. |
void WoopsiString::replace | ( | const WoopsiString & | oldText, |
const WoopsiString & | newText, | ||
const s32 | startIndex, | ||
const s32 | replaceCount | ||
) |
Replace the first replaceCount instances of oldText within the current string from startIndex onwards with newText.
oldText | The text to search for and replace. |
newText | The new text that will appear in place of the old. |
startIndex | The index to start replacing from. |
replaceCount | The number of replacements to make. |
void WoopsiString::replace | ( | const WoopsiString & | oldText, |
const WoopsiString & | newText, | ||
const s32 | startIndex | ||
) |
Replace all instances of oldText within the current string from startIndex onwards with newText.
oldText | The text to search for and replace. |
newText | The new text that will appear in place of the old. |
startIndex | The index to start replacing from. |
void WoopsiString::setText | ( | const WoopsiString & | text, |
const s32 | startIndex, | ||
const s32 | length | ||
) | [virtual] |
Set the text in the string to be a substring of the supplied text.
text | WoopsiString containing the new data for this string. |
startIndex | The starting point of the substring. |
length | The length of the substring. |
void WoopsiString::setText | ( | const u32 | text | ) | [virtual] |
Set the text in the string.
text | Character to to use as the new data for this string. |
void WoopsiString::setText | ( | const char * | text | ) | [virtual] |
Set the text in the string.
text | Char array to use as the new data for this string. |
void WoopsiString::setText | ( | const WoopsiString & | text | ) | [virtual] |
Set the text in the string.
text | WoopsiString containing the new data for this string. |
void WoopsiString::split | ( | const WoopsiString & | separator, |
WoopsiArray< WoopsiString > & | result | ||
) | const |
Splits the string into substrings divided by the supplied separator. The substrings will be placed in the result WoopsiArray.
separator | String used to divide this string. |
result | Will be populated with the subsections of the divided string. |
void WoopsiString::split | ( | const WoopsiString & | separator, |
bool | allowEmptyEntries, | ||
WoopsiArray< WoopsiString > & | result | ||
) | const |
Splits the string into substrings divided by the supplied separator. The substrings will be placed in the result WoopsiArray.
separator | String used to divide this string. |
allowEmptyEntries | If set to false, any empty substrings produced by the dividing process will not be added to the result array. |
result | Will be populated with the subsections of the divided string. |
WoopsiString WoopsiString::subString | ( | s32 | startIndex, |
s32 | length | ||
) | const |
Get a substring from this string.
startIndex | The starting point of the substring. |
length | The length of the substring. |
WoopsiString WoopsiString::subString | ( | s32 | startIndex | ) | const |
Get a substring from this string.
startIndex | The starting point of the substring. |
char* WoopsiGfx::WoopsiString::_text [protected] |
Raw char array data