Robox Library for Cpp: tools module 1.0.0
RLibCpp utilities toolset
Classes | Public Member Functions | Protected Member Functions | List of all members
String Class Reference

Class for handling strings. More...

#include <string.h>

Classes

class  Vector
 Class to handle with lists of String. More...
 

Public Member Functions

 String ()
 Default constructor.
 
 String (const String &src)
 Copy constructor.
 
 String (const char *src)
 Constructor from null termineted char array.
 
 String (char src)
 Constructor from a character.
 
virtual ~String ()
 Virtual destructor.
 
Stringoperator= (const String &src)
 Assigment operator overload.
 
bool operator== (const String &src) const
 Comparison operator overload.
 
bool operator== (const char *src) const
 Comparison operator.
 
bool operator!= (const String &src) const
 Comparison operator overload.
 
bool operator!= (const char *src) const
 Comparison operator.
 
String operator+ (const String &other) const
 Concatenation operator overload.
 
String append (const char other)
 Appends the charcter to the string.
 
String append (const String &other)
 Appends the string other to the string.
 
bool operator< (const String &src) const
 Check if lesser than the specifed string.
 
bool operator<= (const String &src) const
 Check if lesser or equal than the specifed string.
 
bool operator> (const String &src) const
 Check if greater than the specifed string.
 
bool operator>= (const String &src) const
 Check if greater or equal than the specifed string.
 
String subString (size_t pos=0, size_t len=SIZE_MAX) const
 Returns a newly constructed string object with its value initialized to a copy of a substring of this object. The substring is the portion of the object that starts at character position pos and spans len characters(or until the end of the string, whichever comes first).
 
bool endsWith (const String &src, bool caseSensitive=true) const
 Test if the string ends with the src string.
 
bool startsWith (const String &src, bool caseSensitive=true) const
 Test if the string starts with the src string.
 
String toLower () const
 Get a copy of the string converted to lower case.
 
String toUpper () const
 Get a copy of the string converted to upper case.
 
const char * value () const
 Get the string zero terminated content.
 
void setValue (const char *value)
 Set the string cpntent.
 
size_t length () const
 The number of characters in the string.
 
 operator const char * () const
 Get the string zero terminated content.
 
size_t rawDataSize () const
 The string raw data size in bytes.
 
int indexOf (char val, size_t startPos=0, bool caseSensitive=true) const
 Returns the index of the first occurency of the specified character ( val )
 
int indexOf (const String &val, size_t startPos=0, bool caseSensitive=true) const
 Returns the index of the first occurency of the specified string ( val )
 
int lastIndexOf (char val, size_t startPos=0, bool caseSensitive=true) const
 Returns the last index of the first occurency of the specified character ( val )
 
int lastIndexOf (const String &val, size_t startPos=0, bool caseSensitive=true) const
 Returns the last index of the first occurency of the specified string ( val )
 
void replace (const String &oldValue, const String &newValue, bool caseSensitive=true)
 Replaces all the occurency of oldValue with newValue
 
void replace (char oldValue, char newValue, bool caseSensitive=true)
 Replaces all the occurency of oldValue with newValue
 
bool isEmpty () const
 Test if the string is empty.
 
Vector split (char sep, bool keepEmpty=true, bool caseSensitive=true) const
 Splits the string by the specified character into a Vector of String.
 
Vector split (const String &sep, bool keepEmpty=true, bool caseSensitive=true) const
 Splits the string by the specified string into a Vector of String.
 
String trimmedLeft () const
 Returns a copy of the string that has whitespace removed from the start.
 
String trimmedRight () const
 Returns a copy of the string that has whitespace removed from the end.
 
String trimmed () const
 Returns a copy of the string that has whitespace removed from the start and the end.
 
Stringsprintf (const String cformat,...)
 Builds a formatted string from the format string cformat and an arbitrary list of arguments.
 
String at (size_t pos) const
 Get a reference to the character at position pos in the string.
 

Protected Member Functions

void init ()
 Class initialization.
 

Detailed Description

Class for handling strings.

Constructor & Destructor Documentation

◆ String() [1/4]

String ( )

Default constructor.

◆ String() [2/4]

String ( const String & src)

Copy constructor.

Parameters
srcThe source object

◆ String() [3/4]

String ( const char * src)

Constructor from null termineted char array.

Parameters
srcThe source char array

◆ String() [4/4]

String ( char src)

Constructor from a character.

Parameters
srcThe source char

◆ ~String()

virtual ~String ( )
virtual

Virtual destructor.

Member Function Documentation

◆ append() [1/2]

String append ( const char other)

Appends the charcter to the string.

Parameters
otherThe character to add
Returns
The resulting string as concatenation of this and the character

◆ append() [2/2]

String append ( const String & other)

Appends the string other to the string.

Parameters
otherThe string to add
Returns
The resulting string as concatenation of this and the other

◆ at()

String at ( size_t pos) const

Get a reference to the character at position pos in the string.

Parameters
posValue with the position of a character within the string.
Returns
A reference to the character at position pos in the string

If pos is equal to the string length, the function returns a reference to the null character that follows the last character in the string (which should not be modified)

◆ endsWith()

bool endsWith ( const String & src,
bool caseSensitive = true ) const

Test if the string ends with the src string.

Parameters
srcThe string to compare with
caseSensitiveIf setted the comparisono is case sensitive
Returns
The poperation logical result

◆ indexOf() [1/2]

int indexOf ( char val,
size_t startPos = 0,
bool caseSensitive = true ) const

Returns the index of the first occurency of the specified character ( val )

Parameters
valThe character to search
startPosThe starting search position
caseSensitiveIf setted the search is case sensitive
Returns
The index of the first occurency of the specified character or -1 if not found

◆ indexOf() [2/2]

int indexOf ( const String & val,
size_t startPos = 0,
bool caseSensitive = true ) const

Returns the index of the first occurency of the specified string ( val )

Parameters
valThe string to search
startPosThe starting search position
caseSensitiveIf setted the search is case sensitive
Returns
The index of the first occurency of the specified string or -1 if not found

◆ init()

void init ( )
protected

Class initialization.

◆ isEmpty()

bool isEmpty ( ) const

Test if the string is empty.

Returns
The poperation logical result

◆ lastIndexOf() [1/2]

int lastIndexOf ( char val,
size_t startPos = 0,
bool caseSensitive = true ) const

Returns the last index of the first occurency of the specified character ( val )

Parameters
valThe character to search
startPosThe starting search position
caseSensitiveIf setted the search is case sensitive
Returns
The index of the first occurency of the specified character or -1 if not found

◆ lastIndexOf() [2/2]

int lastIndexOf ( const String & val,
size_t startPos = 0,
bool caseSensitive = true ) const

Returns the last index of the first occurency of the specified string ( val )

Parameters
valThe string to search
startPosThe starting search position
caseSensitiveIf setted the search is case sensitive
Returns
The index of the first occurency of the specified string or -1 if not found

◆ length()

size_t length ( ) const

The number of characters in the string.

Returns
The number of characters in the string (terminator excluded)

◆ operator const char *()

operator const char * ( ) const

Get the string zero terminated content.

Returns
Pointer to the zero terminated string content

◆ operator!=() [1/2]

bool operator!= ( const char * src) const

Comparison operator.

Parameters
srcThe source object
Returns
true if objects' content is different

◆ operator!=() [2/2]

bool operator!= ( const String & src) const

Comparison operator overload.

Parameters
srcThe source object
Returns
true if objects' content is different

◆ operator+()

String operator+ ( const String & other) const

Concatenation operator overload.

Parameters
otherThe ohter object to add
Returns
The resulting string as concatenation of this and other

◆ operator<()

bool operator< ( const String & src) const

Check if lesser than the specifed string.

Parameters
srcThe source object
Returns
The operation logical result

◆ operator<=()

bool operator<= ( const String & src) const

Check if lesser or equal than the specifed string.

Parameters
srcThe source object
Returns
The operation logical result

◆ operator=()

String & operator= ( const String & src)

Assigment operator overload.

Parameters
srcThe source object
Returns
A reference to this object

◆ operator==() [1/2]

bool operator== ( const char * src) const

Comparison operator.

Parameters
srcThe source object
Returns
true if objects' content is equal

◆ operator==() [2/2]

bool operator== ( const String & src) const

Comparison operator overload.

Parameters
srcThe source object
Returns
true if objects' content is equal

◆ operator>()

bool operator> ( const String & src) const

Check if greater than the specifed string.

Parameters
srcThe source object
Returns
The operation logical result

◆ operator>=()

bool operator>= ( const String & src) const

Check if greater or equal than the specifed string.

Parameters
srcThe source object
Returns
The operation logical result

◆ rawDataSize()

size_t rawDataSize ( ) const

The string raw data size in bytes.

Returns
The string raw data size in bytes (terminator excluded)

◆ replace() [1/2]

void replace ( char oldValue,
char newValue,
bool caseSensitive = true )

Replaces all the occurency of oldValue with newValue

Parameters
oldValueThe value to be substituted
newValueThe new value
caseSensitiveIf setted the search is case sensitive

◆ replace() [2/2]

void replace ( const String & oldValue,
const String & newValue,
bool caseSensitive = true )

Replaces all the occurency of oldValue with newValue

Parameters
oldValueThe value to be substituted
newValueThe new value
caseSensitiveIf setted the search is case sensitive

◆ setValue()

void setValue ( const char * value)

Set the string cpntent.

Parameters
valuePointer to the zero terminated string content

◆ split() [1/2]

Vector split ( char sep,
bool keepEmpty = true,
bool caseSensitive = true ) const

Splits the string by the specified character into a Vector of String.

Parameters
sepThe separator character
keepEmptyIf setted the emmpty token strings will be inserted into the return Vector
caseSensitiveIf setted the separator search is case sensitive
Returns
The Vector of String

◆ split() [2/2]

Vector split ( const String & sep,
bool keepEmpty = true,
bool caseSensitive = true ) const

Splits the string by the specified string into a Vector of String.

Parameters
sepThe separator string
keepEmptyIf setted the emmpty token strings will be inserted into the return Vector
caseSensitiveIf setted the separator search is case sensitive
Returns
The Vector of String

◆ sprintf()

String & sprintf ( const String cformat,
... )

Builds a formatted string from the format string cformat and an arbitrary list of arguments.

Parameters
cformatThe format string
Returns
A reference to this formatted string.

◆ startsWith()

bool startsWith ( const String & src,
bool caseSensitive = true ) const

Test if the string starts with the src string.

Parameters
srcThe string to compare with
caseSensitiveIf setted the comparisono is case sensitive
Returns
The poperation logical result

◆ subString()

String subString ( size_t pos = 0,
size_t len = SIZE_MAX ) const

Returns a newly constructed string object with its value initialized to a copy of a substring of this object. The substring is the portion of the object that starts at character position pos and spans len characters(or until the end of the string, whichever comes first).

Parameters
posPosition of the first character to be copied as a substring
lenNumber of characters to include in the substring (if the string is shorter, as many characters as possible are used).
Returns
A string object with a substring of this object

◆ toLower()

String toLower ( ) const

Get a copy of the string converted to lower case.

Returns
A copy of the string converted to lower case

This method doesn't affect this object

◆ toUpper()

String toUpper ( ) const

Get a copy of the string converted to upper case.

Returns
A copy of the string converted to upper case

This method doesn't affect this object

◆ trimmed()

String trimmed ( ) const

Returns a copy of the string that has whitespace removed from the start and the end.

Returns
A string object that has whitespace removed from the start and the end.

This method doesn't affect this object

◆ trimmedLeft()

String trimmedLeft ( ) const

Returns a copy of the string that has whitespace removed from the start.

Returns
A string object that has whitespace removed from the start.

This method doesn't affect this object

◆ trimmedRight()

String trimmedRight ( ) const

Returns a copy of the string that has whitespace removed from the end.

Returns
A string object that has whitespace removed from the end.

This method doesn't affect this object

◆ value()

const char * value ( ) const

Get the string zero terminated content.

Returns
Pointer to the zero terminated string content