#include <CATString.h>
This needs a few features for optimization when time is available. First of all, there needs to be a copy-on-write / reference counting feature added so that when strings are copied as return values and such, they don't need to allocate additional RAM unless they are modified.
Also, it could be smarter about the unicode/ASCII buffer swapping. Right now the class is rather innefficient, but it's pretty convenient.
Watch for performance hits when using this class, and fix them if necessary. Don't use in an inner loop :)
Lastly, this ain't directly portable off windows. Many of the string functions (e.g. _vsnwprintf) will need to be modified. Sorry, planning on doing that first thing when porting it :)
Definition at line 39 of file CATString.h.
Public Member Functions | |
CATString () | |
CATString() - Default constructor. | |
CATString (const CATString &str) | |
CATString (const char *str) | |
CATString (const CATWChar *str) | |
CATString (CATUInt32 val) | |
CATString (CATInt32 val) | |
CATString (CATFloat32 val) | |
CATString (CATFloat64 val) | |
CATString (const GUID &guid) | |
CATString (const GUID *guid) | |
CATString (char val) | |
CATString (CATWChar val) | |
CATString (bool val) | |
~CATString () | |
Destructor. | |
void | SetCodePage (CATUInt32 codePage) |
CATString & | operator= (const CATString &str) |
CATString & | operator= (const char *asciistr) |
CATString & | operator= (const CATWChar *unistr) |
CATString & | operator= (char val) |
CATString & | operator= (CATWChar val) |
CATString & | operator= (CATFloat32 val) |
CATString & | operator= (CATFloat64 val) |
CATString & | operator= (const GUID &guid) |
CATString & | operator= (const GUID *guid) |
CATString & | operator= (CATUInt32 val) |
CATString & | operator= (CATInt32 val) |
CATString & | operator= (bool val) |
CATString & | operator+= (const CATString &str) |
CATString & | operator<< (const CATString &str) |
CATString & | operator<< (const char *str) |
CATString & | operator<< (const CATWChar *str) |
CATString & | operator<< (char strChar) |
CATString & | operator<< (const CATWChar strChar) |
CATString & | operator<< (CATUInt32 val) |
CATString & | operator<< (CATInt32 val) |
CATString & | operator<< (CATFloat32 val) |
CATString & | operator<< (CATFloat64 val) |
CATString & | operator<< (const GUID &guid) |
CATString & | operator<< (const GUID *guid) |
operator const char * () const | |
operator const CATWChar * () const | |
operator CATInt32 () const | |
Convert the string to a long, if possible. | |
operator CATInt64 () const | |
operator CATFloat32 () const | |
Convert the string to a float, if possible. | |
operator CATFloat64 () const | |
Convert the string to a float, if possible. | |
operator CATUInt32 () const | |
Convert the string to an unsigned long, if possible. | |
operator bool () const | |
Convert the string to a bool, if possible. | |
CATWChar | GetWChar (CATUInt32 offset) const |
bool | SetWChar (CATUInt32 offset, CATWChar theChar) |
CATUInt32 | Length () |
CATUInt32 | LengthCalc () const |
CATInt32 | Compare (const CATString &str, CATUInt32 cmpLen=0, CATUInt32 offset=0) const |
CATInt32 | CompareNoCase (const CATString &str, CATUInt32 cmpLen=0, CATUInt32 offset=0) const |
CATString | Left (CATUInt32 maxlength) const |
CATString | Right (CATUInt32 start) const |
CATString | FromRight (CATUInt32 length) const |
CATString | Sub (CATUInt32 start, CATUInt32 length) const |
bool | PullNextToken (CATString &token, const CATString &splitTokens) |
bool | Find (const CATString &str, CATUInt32 &offset) const |
bool | Find (CATWChar theChar, CATUInt32 &offset) const |
bool | ReverseFind (const CATString &str, CATUInt32 &offset) const |
bool | ReverseFind (CATWChar theChar, CATUInt32 &offset) const |
bool | IsEmpty () const |
Returns true if string is empty. | |
char * | GetAsciiBuffer (CATUInt32 minLength=0) |
CATWChar * | GetUnicodeBuffer (CATUInt32 minlength=0) |
void | ReleaseBuffer () |
Releases the previous get buffer. | |
void | Trim () |
Trims whitespace chars off both ends of the string. | |
void | Pad (CATUInt32 length, CATWChar theChar=(CATWChar) 0x20) |
CATString & | AppendHex (CATUInt32 hexValue, bool addX=true) |
CATString & | AppendHexByte (CATUInt8 hexValue, bool addX=false) |
CATUInt32 | FromHex () const |
FromHex() converts a string from hex to a CATUInt32. | |
bool | GetGUID (GUID &guid) const |
void | ToUpper () |
void | ToLower () |
const CATString & | Format (const CATWChar *formatSpecs,...) |
Similar to (and uses) swprintf, variable arg formatting. | |
const CATString & | Format (const char *formatSpecs,...) |
Similar to (and uses) sprintf, variable arg formatting. | |
const CATString & | FormatArgs (const CATWChar *formatSpecs, va_list args) |
Formats a string with arguments given a va_list (wide char version). | |
const CATString & | FormatArgs (const char *formatSpecs, va_list args) |
Formats a string with arguments given a va_list. | |
bool | SplitPath (CATString *drive, CATString *path, CATString *filename, CATString *ext) const |
CATString | GetDriveDirectory () const |
Retrieve just the drive and directory from a full path. | |
CATString | GetFilenameExt () const |
Retrieve just the filename and extension from a full path. | |
CATString | GetFilenameNoExt () const |
Retrieve the filename, but not the extension from a full path. | |
CATString | Escape () const |
CATString | Unescape () const |
CATString | EncodeURL () const |
CATString | DecodeURL () const |
Protected Member Functions | |
bool | Create (CATUInt32 length) |
Creates a buffer for a string of the specified length. | |
_inline void | Init () |
Should only be called by constructors (or very carefully from Destroy) to init members. | |
_inline void | Destroy () |
CATUInt32 | GetLength (const char *asciistr) const |
CATUInt32 | GetLength (const CATWChar *unistr) const |
void | CopyIn (const CATWChar *unistr) |
Copies the unicode string into the fUnicodeStr. | |
bool | AllocBuffer (CATUInt32 minLength=0) |
bool | ExpandBuffer (CATUInt32 minLength=0) |
bool | ImportAscii (const char *ascii) |
These replace the old Update() function. | |
bool | UnicodeFromAscii () |
bool | AsciiFromUnicode () const |
Static Protected Member Functions | |
static void | CopyBuffer (char *str1, const char *str2, CATUInt32 length) |
Copies a buffer of chars. | |
static void | CopyBuffer (CATWChar *str1, const CATWChar *str2, CATUInt32 length) |
Copies a buffer of wide chars. | |
Private Attributes | |
bool | fBufferSizeLocked |
True when locked by get buffer. | |
CATUInt32 | fStrLen |
String length if known and not dirty. | |
bool | fLenDirty |
String modified since last size check. | |
CATUInt32 | fBufferLength |
Length of current buffer - include 0. | |
char * | fBuffer |
ASCII buffer. | |
CATWChar * | fUnicodeBuffer |
Unicode buffer. | |
bool | fAsciiLocked |
Ascii is locked - can't use unicode functions. | |
bool | fUnicodeLocked |
Unicode is locked - can't use ascii functions. | |
CATUInt32 | fCodePage |
Current codepage. |