Woopsi 1.0
GUI Framework for Nintendo DS Homebrew
|
#include <woopsistring.h>
Public Member Functions | |
WoopsiString () | |
WoopsiString (const char *text) | |
WoopsiString (const u32 letter) | |
WoopsiString (const WoopsiString &string) | |
virtual | ~WoopsiString () |
StringIterator * | newStringIterator () const |
virtual void | copyToCharArray (char *buffer) const |
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) |
virtual s32 | compareTo (const WoopsiString &string) const |
Protected Member Functions | |
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 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).
WoopsiUI::WoopsiString::WoopsiString | ( | ) |
Constructor to create a blank object.
WoopsiUI::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. |
WoopsiUI::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. |
WoopsiUI::WoopsiString::WoopsiString | ( | const WoopsiString & | string | ) |
Copy constructor.
string | WoopsiString object to create a copy of. |
virtual WoopsiUI::WoopsiString::~WoopsiString | ( | ) | [inline, virtual] |
Destructor.
virtual void WoopsiUI::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 |
virtual void WoopsiUI::WoopsiString::append | ( | const WoopsiString & | text | ) | [virtual] |
Append text to the end of the string.
text | String to append. |
virtual s32 WoopsiUI::WoopsiString::compareTo | ( | const WoopsiString & | string | ) | const [virtual] |
Compares this string to the argument.
string | String to compare to. |
virtual void WoopsiUI::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 WoopsiUI::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. |
virtual s32 WoopsiUI::WoopsiString::getAllocatedSize | ( | ) | const [inline, protected, virtual] |
Get the amount of allocated memory.
virtual const s32 WoopsiUI::WoopsiString::getByteCount | ( | ) | const [inline, virtual] |
Get the of number of bytes in the string.
virtual const char* WoopsiUI::WoopsiString::getCharArray | ( | ) | const [inline, protected, virtual] |
Returns a pointer to the raw char array data.
virtual const u32 WoopsiUI::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 WoopsiUI::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 WoopsiUI::WoopsiString::getLength | ( | ) | const [inline, virtual] |
Get the of number of UTF-8 tokens (ie. the length) of the string.
virtual char* WoopsiUI::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 WoopsiUI::WoopsiString::hasData | ( | ) | const [inline, protected, virtual] |
Check if we've got any string data stored or not.
const s32 WoopsiUI::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 WoopsiUI::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. |
virtual const s32 WoopsiUI::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. |
virtual void WoopsiUI::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 WoopsiUI::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. |
const s32 WoopsiUI::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. |
virtual const s32 WoopsiUI::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. |
StringIterator* WoopsiUI::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.
WoopsiString& WoopsiUI::WoopsiString::operator= | ( | const WoopsiString & | string | ) |
Overloaded assignment operator. Copies the data within the argument string to this string.
string | The string to copy. |
WoopsiString& WoopsiUI::WoopsiString::operator= | ( | const char * | string | ) |
Overloaded assignment operator. Copies the data within the argument char array to this string.
string | The string to copy. |
WoopsiString& WoopsiUI::WoopsiString::operator= | ( | u32 | letter | ) |
Overloaded assignment operator. Copies the data from the argument char to this string.
letter | The char to copy. |
virtual void WoopsiUI::WoopsiString::remove | ( | const s32 | startIndex | ) | [virtual] |
Remove all characters from the string from the start index onwards.
startIndex | Index to remove from. |
virtual void WoopsiUI::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. |
virtual void WoopsiUI::WoopsiString::setText | ( | const WoopsiString & | text | ) | [virtual] |
Set the text in the string.
text | WoopsiString containing the new data for this string. |
virtual void WoopsiUI::WoopsiString::setText | ( | const u32 | text | ) | [virtual] |
Set the text in the string.
text | Character to to use as the new data for this string. |
virtual void WoopsiUI::WoopsiString::setText | ( | const char * | text | ) | [virtual] |
Set the text in the string.
text | Char array to use as the new data for this string. |
WoopsiString* WoopsiUI::WoopsiString::subString | ( | s32 | startIndex | ) | const |
Get a substring from this string. It is the responsibility of the caller to delete the substring when it is no longer required.
startIndex | The starting point of the substring. |
WoopsiString* WoopsiUI::WoopsiString::subString | ( | s32 | startIndex, |
s32 | length | ||
) | const |
Get a substring from this string. It is the responsibility of the caller to delete the substring when it is no longer required.
startIndex | The starting point of the substring. |
length | The length of the substring. |
char* WoopsiUI::WoopsiString::_text [protected] |
Raw char array data