KString
#include<kstring.h>

List of all members.

Detailed Description

Utility class to manipulate strings.

Definition at line97of filekstring.h.


Padding

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

Constructors and Destructor

staticKStringCreate()
 Create an instance.
staticKStringCreate(KString*pString)
 Create an instance if not already allocated ( is null ).
staticKStringDestroyIfEmpty(KString*pString)
 Destroy the allocated space if empty.
staticKStringStringOrEmpty(KString*pString)
 Return the passed pString if it is not empty, or a local static emptyKStringwill be returned.
void Destroy()
 Destroy an allocated version of the string.

Memory Pool Management

static KMemoryAllocator * AllocatorGet()
 Get new memory allocator.
static void AllocatorPurge()
 Purge memory allocator.
static void AllocatorRelease()
 Release memory allocator.

Constructors and Destructor

 KString()
 Default constructor.
 KString(constKString&pStr)
 Copy constructor.
 KString(const char *pStr)
 String constructor.
 KString(char pChar, size_t pNbRepeat=1)
 Character constructor.
 KString(const char *pCharPtr, size_t 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
 Returntrueif string is valid.
KStringInvalidate()
 Invalidate string.
size_t GetLen() const
 Get string length like "C" strlen().
bool IsEmpty() const
 Returntrueif 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 * Buffer()
 Non-const buffer access.
const char * Buffer() const
 const buffer access.

Assignment Operators

constKStringoperator=(constKString&pStr)
 KStringassignment operator.
constKStringoperator=(char pChar)
 Character assignment operator.
constKStringoperator=(const char *pStr)
 String assignment operator.
constKStringoperator=(int pValue)
 Int assignment operator.
constKStringoperator=(float pValue)
 Float assignment operator.
constKStringoperator=(double pValue)
 Double assignment operator.
constKStringCopy(size_t pLen, const char *pStr)
 String assignment function with maximum length.
void Swap(KString&pStr)
 Swap the contents of twoKStringobjects; no allocation is performed.

Append and Concatenation

constKStringAppend(const char *pStr)
 Append as "C" strcat().
constKStringAppendN(const char *pStr, size_t pLength)
 Append as "C" strncat().
constKStringoperator+=(constKString&pKStr)
 KStringappend.
constKStringoperator+=(char pChar)
 Character append.
constKStringoperator+=(const char *pStr)
 String append.
constKStringoperator+=(int pValue)
 Int append.
constKStringoperator+=(float pValue)
 Float append.
KFBX_DLLKString operator+(constKString&pKStr1, constKString&pKStr2)
 KStringconcatenation.
KFBX_DLLKString operator+(constKString&pKStr, char pChar)
 Character concatenation.
KFBX_DLLKString operator+(constKString&pKStr, const char *pStr)
 String concatenation.
KFBX_DLLKString operator+(constKString&pKStr, int pValue)
 Int concatenation.
KFBX_DLLKString operator+(constKString&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==(constKString&pStr) const
 Equality operator.
bool operator!=(constKString&pStr) const
 Inequality operator.
bool operator<(constKString&pStr) const
 Inferior to operator.
bool operator<=(constKString&pStr) const
 Inferior or equal to operator.
bool operator>=(constKString&pStr) const
 Superior or equal to operator.
bool operator>(constKString&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(size_t pFirst, size_t pCount) const
 Extract middle string for a given length.
KString Mid(size_t pFirst) const
 Extract middle string up to the end.
KString Left(size_t pCount) const
 Extract left string.
KString Right(size_t 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, size_t pStartPosition=0) const
 Look for a single character match, like "C" strchr().
int Find(const char *pStrSub, size_t 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, size_t pStartPosition=0) const
 Look for a single character match, like "C" strpbrk().
bool FindAndReplace(const char *pFind, const char *pReplaceBy, size_t pStartPosition=0)
 Replace a substring.
bool ReplaceAll(char pFind, char pReplaceBy)
 Replace a character.

Token Extraction

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

Member Enumeration Documentation

Padding types.

  • eRight
  • eLeft
  • eBoth

Definition at line453of filekstring.h.

Constructor&Destructor Documentation

KString( ) 

Default constructor.

KString(constKStringpStr ) 

Copy constructor.

Parameters:
pStr TheKStringbe copied.

KString(const char * pStr ) 

String constructor.

Parameters:
pStr The string used to constructKString.

KString(char pChar,
size_t pNbRepeat=1 
)

Character constructor.

Parameters:
pChar The character used to constructKString.
pNbRepeat The buffer size ofKString.

KString(const char * pCharPtr,
size_t pLength 
)

String constructor with maximum length.

Parameters:
pCharPtr The string used to constructKString.
pLength Maximum length.

KString(const int pValue ) 

Int constructor.

Parameters:
pValue The int value used to constructKString.

KString(const float pValue ) 

Float constructor.

Parameters:
pValue The float value used to constructKString.

KString(const double pValue ) 

Double constructor.

Parameters:
pValue The double value used to constructKString.

~KString( ) 

Destructor.

Member Function Documentation

staticKString* Create( ) [static]

Create an instance.

staticKString* Create(KStringpString ) [static]

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

Parameters:
pString KStringused to creat a newKString.

void Destroy( ) 

Destroy an allocated version of the string.

staticKString* DestroyIfEmpty(KStringpString ) [static]

Destroy the allocated space if empty.

Parameters:
pString KStringto be destroied if empty.

staticKString* StringOrEmpty(KStringpString ) [static]

Return the passed pString if it is not empty, or a local static emptyKStringwill be returned.

Parameters:
pString If pString is not empty, pString will be returned, or a local static empty string will be returned.

bool IsOK( ) const[inline]

Returntrueif string is valid.

Judge if this string is error.

Definition at line657of filekstring.h.

KString&Invalidate( ) 

Invalidate string.

size_t GetLen( ) const[inline]

Get string length like "C" strlen().

Get the length of this string.

Definition at line659of filekstring.h.

Referenced byIsEmpty(), andStripQuotationMarks().

bool IsEmpty( ) const[inline]

Returntrueif string is of length 0.

Judge if this string is empty.

Definition at line661of filekstring.h.

ReferencesGetLen().

KString&Empty( ) 

Discard the content of the object.

char&operator[](int pIndex ) 

Access by reference.

Parameters:
pIndex The index.
Returns:
The referance of the char at pIndex.

char operator[](int pIndex ) const

Access by copy.

Parameters:
pIndex The index.
Returns:
The char at pIndex.

operator const char *( ) const[inline]

Cast operator.

Get the content of string .

Definition at line668of filekstring.h.

char * Buffer( ) [inline]

Non-const buffer access.

Get the content of string.

Definition at line664of filekstring.h.

const char * Buffer( ) const[inline]

const buffer access.

Get the content of string.

Definition at line666of filekstring.h.

constKString&operator=(constKStringpStr ) 

KStringassignment operator.

Parameters:
pStr TheKStringto be assigned.

constKString&operator=(char pChar ) 

Character assignment operator.

Parameters:
pChar The character to be assigned.

constKString&operator=(const char * pStr ) 

String assignment operator.

Parameters:
pStr The string to be assigned.

constKString&operator=(int pValue ) 

Int assignment operator.

Parameters:
pValue The int value to be assigned.

constKString&operator=(float pValue ) 

Float assignment operator.

Parameters:
pValue The float value to be assigned.

constKString&operator=(double pValue ) 

Double assignment operator.

Parameters:
pValue The double value to be assigned.

constKString&Copy(size_t pLen,
const char * pStr 
)

String assignment function with maximum length.

Parameters:
pLen Maximum length.
pStr The string to be assigned.

void Swap(KStringpStr ) 

Swap the contents of twoKStringobjects; no allocation is performed.

Parameters:
pStr TheKStringto be swapped.

constKString&Append(const char * pStr ) 

Append as "C" strcat().

Parameters:
pStr The string to be appended.

constKString&AppendN(const char * pStr,
size_t pLength 
)

Append as "C" strncat().

Parameters:
pStr The string to be appended.
pLength The length of chars to be appended.

constKString&operator+=(constKStringpKStr ) 

KStringappend.

Parameters:
pKStr TheKStringto be appended.

constKString&operator+=(char pChar ) 

Character append.

Parameters:
pChar The character to be appended.

constKString&operator+=(const char * pStr ) 

String append.

Parameters:
pStr The string to be appended.

constKString&operator+=(int pValue ) 

Int append.

Parameters:
pValue The int value to be appended.

constKString&operator+=(float pValue ) 

Float append.

Parameters:
pValue The float value to be appended.

int Compare(const char * pStr ) const

Compare as "C" strcmp().

Parameters:
pStr The string to be compared.

int CompareNoCase(const char * pStr ) const

Compare as "C" stricmp().

Parameters:
pStr The string to be compared.

bool operator==(constKStringpStr ) const

Equality operator.

Parameters:
pStr TheKStringto be compared.

bool operator!=(constKStringpStr ) const

Inequality operator.

Parameters:
pStr TheKStringto be compared.

bool operator<(constKStringpStr ) const

Inferior to operator.

Parameters:
pStr TheKStringto be compared.

bool operator<=(constKStringpStr ) const

Inferior or equal to operator.

Parameters:
pStr TheKStringto be compared.

bool operator>=(constKStringpStr ) const

Superior or equal to operator.

Parameters:
pStr TheKStringto be compared.

bool operator>(constKStringpStr ) const

Superior to operator.

Parameters:
pStr TheKStringto be compared.

bool operator==(const char * pStr ) const

Equality operator.

Parameters:
pStr The string to be compared.

bool operator!=(const char * pStr ) const

Inequality operator.

Parameters:
pStr The string to be compared.

bool operator<(const char * pStr ) const

Inferior to operator.

Parameters:
pStr The string to be compared.

bool operator<=(const char * pStr ) const

Inferior or equal to operator.

Parameters:
pStr The string to be compared.

bool operator>=(const char * pStr ) const

Superior or equal to operator.

Parameters:
pStr The string to be compared.

bool operator>(const char * pStr ) const

Superior to operator.

Parameters:
pStr The string to be compared.

KStringMid(size_t pFirst,
size_t pCount 
)const

Extract middle string for a given length.

Parameters:
pFirst The start index ofKStringto be extracted.
pCount The length of sub-string to be extracted.

Referenced byRemoveChar(), andStripQuotationMarks().

KStringMid(size_t pFirst ) const

Extract middle string up to the end.

Parameters:
pFirst The start index ofKStringto be extracted.

KStringLeft(size_t pCount ) const

Extract left string.

Parameters:
pCount The length of sub-string to be extracted.

Referenced byRemoveChar().

KStringRight(size_t pCount ) const

Extract right string.

Parameters:
pCount The length of sub-string to be extracted.

KStringPad(PaddingType pPadding,
size_t pLen,
char pCar=' ' 
)const

Add padding characters.

Parameters:
pPadding The padding type.
pLen The length limit ofKStringafter padding.
pCar The character to be padded.

KStringUnPad(PaddingType pPadding ) const

Remove padding characters.

Parameters:
pPadding The padding type.

KStringUpper( ) const

Uppercase conversion.

KStringLower( ) const

Lowercase conversion.

KStringReverse( ) const

Reverse conversion.

KStringConvertToUnix( ) const

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

KStringConvertToWindows( ) const

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

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

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

Parameters:
pChar The character to look for.
pStartPosition Start position to look for.
Returns:
Index or -1 if not found.

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

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

Parameters:
pStrSub The substring to look for.
pStartPosition Start position to look for.
Returns:
Starting index or -1 if not found.

int ReverseFind(char pChar ) const

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

Parameters:
pChar The character to look for.
Returns:
Index or -1 if not found.

Referenced byRemoveChar().

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

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

Parameters:
pStrCharSet The character set.
pStartPosition The start position.
Returns:
Index or -1 if not found.

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

Replace a substring.

Parameters:
pFind The substring to look for.
pReplaceBy The string to replace by.
pStartPosition The start position.
Returns:
trueif substring found and replaced.

bool ReplaceAll(char pFind,
char pReplaceBy 
)

Replace a character.

Parameters:
pFind The character to look for.
pReplaceBy The character to replace by.
Returns:
trueif character found and replaced.

int GetTokenCount(const char * pSpans ) const

Get number of tokens.

Parameters:
pSpans The span
Returns:
The number of tokens.

KStringGetToken(int pTokenIndex,
const char * pSpans 
)const

Get token at given index.

Parameters:
pTokenIndex The token index.
pSpans The span

static KMemoryAllocator* AllocatorGet( ) [static]

Get new memory allocator.

static void AllocatorPurge( ) [static]

Purge memory allocator.

static void AllocatorRelease( ) [static]

Release memory allocator.

Friends And Related Function Documentation

KFBX_DLLKStringoperator+(constKStringpKStr1,
constKStringpKStr2 
)[friend]

KStringconcatenation.

Parameters:
pKStr1 The firstKStringto be concatenated.
pKStr2 The secondKStringto be concatenated.

KFBX_DLLKStringoperator+(constKStringpKStr,
char pChar 
)[friend]

Character concatenation.

Parameters:
pKStr TheKStringbe be concatenated.
pChar The character to be concatenated.

KFBX_DLLKStringoperator+(constKStringpKStr,
const char * pStr 
)[friend]

String concatenation.

Parameters:
pKStr TheKStringbe be concatenated.
pStr The string to be concatenated.

KFBX_DLLKStringoperator+(constKStringpKStr,
int pValue 
)[friend]

Int concatenation.

Parameters:
pKStr TheKStringbe be concatenated.
pValue The int value be be concatenated.

KFBX_DLLKStringoperator+(constKStringpKStr,
float pValue 
)[friend]

Float concatenation.

Parameters:
pKStr TheKStringbe be concatenated.
pValue The float value be be concatenated.