Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
AsciiString Class Reference

#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
 
AsciiStringoperator= (const AsciiString &stringSrc)
 the same as set()
 
AsciiStringoperator= (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
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

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.

Constructor & Destructor Documentation

◆ AsciiString() [1/3]

AsciiString::AsciiString ( )
inline

Default constructor – construct a new, empty AsciiString.

Definition at line 357 of file AsciiString.h.

◆ AsciiString() [2/3]

AsciiString::AsciiString ( const AsciiString & stringSrc)
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.

◆ AsciiString() [3/3]

AsciiString::AsciiString ( const char * s)
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.

◆ ~AsciiString()

AsciiString::~AsciiString ( )
inline

Destructor. Not too exciting... clean up the works and such.

Definition at line 403 of file AsciiString.h.

Member Function Documentation

◆ clear()

void AsciiString::clear ( )
inline

Make the string empty. Equivalent to (str = "") but slightly more efficient.

Definition at line 424 of file AsciiString.h.

◆ compare() [1/2]

int AsciiString::compare ( const AsciiString & stringSrc) const
inline

Conceptually identical to strcmp().

Definition at line 546 of file AsciiString.h.

◆ compare() [2/2]

int AsciiString::compare ( const char * s) const
inline

Conceptually identical to strcmp().

Definition at line 553 of file AsciiString.h.

◆ compareNoCase() [1/2]

int AsciiString::compareNoCase ( const AsciiString & stringSrc) const
inline

Conceptually identical to _stricmp().

Definition at line 560 of file AsciiString.h.

◆ compareNoCase() [2/2]

int AsciiString::compareNoCase ( const char * s) const
inline

Conceptually identical to _stricmp().

Definition at line 567 of file AsciiString.h.

◆ concat() [1/3]

void AsciiString::concat ( const AsciiString & stringSrc)
inline

Concatenate the given string onto self.

Definition at line 528 of file AsciiString.h.

◆ concat() [2/3]

void AsciiString::concat ( const char * s)
inline

Concatenate the given string onto self.

Definition at line 509 of file AsciiString.h.

◆ concat() [3/3]

void AsciiString::concat ( const char c)
inline

Concatenate the given character onto self.

this can probably be made more efficient, if necessary

Definition at line 536 of file AsciiString.h.

◆ debugIgnoreLeaks()

void AsciiString::debugIgnoreLeaks ( )

Definition at line 105 of file AsciiString.cpp.

◆ endsWith() [1/2]

Bool AsciiString::endsWith ( const AsciiString & stringSrc) const
inline

Definition at line 304 of file AsciiString.h.

◆ endsWith() [2/2]

Bool AsciiString::endsWith ( const char * p) const

return true iff self ends with the given string.

Definition at line 334 of file AsciiString.cpp.

◆ endsWithNoCase() [1/2]

Bool AsciiString::endsWithNoCase ( const AsciiString & stringSrc) const
inline

Definition at line 310 of file AsciiString.h.

◆ endsWithNoCase() [2/2]

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.

◆ ensureUniqueBufferOfSize()

void AsciiString::ensureUniqueBufferOfSize ( int numCharsNeeded,
Bool preserveData,
const char * strToCpy,
const char * strToCat )
protected

Definition at line 120 of file AsciiString.cpp.

◆ find()

const char * AsciiString::find ( char c) const
inline

Conceptually identical to strchr().

Definition at line 574 of file AsciiString.h.

◆ format() [1/2]

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.

◆ format() [2/2]

void AsciiString::format ( const char * format,
... )

Definition at line 273 of file AsciiString.cpp.

◆ format_va() [1/2]

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.

◆ format_va() [2/2]

void AsciiString::format_va ( const char * format,
va_list args )

Definition at line 295 of file AsciiString.cpp.

◆ getBufferForRead()

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.

◆ getCharAt()

char AsciiString::getCharAt ( int index) const
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.

◆ getLength()

int AsciiString::getLength ( ) const
inline

Return the length, in characters (not bytes!), of the string.

Definition at line 410 of file AsciiString.h.

◆ isEmpty()

Bool AsciiString::isEmpty ( ) const
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.

◆ isNone()

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.

◆ isNotEmpty()

Bool AsciiString::isNotEmpty ( ) const
inline

Definition at line 328 of file AsciiString.h.

◆ isNotNone()

Bool AsciiString::isNotNone ( ) const
inline

Definition at line 329 of file AsciiString.h.

◆ nextToken()

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.

◆ operator=() [1/2]

AsciiString & AsciiString::operator= ( const AsciiString & stringSrc)
inline

the same as set()

Definition at line 491 of file AsciiString.h.

◆ operator=() [2/2]

AsciiString & AsciiString::operator= ( const char * s)
inline

the same as set()

Definition at line 500 of file AsciiString.h.

◆ peek()

char * AsciiString::peek ( ) const
inlineprotected

Definition at line 349 of file AsciiString.h.

◆ releaseBuffer()

void AsciiString::releaseBuffer ( )
inlineprotected

Definition at line 387 of file AsciiString.h.

◆ removeLastChar()

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.

◆ reverseFind()

const char * AsciiString::reverseFind ( char c) const
inline

Conceptually identical to strrchr().

Definition at line 580 of file AsciiString.h.

◆ set() [1/2]

void AsciiString::set ( const AsciiString & stringSrc)
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.

◆ set() [2/2]

void AsciiString::set ( const char * s)
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.

◆ startsWith() [1/2]

Bool AsciiString::startsWith ( const AsciiString & stringSrc) const
inline

Definition at line 292 of file AsciiString.h.

◆ startsWith() [2/2]

Bool AsciiString::startsWith ( const char * p) const

return true iff self starts with the given string.

Definition at line 306 of file AsciiString.cpp.

◆ startsWithNoCase() [1/2]

Bool AsciiString::startsWithNoCase ( const AsciiString & stringSrc) const
inline

Definition at line 298 of file AsciiString.h.

◆ startsWithNoCase() [2/2]

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.

◆ str()

const char * AsciiString::str ( ) const
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.

◆ toLower()

void AsciiString::toLower ( void )

Make the string lowercase

Definition at line 226 of file AsciiString.cpp.

◆ translate()

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.

Todo
srj put in a real translation here; this will only work for 7-bit ascii

Definition at line 178 of file AsciiString.cpp.

◆ trim()

void AsciiString::trim ( void )

Remove leading and trailing whitespace from the string.

Definition at line 190 of file AsciiString.cpp.

Member Data Documentation

◆ m_data

AsciiStringData* AsciiString::m_data
protected

Definition at line 113 of file AsciiString.h.

◆ TheEmptyString

AsciiString AsciiString::TheEmptyString
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.


The documentation for this class was generated from the following files: