#include <AsciiString.h>
Public Types | |
| enum | { MAX_FORMAT_BUF_LEN = 2048 , MAX_LEN = 32767 } |
Public Member Functions | |
| AsciiString () | |
| AsciiString (const AsciiString &stringSrc) | |
| AsciiString (const char *s) | |
| ~AsciiString () | |
| int | getLength () const |
| Bool | isEmpty () const |
| void | clear () |
| char | getCharAt (int index) const |
| const char * | str () const |
| char * | getBufferForRead (Int len) |
| void | set (const AsciiString &stringSrc) |
| void | set (const char *s) |
| void | translate (const UnicodeString &stringSrc) |
| void | concat (const AsciiString &stringSrc) |
| void | concat (const char *s) |
| void | concat (const char c) |
| void | trim (void) |
| void | toLower (void) |
| void | removeLastChar () |
| void | format (AsciiString format,...) |
| void | format (const char *format,...) |
| void | format_va (const AsciiString &format, va_list args) |
| void | format_va (const char *format, va_list args) |
| int | compare (const AsciiString &stringSrc) const |
| int | compare (const char *s) const |
| int | compareNoCase (const AsciiString &stringSrc) const |
| int | compareNoCase (const char *s) const |
| const char * | find (char c) const |
| const char * | reverseFind (char c) const |
| Bool | startsWith (const char *p) const |
| Bool | startsWith (const AsciiString &stringSrc) const |
| Bool | startsWithNoCase (const char *p) const |
| Bool | startsWithNoCase (const AsciiString &stringSrc) const |
| Bool | endsWith (const char *p) const |
| Bool | endsWith (const AsciiString &stringSrc) const |
| Bool | endsWithNoCase (const char *p) const |
| Bool | endsWithNoCase (const AsciiString &stringSrc) const |
| Bool | nextToken (AsciiString *token, const char *seps=NULL) |
| Bool | isNone () const |
| Bool | isNotEmpty () const |
| Bool | isNotNone () const |
| AsciiString & | operator= (const AsciiString &stringSrc) |
| the same as set() | |
| AsciiString & | operator= (const char *s) |
| the same as set() | |
| void | debugIgnoreLeaks () |
Static Public Attributes | |
| static AsciiString | TheEmptyString |
Protected Member Functions | |
| char * | peek () const |
| void | releaseBuffer () |
| void | ensureUniqueBufferOfSize (int numCharsNeeded, Bool preserveData, const char *strToCpy, const char *strToCat) |
Protected Attributes | |
| AsciiStringData * | m_data |
AsciiString is the fundamental single-byte string type used in the Generals code base, and should be preferred over all other string constructions (e.g., array of char, STL string<>, WWVegas StringClass, etc.)
Of course, other string setups may be used when necessary or appropriate!
AsciiString is modeled after the MFC CString class, with some minor syntactic differences to keep in line with our coding conventions.
Basically, AsciiString 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, AsciiString handles all memory issues, so there's no need to do anything to free memory... just allow the AsciiString's destructor to run.
AsciiStrings are suitable for use as automatic, member, or static variables.
Definition at line 86 of file AsciiString.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 AsciiString, in chars |
Definition at line 121 of file AsciiString.h.
|
inline |
Default constructor – construct a new, empty AsciiString.
Definition at line 357 of file AsciiString.h.
|
inline |
Copy constructor – make this AsciiString identical to the other AsciiString. (This is actually quite efficient, because they will simply share the same string and increment the refcount.)
Definition at line 375 of file AsciiString.h.
|
inline |
Constructor – from a literal string. Constructs an AsciiString with the given string. Note that a copy of the string is made; the input ptr is not saved. Note that this is no longer explicit, as the conversion is almost always wanted, anyhow.
Definition at line 363 of file AsciiString.h.
|
inline |
Destructor. Not too exciting... clean up the works and such.
Definition at line 403 of file AsciiString.h.
|
inline |
Make the string empty. Equivalent to (str = "") but slightly more efficient.
Definition at line 424 of file AsciiString.h.
|
inline |
Conceptually identical to strcmp().
Definition at line 546 of file AsciiString.h.
|
inline |
Conceptually identical to strcmp().
Definition at line 553 of file AsciiString.h.
|
inline |
Conceptually identical to _stricmp().
Definition at line 560 of file AsciiString.h.
|
inline |
Conceptually identical to _stricmp().
Definition at line 567 of file AsciiString.h.
|
inline |
Concatenate the given string onto self.
Definition at line 528 of file AsciiString.h.
|
inline |
Concatenate the given string onto self.
Definition at line 509 of file AsciiString.h.
|
inline |
Concatenate the given character onto self.
this can probably be made more efficient, if necessary
Definition at line 536 of file AsciiString.h.
| void AsciiString::debugIgnoreLeaks | ( | ) |
Definition at line 105 of file AsciiString.cpp.
|
inline |
Definition at line 304 of file AsciiString.h.
| Bool AsciiString::endsWith | ( | const char * | p | ) | const |
return true iff self ends with the given string.
Definition at line 334 of file AsciiString.cpp.
|
inline |
Definition at line 310 of file AsciiString.h.
| Bool AsciiString::endsWithNoCase | ( | const char * | p | ) | const |
return true iff self ends with the given string. (case insensitive)
Definition at line 348 of file AsciiString.cpp.
|
protected |
Definition at line 120 of file AsciiString.cpp.
|
inline |
Conceptually identical to strchr().
Definition at line 574 of file AsciiString.h.
| void AsciiString::format | ( | AsciiString | 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 262 of file AsciiString.cpp.
| void AsciiString::format | ( | const char * | format, |
| ... ) |
Definition at line 273 of file AsciiString.cpp.
| void AsciiString::format_va | ( | const AsciiString & | 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 284 of file AsciiString.cpp.
| void AsciiString::format_va | ( | const char * | format, |
| va_list | args ) |
Definition at line 295 of file AsciiString.cpp.
| char * AsciiString::getBufferForRead | ( | Int | len | ) |
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 168 of file AsciiString.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 432 of file AsciiString.h.
|
inline |
Return the length, in characters (not bytes!), of the string.
Definition at line 410 of file AsciiString.h.
|
inline |
Return true iff the length of the string is zero. Equivalent to (getLength() == 0) but slightly more efficient.
Definition at line 417 of file AsciiString.h.
| Bool AsciiString::isNone | ( | ) | const |
return true iff the string is "NONE" (case-insensitive). Hey, hokey, but we use it a ton.
Definition at line 362 of file AsciiString.cpp.
|
inline |
Definition at line 328 of file AsciiString.h.
|
inline |
Definition at line 329 of file AsciiString.h.
| Bool AsciiString::nextToken | ( | AsciiString * | token, |
| const char * | seps = NULL ) |
conceptually similar to strtok():
extract the next seps-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 368 of file AsciiString.cpp.
|
inline |
the same as set()
Definition at line 491 of file AsciiString.h.
|
inline |
the same as set()
Definition at line 500 of file AsciiString.h.
|
inlineprotected |
Definition at line 349 of file AsciiString.h.
|
inlineprotected |
Definition at line 387 of file AsciiString.h.
| void AsciiString::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 246 of file AsciiString.cpp.
|
inline |
Conceptually identical to strrchr().
Definition at line 580 of file AsciiString.h.
|
inline |
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 448 of file AsciiString.h.
|
inline |
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 472 of file AsciiString.h.
|
inline |
Definition at line 292 of file AsciiString.h.
| Bool AsciiString::startsWith | ( | const char * | p | ) | const |
return true iff self starts with the given string.
Definition at line 306 of file AsciiString.cpp.
|
inline |
Definition at line 298 of file AsciiString.h.
| Bool AsciiString::startsWithNoCase | ( | const char * | p | ) | const |
return true iff self starts with the given string. (case insensitive)
Definition at line 320 of file AsciiString.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 AsciiStrings.
Definition at line 440 of file AsciiString.h.
| void AsciiString::toLower | ( | void | ) |
Make the string lowercase
Definition at line 226 of file AsciiString.cpp.
| void AsciiString::translate | ( | const UnicodeString & | 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 178 of file AsciiString.cpp.
| void AsciiString::trim | ( | void | ) |
Remove leading and trailing whitespace from the string.
Definition at line 190 of file AsciiString.cpp.
|
protected |
Definition at line 113 of file AsciiString.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 133 of file AsciiString.h.