Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::String Class Reference

#include <elm/string/String.h>

Public Member Functions

 String (void)
 
 String (const char *str, int _len)
 
 String (const char *str)
 
 String (cstring str)
 
 String (const String &str)
 
 ~String (void)
 
Stringoperator= (const String &str)
 
Stringoperator= (const CString str)
 
Stringoperator= (const char *str)
 
int length (void) const
 
const char * chars (void) const
 
int compare (const String &str) const
 
int compare (const CString str) const
 
bool isEmpty (void) const
 
 operator bool (void) const
 
CString toCString (void) const
 
const char * operator& (void) const
 
char charAt (int index) const
 
char operator[] (int index) const
 
String substring (int _off) const
 
String substring (int _off, int _len) const
 
String concat (const CString str) const
 
String concat (const String &str) const
 
int indexOf (char chr) const
 
int indexOf (char chr, int pos) const
 
int indexOf (const String &str, int pos=0)
 
int lastIndexOf (char chr) const
 
int lastIndexOf (char chr, int pos) const
 
int lastIndexOf (const String &str)
 
int lastIndexOf (const String &str, int pos)
 
bool startsWith (const char *str) const
 
bool startsWith (const CString str) const
 
bool startsWith (const String &str) const
 
bool endsWith (const char *str) const
 
bool endsWith (const CString str) const
 
bool endsWith (const String &str) const
 
String trim (void) const
 
String ltrim (void) const
 
String rtrim (void) const
 

Detailed Description

An immutable implementation of the string data type. Refer to StringBuffer for long concatenation string building.

Warning
This string class is bound to strings of less than 65535 characters.

Constructor & Destructor Documentation

elm::String::String ( void  )

Build an empty string.

Referenced by substring().

elm::String::String ( const char *  str,
int  _len 
)

Build a string from a character array.

Parameters
strCharacter array base.
_lenCharacter array length.
elm::String::String ( const char *  str)

Build an ELM string from a C string.

Parameters
strC string.
elm::String::String ( cstring  str)

Build a string from a CString.

Parameters
strCString object to use.

References elm::CString::chars(), and elm::CString::length().

elm::String::String ( const String str)

Clone an existing string.

Parameters
strString to clone.
elm::String::~String ( void  )

Member Function Documentation

char elm::String::charAt ( int  index) const

Get a character at some position in the string.

Parameters
indexIndex of the character to get (It is an error to give a negative index or an index greater or equal to the string length).
Returns
Matching character.

Referenced by ltrim(), operator[](), and rtrim().

const char * elm::String::chars ( void  ) const

Get access to internal representation of the string. Use it with caution and recall that the got buffer may be shared by many different strings.

Returns
Raw access to character buffer.

Referenced by compare(), elm::CString::concat(), concat(), elm::CString::endsWith(), endsWith(), elm::HashKey< String >::hash(), indexOf(), lastIndexOf(), elm::io::Output::print(), elm::sys::ProcessBuilder::run(), elm::CString::startsWith(), startsWith(), toCString(), and elm::option::ValueOption< T >::ValueOption().

int elm::String::compare ( const String str) const

Compare two strings with ASCII order.

Parameters
strString to compare with.
Returns
0 for equality, <0 if the current string is less than given one, >0 if the current string is greater than given one.

References chars().

Referenced by elm::operator!=(), elm::operator<(), elm::operator<=(), elm::operator==(), elm::operator>(), and elm::operator>=().

int elm::String::compare ( const CString  str) const

Compare this string with a CString object using ASCII order.

Parameters
strString to compare with.
Returns
0 for equality, <0 if the current string is less than given one, >0 if the current string is greater than given one.

References elm::CString::chars(), chars(), and elm::CString::length().

String elm::String::concat ( const CString  str) const

Concatenate a string with a C string.

Parameters
strC string to concatenate after.
Returns
Result of concatenation.

References elm::CString::chars(), chars(), concat(), and elm::CString::length().

Referenced by concat().

String elm::String::concat ( const String str) const

Concatenate two strings.

Parameters
strString to concatenate after.
Returns
Result of concatenation.

References chars(), concat(), and length().

Referenced by concat().

bool elm::String::endsWith ( const char *  str) const

Test if the string ends with the given C string.

Parameters
strC string to compare.
Returns
True if the string ends with, false else.

References CString.

bool elm::String::endsWith ( const CString  str) const

Test if the string ends with the given string.

Parameters
strString to compare.
Returns
True if the string ends with, false else.

References elm::CString::chars(), chars(), and elm::CString::length().

bool elm::String::endsWith ( const String str) const

Test if the string ends with the given string.

Parameters
strString to compare.
Returns
True if the string ends with, false else.

References chars().

int elm::String::indexOf ( char  chr) const

Get the first index of a character in the string.

Parameters
chrCharacter to look for.
indexIndex of the character in the string or -1 if not found.

References indexOf().

Referenced by elm::ini::Section::getList(), indexOf(), elm::ini::File::load(), elm::Version::operator=(), elm::option::Manager::parse(), and elm::sys::Plugger::Plugger().

int elm::String::indexOf ( char  chr,
int  pos 
) const

Get the first index of a character in the string from the given position.

Parameters
chrCharacter to look for.
posPosition to start to look for (it is an error to pass a negative position or a position greater or equal to the string length).
indexIndex of the character in the string or -1 if not found.

References chars().

int elm::String::indexOf ( const String string,
int  pos = 0 
)

Find the first occurence of a substring.

Parameters
stringString to look for.
posStart position.

References indexOf(), length(), and substring().

bool elm::String::isEmpty ( void  ) const

Test if string is empty.

Returns
True if the string is empty, false else.

Referenced by operator bool().

int elm::String::lastIndexOf ( char  chr) const

Get the last index of a character in the string.

Parameters
chrCharacter to look for.
indexIndex of the character in the string or -1 if not found.

References lastIndexOf(), and length().

Referenced by elm::sys::Path::basePart(), elm::sys::Path::extension(), lastIndexOf(), and elm::sys::Path::setExtension().

int elm::String::lastIndexOf ( char  chr,
int  pos 
) const

Get the last index of a character in the string from the given position.

Parameters
chrCharacter to look for.
posPosition to start to look for (it is an error to pass a negative or null position or a position greater to the string length).
indexIndex of the character in the string or -1 if not found.

References chars().

int elm::String::lastIndexOf ( const String str)

References lastIndexOf(), and length().

Referenced by lastIndexOf().

int elm::String::lastIndexOf ( const String string,
int  pos 
)

Find the last occurence of a substring.

Parameters
stringString to look for.
posPosition to start to look before.

References lastIndexOf(), length(), and substring().

string elm::String::ltrim ( void  ) const

Remove blanks at left of the current string.

Returns
Left-trimmed string.

References charAt(), length(), and substring().

Referenced by trim().

elm::String::operator bool ( void  ) const

Same as isEmpty().

References isEmpty().

const char * elm::String::operator& ( void  ) const

Convert to C string.

Returns
Matching C string.

References elm::CString::chars(), and toCString().

String & elm::String::operator= ( const String str)

Assign a string to the current one.

Parameters
strString to assign.
Returns
Current string.
String & elm::String::operator= ( const CString  str)

Assign a CString object to the current string.

Parameters
strCString object to assign.
Returns
Current string.

References elm::CString::chars(), and elm::CString::length().

String & elm::String::operator= ( const char *  str)

Assign a C string to the current string.

Parameters
strC string to assign.
Returns
Current string.
char elm::String::operator[] ( int  index) const

Same as charAt().

References charAt().

string elm::String::rtrim ( void  ) const

Remove blanks at right of the current string.

Returns
Right-trimmed string.

References charAt(), length(), and substring().

Referenced by trim().

bool elm::String::startsWith ( const char *  str) const

Test if the string starts with the given C string.

Parameters
strC string to compare.
Returns
True if the string starts with, false else.

References CString.

Referenced by elm::sys::Path::contains(), elm::sys::evaluate(), and elm::sys::Plugger::plug().

bool elm::String::startsWith ( const CString  str) const

Test if the string starts with the given C string.

Parameters
strC string to compare.
Returns
True if the string starts with, false else.

References elm::CString::chars(), chars(), and elm::CString::length().

bool elm::String::startsWith ( const String str) const

Test if the string starts with the given string.

Parameters
strString to compare.
Returns
True if the string starts with, false else.

References chars(), and length().

String elm::String::substring ( int  _off,
int  _len 
) const

References String().

CString elm::String::toCString ( void  ) const

Convert the current string to a CString object.

Returns
Matching CString object.
Warning
The returned CString contains a pointer to a buffer owned by the current string. This buffer is only valid while the current is living.

References chars().

Referenced by elm::io::WinInStream::lastErrorMessage(), elm::serial2::XOMSerializer::onValue(), operator&(), and elm::xom::Serializer::writeXMLDeclaration().

string elm::String::trim ( void  ) const

Remove blanks at left and right of the current string.

Returns
Trimmed string.

References ltrim(), and rtrim().


The documentation for this class was generated from the following files: