#include <UnicodeString.h>
Public Types | |
| enum | { MAX_FORMAT_BUF_LEN = 2048 , MAX_LEN = 32767 } |
Public Member Functions | |
| UnicodeString () | |
| UnicodeString (const UnicodeString &stringSrc) | |
| UnicodeString (const WideChar *s) | |
| ~UnicodeString () | |
| int | getLength () const |
| Bool | isEmpty () const |
| void | clear () |
| WideChar | getCharAt (int index) const |
| const WideChar * | str () const |
| WideChar * | getBufferForRead (Int len) |
| void | set (const UnicodeString &stringSrc) |
| void | set (const WideChar *s) |
| void | translate (const AsciiString &stringSrc) |
| void | concat (const UnicodeString &stringSrc) |
| void | concat (const WideChar *s) |
| void | concat (const WideChar c) |
| void | trim (void) |
| void | removeLastChar () |
| void | format (UnicodeString format,...) |
| void | format (const WideChar *format,...) |
| void | format_va (const UnicodeString &format, va_list args) |
| void | format_va (const WideChar *format, va_list args) |
| int | compare (const UnicodeString &stringSrc) const |
| int | compare (const WideChar *s) const |
| int | compareNoCase (const UnicodeString &stringSrc) const |
| int | compareNoCase (const WideChar *s) const |
| Bool | nextToken (UnicodeString *token, UnicodeString delimiters=UnicodeString::TheEmptyString) |
| UnicodeString & | operator= (const UnicodeString &stringSrc) |
| the same as set() | |
| UnicodeString & | operator= (const WideChar *s) |
| the same as set() | |
Static Public Attributes | |
| static UnicodeString | TheEmptyString |
Protected Member Functions | |
| WideChar * | peek () const |
| void | releaseBuffer () |
| void | ensureUniqueBufferOfSize (int numCharsNeeded, Bool preserveData, const WideChar *strToCpy, const WideChar *strToCat) |
Protected Attributes | |
| UnicodeStringData * | m_data |
UnicodeString is the fundamental double-byte string type used in the Generals code base, and should be preferred over all other string constructions (e.g., array of WideChar, STL string<>, WWVegas StringClass, etc.)
Of course, other string setups may be used when necessary or appropriate!
UnicodeString is modeled after the MFC CString class, with some minor syntactic differences to keep in line with our coding conventions.
Basically, UnicodeString allows you to treat a string as an intrinsic type, rather analogous to 'int' – when passed by value, a new string is created, and modifying the new string doesn't modify the original. This is done fairly efficiently, so that no new memory allocation is done unless the string is actually modified.
Naturally, UnicodeString handles all memory issues, so there's no need to do anything to free memory... just allow the UnicodeString's destructor to run.
UnicodeStrings are suitable for use as automatic, member, or static variables.
Definition at line 84 of file UnicodeString.h.
| anonymous enum |
| Enumerator | |
|---|---|
| MAX_FORMAT_BUF_LEN | max total len of string created by format/format_va |
| MAX_LEN | max total len of any UnicodeString, in chars |
Definition at line 117 of file UnicodeString.h.
|
inline |
Default constructor – construct a new, empty UnicodeString.
Definition at line 303 of file UnicodeString.h.
| UnicodeString::UnicodeString | ( | const UnicodeString & | stringSrc | ) |
Copy constructor – make this UnicodeString identical to the other UnicodeString. (This is actually quite efficient, because they will simply share the same string and increment the refcount.)
Definition at line 71 of file UnicodeString.cpp.
|
explicit |
Constructor – from a literal string. Constructs an UnicodeString with the given string. Note that a copy of the string is made; the input ptr is not saved. Note also that this is declared 'explicit' to avoid implicit conversions from const-WideChar-* (e.g., as input arguments).
Definition at line 144 of file UnicodeString.cpp.
|
inline |
Destructor. Not too exciting... clean up the works and such.
Definition at line 309 of file UnicodeString.h.
|
inline |
Make the string empty. Equivalent to (str = "") but slightly more efficient.
Definition at line 330 of file UnicodeString.h.
|
inline |
Conceptually identical to wsccmp().
Definition at line 390 of file UnicodeString.h.
|
inline |
Conceptually identical to wsccmp().
Definition at line 397 of file UnicodeString.h.
|
inline |
Conceptually identical to _wcsicmp().
Definition at line 404 of file UnicodeString.h.
|
inline |
Conceptually identical to _wcsicmp().
Definition at line 411 of file UnicodeString.h.
|
inline |
Concatenate the given string onto self.
Definition at line 372 of file UnicodeString.h.
| void UnicodeString::concat | ( | const WideChar * | s | ) |
Concatenate the given string onto self.
Definition at line 212 of file UnicodeString.cpp.
|
inline |
Concatenate the given character onto self.
this can probably be made more efficient, if necessary
Definition at line 380 of file UnicodeString.h.
|
protected |
Definition at line 80 of file UnicodeString.cpp.
| void UnicodeString::format | ( | const WideChar * | format, |
| ... ) |
Definition at line 297 of file UnicodeString.cpp.
| void UnicodeString::format | ( | UnicodeString | format, |
| ... ) |
Analogous to sprintf() – this formats a string according to the given sprintf-style format string (and the variable argument list) and stores the result in self.
Definition at line 286 of file UnicodeString.cpp.
| void UnicodeString::format_va | ( | const UnicodeString & | format, |
| va_list | args ) |
Identical to format(), but takes a va_list rather than a variable argument list. (i.e., analogous to vsprintf.)
Definition at line 308 of file UnicodeString.cpp.
| void UnicodeString::format_va | ( | const WideChar * | format, |
| va_list | args ) |
Definition at line 319 of file UnicodeString.cpp.
Makes sure there is room for a string of len+1 characters, and returns a pointer to the string buffer. This ensures that the string buffer is NOT shared. This is intended for the file reader, that is reading new strings in from a file. jba.
Definition at line 190 of file UnicodeString.cpp.
|
inline |
Return the character and the given (zero-based) index into the string. No range checking is done (except in debug mode).
Definition at line 338 of file UnicodeString.h.
|
inline |
Return the length, in characters (not bytes!), of the string.
Definition at line 316 of file UnicodeString.h.
|
inline |
Return true iff the length of the string is zero. Equivalent to (getLength() == 0) but slightly more efficient.
Definition at line 323 of file UnicodeString.h.
| Bool UnicodeString::nextToken | ( | UnicodeString * | token, |
| UnicodeString | delimiters = UnicodeString::TheEmptyString ) |
conceptually similar to strtok():
extract the next whitespace-delimited token from the front of 'this' and copy it into 'token', returning true if a nonempty token was found. (note that this modifies 'this' as well, stripping the token off!)
Definition at line 330 of file UnicodeString.cpp.
|
inline |
the same as set()
Definition at line 354 of file UnicodeString.h.
|
inline |
the same as set()
Definition at line 363 of file UnicodeString.h.
|
inlineprotected |
Definition at line 295 of file UnicodeString.h.
|
protected |
Definition at line 128 of file UnicodeString.cpp.
| void UnicodeString::removeLastChar | ( | ) |
Remove the final character in the string. If the string is empty, do nothing. (This is a rather dorky method, but used a lot in text editing, thus its presence here.)
Definition at line 270 of file UnicodeString.cpp.
| void UnicodeString::set | ( | const UnicodeString & | stringSrc | ) |
Replace the contents of self with the given string. (This is actually quite efficient, because they will simply share the same string and increment the refcount.)
Definition at line 155 of file UnicodeString.cpp.
| void UnicodeString::set | ( | const WideChar * | s | ) |
Replace the contents of self with the given string. Note that a copy of the string is made; the input ptr is not saved.
Definition at line 171 of file UnicodeString.cpp.
|
inline |
Return a pointer to the (null-terminated) string. Note that this is a const pointer: do NOT change this! It is imperative that it be impossible (or at least, really difficuly) for someone to change our private data, since it might be shared amongst other UnicodeStrings.
Definition at line 346 of file UnicodeString.h.
| void UnicodeString::translate | ( | const AsciiString & | stringSrc | ) |
replace contents of self with the given string. Note the nomenclature is translate rather than set; this is because not all single-byte strings translate one-for-one into UnicodeStrings, so some data manipulation may be necessary, and the resulting strings may not be equivalent.
Definition at line 200 of file UnicodeString.cpp.
| void UnicodeString::trim | ( | void | ) |
Remove leading and trailing whitespace from the string.
Definition at line 231 of file UnicodeString.cpp.
|
protected |
Definition at line 109 of file UnicodeString.h.
|
static |
This is a convenient global used to indicate the empty string, so we don't need to construct temporaries for such a common thing.
Definition at line 129 of file UnicodeString.h.