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)
 Destroy the allocated space if empty.
void Destroy()
 Destroy an allocated version of the string.

Memory Pool Management

static KMemoryAllocator * AllocatorGet()
static void AllocatorPurge()
static void AllocatorRelease()

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.
void Swap(KString&)
 KStringassignment operator.

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.
KBASELIB_DLLKString operator+(constKString&pKStr1, constKString&pKStr2)
 KStringconcatenation.
KBASELIB_DLLKString operator+(constKString&pKStr, char pChar)
 Character concatenation.
KBASELIB_DLLKString operator+(constKString&pKStr, const char *pStr)
 String concatenation.
KBASELIB_DLLKString operator+(constKString&pKStr, int pValue)
 Int concatenation.
KBASELIB_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 line341of filekstring.h.

Constructor&Destructor Documentation

KString( ) 

Default constructor.

KString(constKStringpStr ) 

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.

Member Function Documentation

staticKString* Create( ) [static]

Create an instance.

staticKString* Create(KStringpString ) [static]

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

void Destroy( ) 

Destroy an allocated version of the string.

staticKString* DestroyIfEmpty(KStringpString ) [static]

Destroy the allocated space if empty.

staticKString* StringOrEmpty(KStringpString ) [static]

Destroy the allocated space if empty.

bool IsOK( ) const[inline]

Returntrueif string is valid.

Definition at line508of filekstring.h.

KString&Invalidate( ) 

Invalidate string.

size_t GetLen( ) const[inline]

Get string length like "C" strlen().

Definition at line509of filekstring.h.

Referenced byIsEmpty().

bool IsEmpty( ) const[inline]

Returntrueif string is of length 0.

Definition at line510of filekstring.h.

ReferencesGetLen().

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[inline]

Cast operator.

Definition at line514of filekstring.h.

char * Buffer( ) [inline]

Non-const buffer access.

Definition at line512of filekstring.h.

const char * Buffer( ) const[inline]

const buffer access.

Definition at line513of filekstring.h.

constKString&operator=(constKStringpStr ) 

KStringassignment operator.

constKString&operator=(char pChar ) 

Character assignment operator.

constKString&operator=(const char * pStr ) 

String assignment operator.

constKString&operator=(int pValue ) 

Int assignment operator.

constKString&operator=(float pValue ) 

Float assignment operator.

constKString&operator=(double pValue ) 

Double assignment operator.

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

String assignment function.

void Swap(KString ) 

KStringassignment operator.

constKString&Append(const char * pStr ) 

Append as "C" strcat().

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

Append as "C" strncat().

constKString&operator+=(constKStringpKStr ) 

KStringappend.

constKString&operator+=(char pChar ) 

Character append.

constKString&operator+=(const char * pStr ) 

String append.

constKString&operator+=(int pValue ) 

Int append.

constKString&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==(constKStringpStr ) const

Equality operator.

bool operator!=(constKStringpStr ) const

Inequality operator.

bool operator<(constKStringpStr ) const

Inferior to operator.

bool operator<=(constKStringpStr ) const

Inferior or equal to operator.

bool operator>=(constKStringpStr ) const

Superior or equal to operator.

bool operator>(constKStringpStr ) 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.

KStringMid(size_t pFirst,
size_t pCount 
)const

Extract middle string for a given length.

KStringMid(size_t pFirst ) const

Extract middle string up to the end.

KStringLeft(size_t pCount ) const

Extract left string.

KStringRight(size_t pCount ) const

Extract right string.

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

Add padding characters.

KStringUnPad(PaddingType pPadding ) const

Remove padding characters.

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().

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().

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.

int FindOneOf(const char * pStrCharSet,
size_t 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,
size_t pStartPosition=0 
)

Replace a substring.

Returns:
trueif substring found and replaced.

bool ReplaceAll(char pFind,
char pReplaceBy 
)

Replace a character.

Returns:
trueif character found and replaced.

int GetTokenCount(const char * pSpans ) const

Get number of tokens.

KStringGetToken(int pTokenIndex,
const char * pSpans 
)const

Get token at given index.

Friends And Related Function Documentation

KBASELIB_DLLKStringoperator+(constKStringpKStr1,
constKStringpKStr2 
)[friend]

KStringconcatenation.

KBASELIB_DLLKStringoperator+(constKStringpKStr,
char pChar 
)[friend]

Character concatenation.

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

String concatenation.

KBASELIB_DLLKStringoperator+(constKStringpKStr,
int pValue 
)[friend]

Int concatenation.

KBASELIB_DLLKStringoperator+(constKStringpKStr,
float pValue 
)[friend]

Float concatenation.