http://www.sea-of-memes.com/documentation/mgUtil/mgString.html
Class mgString
Declared in: mgUtil/Util/mgString.h
A variable-length string class. Wherever arguments are "const char*", these are assumed to be UTF-8 format strings. WCHAR arguments should be Unicode string constants, which are handled differently under each platform.
The (const char*) cast returns UTF-8 strings. The toWCHAR method returns a (const wchar_t*), which is only really useful under Windows, where system calls expect a string in this format.
Unfortunately, C++ automatically generates a cast to (const char*) when you code string[i] -- it becomes ((const char*) string)[i]. This allows the caller to iterate through characters, which is not meaningful in a UTF-8 string.
A 'letter' in the class is one or more Unicode characters (a main character and other combining characters) that together form a single symbol in a word. Since the internal format is UTF-8, a single letter may be many bytes.
class mgString
Public Variables
none.
Public Methods
mgString(const char* str, int len)
mgString(const WCHAR* str, int len)
mgString(const mgString& other)
mgString& operator=(const char* str)
mgString& operator=(const WCHAR* str)
mgString& operator=(const mgString& other)
mgString& operator+=(const char* str)
mgString& operator+=(const WCHAR* str)
mgString& operator+=(const mgString& buffer)
mgString& write(const char* data, int len)
mgString& write(const WCHAR* data, int len)
int nextLetter(int posn, char* letter = NULL)
int prevLetter(int posn, char* letter = NULL)
void toWCHAR(WCHAR*& target, int& len)
int compareN(int len, const char* str)
int compareN(int len, const WCHAR* str)
BOOL equalsIgnoreCase(const char* str)
BOOL equalsIgnoreCase(const WCHAR* str)
int find(int posn, const char* str, int len = -1)
int find(int posn, const WCHAR* str, int len = -1)
int reverseFind(int posn, char c)
int reverseFind(int posn, WCHAR c)
int reverseFind(int posn, const char* str, int len = -1)
int reverseFind(int posn, const WCHAR* str, int len = -1)
BOOL startsWith(const char* string)
BOOL startsWith(const WCHAR* string)
BOOL endsWith(const char* string)
BOOL endsWith(const WCHAR* string)
void deleteAt(int posn, int len)
void insertAt(int posn, const char* str, int len = -1)
int setLetter(int posn, const char* letter, int len = -1)
int setLetter(int posn, const int* chars, int len)
void deleteLettersAt(int posn, int len)
void substring(mgString& target, int posn, int len)
void substring(mgString& target, int posn)
int getToken(int posn, const char* delims, mgString& token)
int scan(const char* fmt, ...)
int scan(const WCHAR* fmt, ...)
void format(const char* fmt, ...)
void format(const WCHAR* fmt, ...)
void formatV(const char* fmt, va_list args)
void formatV(const WCHAR* fmt, va_list args)
int fromUTF8(const char* source, int& utfCount)
int lenWCHAR(const char* source, int len)
void toWCHAR(const char* source, WCHAR*& target, int& len)
Protected Variables
char m_shortData[ MG_SHORT_STRING_LEN]
Protected Methods
int lenUTF8(const WCHAR* source, int len)
void toUTF8(char* target, int& len, int source)
Details
| public | |
| mgString() | |
constructor | |
| public | |
| mgString( | |
| const char* str); | |
constructor | |
| public | |
| mgString( | |
| const WCHAR* str); | |
constructor | |
| public | |
| mgString( | |
| const char* str, | |
| int len); | |
constructor | |
| public | |
| mgString( | |
| const WCHAR* str, | |
| int len); | |
constructor | |
| public | |
| mgString( | |
| const mgString& other); | |
constructor | |
| public | |
| void setGrowBy( | |
| int len); | |
allocation increased by growby when string full | |
| public | |
| void setAllocLength( | |
| int len); | |
set memory allocated for string | |
| public | |
| mgString& operator=( | |
| char c); | |
assign to a character | |
| public | |
| mgString& operator=( | |
| WCHAR c); | |
assign to a character | |
| public | |
| mgString& operator=( | |
| const char* str); | |
assign to a string | |
| public | |
| mgString& operator=( | |
| const WCHAR* str); | |
assign to a string | |
| public | |
| mgString& operator=( | |
| const mgString& other); | |
assign to a string | |
| public | |
| mgString& operator+=( | |
| char c); | |
append char to string | |
| public | |
| mgString& operator+=( | |
| WCHAR c); | |
append char to string | |
| public | |
| mgString& operator+=( | |
| const char* str); | |
append to string | |
| public | |
| mgString& operator+=( | |
| const WCHAR* str); | |
append to string | |
| public | |
| mgString& operator+=( | |
| const mgString& buffer); | |
append to string | |
| public | |
| mgString& write( | |
| const char* data, | // data to append |
| int len); | // length of data |
append to string | |
| public | |
| mgString& write( | |
| const WCHAR* data, | // data to append |
| int len); | // length of data |
append to string | |
| public const | |
| int nextLetter( | |
| int posn, | |
| char* letter = NULL); | |
return next letter in a string. This may be more than a single Unicode character, if combining characters were supported. | |
| public const | |
| int prevLetter( | |
| int posn, | |
| char* letter = NULL); | |
return previous letter in a string. This may be more than a single Unicode character, if combining characters were supported. | |
| public const | |
| int countLetters() | |
return number of 'letters' in a string. Multiple unicode characters can make up a letter. | |
| public | |
| void empty() | |
reset the buffer to length 0 | |
| public const | |
| int length() | |
return the length | |
| public const | |
| BOOL isEmpty() | |
return true if empty | |
| public const | |
| operator const char*() | |
return buffer as const UTF-8 string | |
| public const | |
| void toWCHAR( | |
| WCHAR*& target, | |
| int& len); | |
return Unicode string. caller owns storage | |
| public const | |
| int compareN( | |
| int len, | // length to compare |
| const char* str); | // comparison string |
compare N letters of a string | |
| public const | |
| int compareN( | |
| int len, | // length to compare |
| const WCHAR* str); | // comparison string |
compare N letters of a string | |
| public const | |
| BOOL equals( | |
| const char* str); | // comparison string |
compare to a string | |
| public const | |
| BOOL equals( | |
| const WCHAR* str); | // comparison string |
compare to a string | |
| public const | |
| BOOL equalsIgnoreCase( | |
| const char* str); | // comparison string |
compare ignore case | |
| public const | |
| BOOL equalsIgnoreCase( | |
| const WCHAR* str); | // comparison string |
compare ignore case | |
| public const | |
| int find( | |
| int posn, | // starting letter position |
| char c); | // char to find |
find character | |
| public const | |
| int find( | |
| int posn, | // starting letter position |
| WCHAR c); | // char to find |
find character | |
| public const | |
| int find( | |
| int posn, | // starting letter position |
| const char* str, | // string to find |
| int len = -1); | // length of string (bytes) |
find substring | |
| public const | |
| int find( | |
| int posn, | // starting letter position |
| const WCHAR* str, | // string to find |
| int len = -1); | // length of string (unicode chars) |
find substring | |
| public const | |
| int reverseFind( | |
| int posn, | // ending letter position |
| char c); | // char to find |
find last occurance of char | |
| public const | |
| int reverseFind( | |
| int posn, | // ending letter position |
| WCHAR c); | // char to find |
find last occurance of char | |
| public const | |
| int reverseFind( | |
| int posn, | // ending letter position |
| const char* str, | // string to find |
| int len = -1); | // length (bytes) |
find last occurance of substring | |
| public const | |
| int reverseFind( | |
| int posn, | // ending letter position |
| const WCHAR* str, | // string to find |
| int len = -1); | // length (unicode chars) |
find last occurance of substring | |
| public const | |
| BOOL startsWith( | |
| const char* string); | |
return true if starts with string | |
| public const | |
| BOOL startsWith( | |
| const WCHAR* string); | |
return true if starts with string | |
| public const | |
| BOOL endsWith( | |
| const char* string); | |
return true if ends with string | |
| public const | |
| BOOL endsWith( | |
| const WCHAR* string); | |
return true if ends with string | |
| public | |
| void trimLeft() | |
remove leading white space | |
| public | |
| void trimRight() | |
remove trailing white space | |
| public | |
| void trim() | |
remove leading and trailing white space | |
| public const | |
| BOOL isSpace( | |
| int posn); | |
return true if char posn is a space | |
| public const | |
| BOOL isDigit( | |
| int posn); | |
return true if char posn is a digit | |
| public const | |
| BOOL isHexDigit( | |
| int posn); | |
return true if char posn is a hex digit | |
| public const | |
| BOOL isAlphaNumeric( | |
| int posn); | |
return true if char posn is alpha numeric | |
| public | |
| void makeLower() | |
convert to lower case | |
| public | |
| void deleteAt( | |
| int posn, | // starting letter offset |
| int len); | // count of letters |
delete text | |
| public | |
| void insertAt( | |
| int posn, | // letter offset |
| const char* str, | // string to insert |
| int len = -1); | // length of string |
insert into string | |
| public | |
| int setLetter( | |
| int posn, | // letter offset |
| const char* letter, | // letter codes |
| int len = -1); | // length of string |
replace a letter, return next position | |
| public | |
| int setLetter( | |
| int posn, | // letter offset |
| const int* chars, | // unicode characters |
| int len); | // count of characters |
replace a letter, return next position | |
| public | |
| void deleteLettersAt( | |
| int posn, | // starting letter offset |
| int len); | // count of letters |
delete letters | |
| public const | |
| void substring( | |
| mgString& target, | |
| int posn, | // letter offset |
| int len); | // length (bytes) |
extract substring | |
| public const | |
| void substring( | |
| mgString& target, | |
| int posn); | |
extract from position to end of string | |
| public const | |
| int getToken( | |
| int posn, | |
| const char* delims, | |
| mgString& token); | |
get next token, return ending position | |
| public const | |
| int scan( | |
| const char* fmt, | |
| ...); | |
scan string and extract items | |
| public const | |
| int scan( | |
| const WCHAR* fmt, | |
| ...); | |
scan string and extract items | |
| public | |
| void format( | |
| const char* fmt, | |
| ...); | |
format string to buffer | |
| public | |
| void format( | |
| const WCHAR* fmt, | |
| ...); | |
format wide string to buffer | |
| public | |
| void formatV( | |
| const char* fmt, | |
| va_list args); | |
format string to buffer, variable args | |
| public | |
| void formatV( | |
| const WCHAR* fmt, | |
| va_list args); | |
format wide string to buffer, variable args | |
| public static | |
| int fromUTF8( | |
| const char* source, | |
| int& utfCount); | |
convert UTF8 string to unicode | |
| public static | |
| int lenWCHAR( | |
| const char* source, | |
| int len); | |
return length of string in WCHAR | |
| public static | |
| void toWCHAR( | |
| const char* source, | |
| WCHAR*& target, | |
| int& len); | |
return Unicode string. caller owns storage | |
| protected | |
| int m_allocLen; | |
allocation length | |
| protected | |
| int m_dataLen; | |
data length | |
| protected | |
| int m_growBy; | |
size of increase in alloc | |
| protected | |
| char* m_data; | |
data to add | |
| protected | |
| char m_shortData[ MG_SHORT_STRING_LEN]; | |
initial data | |
| protected | |
| void init() | |
shared initialization | |
| protected | |
| void grow( | |
| int newLen); | // length needed |
grow buffer to hold new length | |
| protected static | |
| int lenUTF8( | |
| int c); | |
return length of UTF-8 encoded char | |
| protected static | |
| int lenUTF8( | |
| const WCHAR* source, | |
| int len); | |
return length of UTF-8 encoded string | |
| protected static | |
| void toUTF8( | |
| char* target, | |
| int& len, | |
| int source); | |
convert to UTF8 format | |