KString Class Reference

#include <kstring.h>

List of all members.


Detailed Description

Utility class to manipulate strings.

Definition at line 87 of file kstring.h.

Padding

enum  PaddingType
 Padding types. More...
KString Pad (PaddingType pPadding, int pLen, char pCar= ' ') const
 Add padding characters.
KString UnPad (PaddingType pPadding) const
 Remove padding characters.

Constructors and Destructor

static KStringCreate ()
 Create an instance.
static KStringCreate (KString *pString)
 Create an instance if not already allocated ( is null ).
static KStringDestroyIfEmpty (KString *pString)
 Destroy the allocated space if empty.
static KStringStringOrEmpty (KString *pString)
 Destroy the allocated space if empty.
void Destroy ()
 Destroy an allocated version of the string.

Constructors and Destructor

 KString ()
 Default constructor.
 KString (const KString &pStr)
 Copy constructor.
 KString (const char *pStr)
 String constructor.
 KString (char pChar, int pNbRepeat=1)
 Character constructor.
 KString (const char *pCharPtr, int pLength)
 String constructor with maximum length.
 KString (const int pValue)
 Int constructor.
 KString (const float pValue)
 Float constructor.
 KString (const double pValue)
 Double constructor.
 ~KString ()
 Destructor.

Instance Validation.

bool IsOK () const
 Return true if string is valid.
KStringInvalidate ()
 Invalidate string.
int GetLen () const
 Get string length like "C" strlen().
bool IsEmpty () const
 Return true if string is of length 0.
KStringEmpty ()
 Discard the content of the object.

Buffer Access

char & operator[] (int pIndex)
 Access by reference.
char operator[] (int pIndex) const
 Access by copy.
 operator const char * () const
 Cast operator.
char * ToChars () const
 Uniform non-UNICODE support.
char * Buffer ()
 Non-const buffer access.
char * GetBuffer ()
 Non-const buffer access, same as Buffer().

Assignement Operators

const KStringoperator= (const KString &pStr)
 KString assignment operator.
const KStringoperator= (char pChar)
 Character assignment operator.
const KStringoperator= (const char *pStr)
 String assignment operator.
const KStringoperator= (int pValue)
 Int assignment operator.
const KStringoperator= (float pValue)
 Float assignment operator.
const KStringoperator= (double pValue)
 Double assignment operator.
const KStringCopy (int pLen, const char *pStr)
 String assignment function.

Append and Concatenation

const KStringAppend (const char *pStr)
 Append as "C" strcat().
const KStringAppendN (const char *pStr, int pLength)
 Append as "C" strncat().
const KStringoperator+= (const KString &pKStr)
 KString append.
const KStringoperator+= (char pChar)
 Character append.
const KStringoperator+= (const char *pStr)
 String append.
const KStringoperator+= (int pValue)
 Int append.
const KStringoperator+= (float pValue)
 Float append.
KBASELIB_DLL KString operator+ (const KString &pKStr1, const KString &pKStr2)
 KString concatenation.
KBASELIB_DLL KString operator+ (const KString &pKStr, char pChar)
 Character concatenation.
KBASELIB_DLL KString operator+ (const KString &pKStr, const char *pStr)
 String concatenation.
KBASELIB_DLL KString operator+ (const KString &pKStr, int pValue)
 Int concatenation.
KBASELIB_DLL KString operator+ (const KString &pKStr, float pValue)
 Float concatenation.

String Comparison

int Compare (const char *pStr) const
 Compare as "C" strcmp().
int CompareNoCase (const char *pStr) const
 Compare as "C" stricmp().
bool operator== (const KString &pStr) const
 Equality operator.
bool operator!= (const KString &pStr) const
 Inequality operator.
bool operator< (const KString &pStr) const
 Inferior to operator.
bool operator<= (const KString &pStr) const
 Inferior or equal to operator.
bool operator>= (const KString &pStr) const
 Superior or equal to operator.
bool operator> (const KString &pStr) const
 Superior to operator.
bool operator== (const char *pStr) const
 Equality operator.
bool operator!= (const char *pStr) const
 Inequality operator.
bool operator< (const char *pStr) const
 Inferior to operator.
bool operator<= (const char *pStr) const
 Inferior or equal to operator.
bool operator>= (const char *pStr) const
 Superior or equal to operator.
bool operator> (const char *pStr) const
 Superior to operator.

Substring Extraction

KString Mid (int pFirst, int pCount) const
 Extract middle string for a given length.
KString Mid (int pFirst) const
 Extract middle string up to the end.
KString Left (int pCount) const
 Extract left string.
KString Right (int pCount) const
 Extract right string.

Conversion

KString Upper () const
 Uppercase conversion.
KString Lower () const
 Lowercase conversion.
KString Reverse () const
 Reverse conversion.
KString ConvertToUnix () const
 Convert to Unix, changes \r\n characters for a single \n.
KString ConvertToWindows () const
 Convert to Windows, changes \n character for both \r\n.

Search

int Find (char pChar, int pStartPosition=0) const
 Look for a single character match, like "C" strchr().
int Find (const char *pStrSub, int pStartPosition=0) const
 Look for a substring match, like "C" strstr().
int ReverseFind (char pChar) const
 Look for a single character match, like "C" strrchr().
int FindOneOf (const char *pStrCharSet, int pStartPosition=0) const
 Look for a single character match, like "C" strpbrk().
bool FindAndReplace (const char *pFind, const char *pReplaceBy, int pStartPosition=0)
 Replace a substring.

Token Extraction

int GetTokenCount (const char *pSpans)
 Get number of tokens.
KString GetToken (int pTokenIndex, const char *pSpans)
 Get token at given index.


Member Enumeration Documentation

Padding types.

Definition at line 334 of file kstring.h.


Constructor & Destructor Documentation

KString (  ) 

Default constructor.

KString ( const KString pStr  ) 

Copy constructor.

KString ( const char *  pStr  ) 

String constructor.

KString ( char  pChar,
int  pNbRepeat = 1 
)

Character constructor.

KString ( const char *  pCharPtr,
int  pLength 
)

String constructor with maximum length.

KString ( const int  pValue  ) 

Int constructor.

KString ( const float  pValue  ) 

Float constructor.

KString ( const double  pValue  ) 

Double constructor.

~KString (  ) 

Destructor.


Member Function Documentation

static KString* Create (  )  [static]

Create an instance.

static KString* Create ( KString pString  )  [static]

Create an instance if not already allocated ( is null ).

void Destroy (  ) 

Destroy an allocated version of the string.

static KString* DestroyIfEmpty ( KString pString  )  [static]

Destroy the allocated space if empty.

static KString* StringOrEmpty ( KString pString  )  [static]

Destroy the allocated space if empty.

bool IsOK (  )  const

Return true if string is valid.

KString& Invalidate (  ) 

Invalidate string.

int GetLen (  )  const

Get string length like "C" strlen().

Referenced by StripQuotationMarks().

bool IsEmpty (  )  const

Return true if string is of length 0.

KString& Empty (  ) 

Discard the content of the object.

char& operator[] ( int  pIndex  ) 

Access by reference.

char operator[] ( int  pIndex  )  const

Access by copy.

operator const char * (  )  const

Cast operator.

char* ToChars (  )  const

Uniform non-UNICODE support.

char* Buffer (  ) 

char* GetBuffer (  ) 

Non-const buffer access, same as Buffer().

const KString& operator= ( const KString pStr  ) 

KString assignment operator.

const KString& operator= ( char  pChar  ) 

Character assignment operator.

const KString& operator= ( const char *  pStr  ) 

String assignment operator.

const KString& operator= ( int  pValue  ) 

Int assignment operator.

const KString& operator= ( float  pValue  ) 

Float assignment operator.

const KString& operator= ( double  pValue  ) 

Double assignment operator.

const KString& Copy ( int  pLen,
const char *  pStr 
)

String assignment function.

const KString& Append ( const char *  pStr  ) 

Append as "C" strcat().

const KString& AppendN ( const char *  pStr,
int  pLength 
)

Append as "C" strncat().

const KString& operator+= ( const KString pKStr  ) 

KString append.

const KString& operator+= ( char  pChar  ) 

Character append.

const KString& operator+= ( const char *  pStr  ) 

String append.

const KString& operator+= ( int  pValue  ) 

Int append.

const KString& operator+= ( float  pValue  ) 

Float append.

int Compare ( const char *  pStr  )  const

Compare as "C" strcmp().

int CompareNoCase ( const char *  pStr  )  const

Compare as "C" stricmp().

bool operator== ( const KString pStr  )  const

Equality operator.

bool operator!= ( const KString pStr  )  const

Inequality operator.

bool operator< ( const KString pStr  )  const

Inferior to operator.

bool operator<= ( const KString pStr  )  const

Inferior or equal to operator.

bool operator>= ( const KString pStr  )  const

Superior or equal to operator.

bool operator> ( const KString pStr  )  const

Superior to operator.

bool operator== ( const char *  pStr  )  const

Equality operator.

bool operator!= ( const char *  pStr  )  const

Inequality operator.

bool operator< ( const char *  pStr  )  const

Inferior to operator.

bool operator<= ( const char *  pStr  )  const

Inferior or equal to operator.

bool operator>= ( const char *  pStr  )  const

Superior or equal to operator.

bool operator> ( const char *  pStr  )  const

Superior to operator.

KString Mid ( int  pFirst,
int  pCount 
) const

Extract middle string for a given length.

Referenced by RemoveChar(), and StripQuotationMarks().

KString Mid ( int  pFirst  )  const

Extract middle string up to the end.

KString Left ( int  pCount  )  const

Extract left string.

Referenced by RemoveChar().

KString Right ( int  pCount  )  const

Extract right string.

KString Pad ( PaddingType  pPadding,
int  pLen,
char  pCar = ' ' 
) const

Add padding characters.

KString UnPad ( PaddingType  pPadding  )  const

Remove padding characters.

KString Upper (  )  const

Uppercase conversion.

KString Lower (  )  const

Lowercase conversion.

KString Reverse (  )  const

Reverse conversion.

KString ConvertToUnix (  )  const

Convert to Unix, changes \r\n characters for a single \n.

KString ConvertToWindows (  )  const

Convert to Windows, changes \n character for both \r\n.

int Find ( char  pChar,
int  pStartPosition = 0 
) const

Look for a single character match, like "C" strchr().

Returns:
Index or -1 if not found.

int Find ( const char *  pStrSub,
int  pStartPosition = 0 
) const

Look for a substring match, like "C" strstr().

Returns:
Starting index or -1 if not found.

int ReverseFind ( char  pChar  )  const

Look for a single character match, like "C" strrchr().

Returns:
Index or -1 if not found.

Referenced by RemoveChar().

int FindOneOf ( const char *  pStrCharSet,
int  pStartPosition = 0 
) const

Look for a single character match, like "C" strpbrk().

Returns:
Index or -1 if not found.

bool FindAndReplace ( const char *  pFind,
const char *  pReplaceBy,
int  pStartPosition = 0 
)

Replace a substring.

Returns:
true if substring found and replaced.

int GetTokenCount ( const char *  pSpans  ) 

Get number of tokens.

KString GetToken ( int  pTokenIndex,
const char *  pSpans 
)

Get token at given index.


Friends And Related Function Documentation

KBASELIB_DLL KString operator+ ( const KString pKStr1,
const KString pKStr2 
) [friend]

KString concatenation.

KBASELIB_DLL KString operator+ ( const KString pKStr,
char  pChar 
) [friend]

Character concatenation.

KBASELIB_DLL KString operator+ ( const KString pKStr,
const char *  pStr 
) [friend]

String concatenation.

KBASELIB_DLL KString operator+ ( const KString pKStr,
int  pValue 
) [friend]

Int concatenation.

KBASELIB_DLL KString operator+ ( const KString pKStr,
float  pValue 
) [friend]

Float concatenation.