C String. More...

#include <rcstring.h>

Inheritance diagram for RCString:
[legend]
Collaboration diagram for RCString:
[legend]

Public Member Functions

 RCString (void)
 
 RCString (const char *src)
 
 RCString (const char *src, size_t len)
 
 RCString (const std::string &src)
 
 RCString (char car)
 
 RCString (const RCString &src)
 
Internal methods
void Copy (const char *text, size_t nb)
 
size_t GetLen (void) const
 
size_t GetMaxLen (void) const
 
void SetLen (size_t len)
 
void SetLen (size_t len, const RCString &str)
 
bool IsEmpty (void) const
 
bool ContainOnlySpaces (void) const
 
Manipulation methods
void Clear (void)
 
RCString ToUpper (void) const
 
RCString ToLower (void) const
 
RCString Trim (void) const
 
RCString Trim (const RCString &str) const
 
int Find (const char car, int pos=0, bool CaseSensitive=true) const
 
int FindStr (const RCString &str, int pos=0, bool CaseSensitive=true) const
 
int FindAnyStr (const RCString &str, int pos=0, bool CaseSensitive=true) const
 
void Replace (const char search, const char rep, bool first=false, int pos=0)
 
void ReplaceStr (const RCString &search, const RCString &rep, bool first=false, int pos=0)
 
bool Begins (const RCString &begin, bool skip=false) const
 
bool Ends (const RCString &end, bool skip=false) const
 
RCString Mid (size_t idx, size_t len=(size_t)-1) const
 
bool IsAt (const RCString &sub, int pos) const
 
void Insert (const RCString &sub, int pos, size_t del=0)
 
void Split (iRContainer< RCString > &elements, const char car, const char del=0) const
 
void GuessWords (iRContainer< RCString > &elements, bool hyphen) const
 
void Concat (const iRContainer< RCString > &elements, const char car=0)
 
Methods related to containers
int Compare (const RCString &src) const
 
int Compare (const char *src) const
 
size_t HashCode (size_t max) const
 
Operators
const char * operator() (void) const
 
 operator const char * (void) const
 
 operator std::string () const
 
const char & operator[] (size_t idx) const
 
char & operator[] (size_t idx)
 
bool operator== (const RCString &src) const
 
bool operator== (const char *src) const
 
bool operator!= (const RCString &src) const
 
bool operator!= (const char *src) const
 
RCStringoperator= (const RCString &src)
 
RCStringoperator= (const char *src)
 
RCStringoperator= (const std::string &src)
 
RCStringoperator+= (const RCString &src)
 
RCStringoperator+= (const char *src)
 
RCStringoperator+= (const char src)
 
- Public Member Functions inherited from BasicString< char, RCString >
void Copy (const char *text, size_t nb)
 
RCStringoperator= (const RCString &src)
 
RCStringoperator= (const char *src)
 
size_t GetLen (void) const
 
size_t GetMaxLen (void) const
 
void SetLen (size_t len)
 
void SetLen (size_t len, const RCString &str)
 
bool IsEmpty (void) const
 
void Clear (void)
 
RCString ToUpper (void) const
 
RCString ToLower (void) const
 
RCString Trim (void) const
 
RCString Trim (const RCString &str) const
 
bool ContainOnlySpaces (void) const
 
RCStringoperator+= (const RCString &src)
 
RCStringoperator+= (const char *src)
 
int Find (const charcar, int pos=0, bool CaseSensitive=true) const
 
int FindStr (const RCString &str, int pos=0, bool CaseSensitive=true) const
 
int FindAnyStr (const RCString &str, int pos=0, bool CaseSensitive=true) const
 
void Replace (const charsearch, const charrep, bool first=false, int pos=0)
 
void ReplaceStr (const RCString &search, const RCString &rep, bool first=false, int pos=0)
 
const char & operator[] (size_t idx) const
 
char & operator[] (size_t idx)
 
bool Begins (const RCString &begin, bool skip=false) const
 
bool Ends (const RCString &end, bool skip=false) const
 
RCString Mid (size_t idx, size_t len=(size_t)-1) const
 
bool IsAt (const RCString &sub, int pos) const
 
void Insert (const RCString &sub, int pos, size_t del=0)
 
void Split (iRContainer< RCString > &elements, const charcar, const chardel) const
 
void GuessWords (iRContainer< RCString > &elements, bool hyphen) const
 
void Concat (const iRContainer< RCString > &elements, const charcar)
 
size_t HashIndex (size_t idx) const
 
 ~BasicString (void)
 

Static Public Attributes

static const RCString Null
 

Additional Inherited Members

- Protected Member Functions inherited from BasicString< char, RCString >
 BasicString (void)
 
 BasicString (const BasicString &str)
 
 BasicString (const charcar)
 
 BasicString (const char *src)
 
 BasicString (const char *src, size_t len)
 
void Copy (void)
 
- Static Protected Member Functions inherited from BasicString< char, RCString >
static CharBuffer * GetDataNull (void)
 
- Protected Attributes inherited from BasicString< char, RCString >
CharBuffer * Data
 
- Static Protected Attributes inherited from BasicString< char, RCString >
static CharBuffer * DataNull
 

Detailed Description

C String.

This class implements a C string (char*) as a class. The class uses a shared approach. For example in the following code:

RString str1("Hello Wold");
RString str2;
str2=str1;

The strings str1 and str2 use (as long as none of them is modified) the same copy of the characters string.

Constructor & Destructor Documentation

RCString ( void  )

Construct a empty string.

RCString ( const char *  src)

Construct a string from a C-style string.

Parameters
srcC-style string used as reference.
RCString ( const char *  src,
size_t  len 
)

Construct a string by doing a deep copy of the first characters of a C-style string.

Parameters
srcC string used as reference.
lenLength.
RCString ( const std::string &  src)

Construct a string from a C-style string.

Parameters
srcC-style string used as reference.
RCString ( char  car)
explicit

Construct a string from a character.

Parameters
carCharacter.
RCString ( const RCString src)

Construct a string from another string.

Parameters
srcString used as reference.

Member Function Documentation

void Copy ( const char *  text,
size_t  nb 
)

Copy a certain number of characters in the string.

Parameters
textText to copy.
nbNumber of characters to copy.
size_t GetLen ( void  ) const
size_t GetMaxLen ( void  ) const
void SetLen ( size_t  len)

Set the length of the string. If the length is shorter that the current one, the string is truncated. If the length is greater than the current one, the internal buffer is updated. Any new space allocated contains arbitrary data.

Parameters
lenLength of the string.
void SetLen ( size_t  len,
const RCString str 
)

Set the length of the string. If the length is shorter that the current one, the string is truncated. If the length is greater than the current one, the second string is used to fill the first string (eventually it is copied several times).

Parameters
lenLength of the string.
strString used to fill.
bool IsEmpty ( void  ) const
bool ContainOnlySpaces ( void  ) const
void Clear ( void  )

Clear the content of the string.

RCString ToUpper ( void  ) const

Get a uppercase version of the string.

Returns
String.
RCString ToLower ( void  ) const

Get a lowercase version of the string.

Returns
String.
RCString Trim ( void  ) const

This function return a string by stripping whitespace (or other characters) from the beginning and end of the string.

Returns
String.
RCString Trim ( const RCString str) const

This function return a string by stripping a given sub-string from the beginning and end of the string.

Parameters
strSub-string to strip.
Returns
String.
int Find ( const char  car,
int  pos = 0,
bool  CaseSensitive = true 
) const

Find the position of a given character in the string.

Parameters
carCharacter to find.
posPosition to start the search. Negative values start the search from the end.
CaseSensitiveIs the search case sensitive.
Returns
The position of the first occurrence or -1 if the character was not found.
int FindStr ( const RCString str,
int  pos = 0,
bool  CaseSensitive = true 
) const

Find the position of a given string in the string.

Parameters
strString to find.
posPosition to start the search. Negative values start the search from the end.
CaseSensitiveIs the search case sensitive.
Returns
The position of the first occurrence or -1 if the character was not found.
int FindAnyStr ( const RCString str,
int  pos = 0,
bool  CaseSensitive = true 
) const

Find the position of a character of a given set in the string.

Parameters
strString to find.
posPosition to start the search. Negative values start the search from the end.
CaseSensitiveIs the search case sensitive.
Returns
The position of the first occurrence or -1 if the character was not found.
void Replace ( const char  search,
const char  rep,
bool  first = false,
int  pos = 0 
)

Replace a given character in the string.

Parameters
searchCharacter to search.
repCharacter that will put in.
firstMust it stops after the first occurrence.
posPosition to start. Negative values start the search from the end.
void ReplaceStr ( const RCString search,
const RCString rep,
bool  first = false,
int  pos = 0 
)

Replace a given sub-string in the string.

Parameters
searchString to search.
repString that will put in.
firstMust it stops after the first occurrence.
posPosition to start. Negative values start the search from the end.
bool Begins ( const RCString begin,
bool  skip = false 
) const

Look if a string begins with a given sub-string.

Parameters
beginSub-string to search for.
skipIf true, leading spaces are skipped for the comparison.
Returns
true if the string begins with the sub-string.
bool Ends ( const RCString end,
bool  skip = false 
) const

Look if a string ends with a given sub-string.

Parameters
endSub-string to search for.
skipIf true, ending spaces are skipped for the comparison.
Returns
true if the string ends with the sub-string.
RCString Mid ( size_t  idx,
size_t  len = (size_t)-1 
) const

Get a sub-string of a given string.

Parameters
idxIndex of the first character.
lenLength of the sub-string. If the length is not specified, the end of the string is copied.
Returns
A string containing the substring.
bool IsAt ( const RCString sub,
int  pos 
) const

Verify if a given sub-string is at a given position.

Parameters
subSub-string.
posPosition. If negative, the sub-string is searched at a given position of the end.
Returns
true if the string at a given position.
void Insert ( const RCString sub,
int  pos,
size_t  del = 0 
)

Insert a sub-string at a given position of the string.

Parameters
subSub-string to insert.
posPosition. If negative, the sub-string is searched at a given position of the end.
delNumber of characters that will be replaced by the sub-string. If del=(size_t)-1, all the characters after pos are deleted.
void Split ( iRContainer< RCString > &  elements,
const char  car,
const char  del = 0 
) const

Split the string to find all the elements separated by a given character.

Parameters
elementsContainer that will hold the results. It is not emptied by the method.
carCharacter used as separator.
delDelimiter of an element.
void GuessWords ( iRContainer< RCString > &  elements,
bool  hyphen 
) const

Try to guess the different words in a given string. In practice, it supposes that certain characters separates words (spaces, ponctuations, uppercase, etc.).

Parameters
elementsContainer that will hold the results. It is not emptied by the method.
hyphenShould a hyphen be considered as a separator?
void Concat ( const iRContainer< RCString > &  elements,
const char  car = 0 
)

Concatenate a series of elements and, eventually, separated them by a given character.

Parameters
elementsContainer of elements to concatenate.
carCharacter used as separator.
int Compare ( const RCString src) const

Lexically compares two strings and returns an integer less than, equal to, or greater than zero if this is less than, equal to, or greater than src.

Parameters
srcString to compare with.
See also
R::RContainer.
int Compare ( const char *  src) const

Lexically compares two strings and returns an integer less than, equal to, or greater than zero if this is less than, equal to, or greater than src.

Parameters
srcString to compare with.
See also
R::RContainer.
size_t HashCode ( size_t  max) const

Compute a hash code that in the range [0,max-1]. In practice, in computes a sum based on the Unicode values the characters.

This method is R::RHashContainer to manage string.

Parameters
maxMaximal value.
Returns
a number in the range [0,max-1].
const char* operator() ( void  ) const

Return the string. The resulting array should be copied (and not destroyed) since it is an internal structure.

operator const char * ( void  ) const

Return the string. The resulting array should be copied (and not destroyed) since it is an internal structure.

operator std::string ( ) const

Get a normal C++ string representing the current string.

Returns
std::string.
const char& operator[] ( size_t  idx) const
char& operator[] ( size_t  idx)
bool operator== ( const RCString src) const

Equal operator.

Parameters
srcString to compare with.
bool operator== ( const char *  src) const

Equal operator.

Parameters
srcString to compare with.
bool operator!= ( const RCString src) const

Non-equal operator.

Parameters
srcString to compare with.
bool operator!= ( const char *  src) const

Non-equal operator.

Parameters
srcString to compare with.
RCString& operator= ( const RCString src)

Assignment operator using another string.

Parameters
srcSource string.
RCString& operator= ( const char *  src)

Assignment operator using another string.

Parameters
srcSource string.
RCString& operator= ( const std::string &  src)

Assignment operator using a string.

Parameters
srcSource string.
RCString& operator+= ( const RCString src)

Add another string.

Parameters
srcSource string.
RCString& operator+= ( const char *  src)

Add another string.

Parameters
srcSource string.
RCString& operator+= ( const char  src)

Add a character to the string.

Parameters
srcCharacter.

Field Documentation

const RCString Null
static

Null string.