Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
String Class Reference

#include <elm/string/String.h>

Classes

class  Iter
 

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 * asNullTerminated () const
 
const char * asSysString () 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
 
String replace (String pat, String sub)
 
Iter begin () const
 
Iter end () const
 
template<class C >
String join (const C &coll)
 

Static Public Member Functions

static String make (char chr)
 
static String make (String chr, int n)
 

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

◆ String() [1/5]

String ( void  )
inline

Build an empty string.

Referenced by String::make(), and String::substring().

◆ String() [2/5]

String ( const char *  str,
int  _len 
)
inline

Build a string from a character array.

Parameters
strCharacter array base.
_lenCharacter array length.

References elm::str().

◆ String() [3/5]

String ( const char *  str)
inline

Build an ELM string from a C string.

Parameters
strC string.

References elm::str().

◆ String() [4/5]

String ( cstring  str)
inline

Build a string from a CString.

Parameters
strCString object to use.

References String::chars(), String::length(), and elm::str().

◆ String() [5/5]

String ( const String str)
inline

Clone an existing string.

Parameters
strString to clone.

◆ ~String()

~String ( void  )
inline

Member Function Documentation

◆ asNullTerminated()

const char * asNullTerminated ( ) const
inline

Convert the current string to a null-terminated character array (C standard). The ownership of the character array is retained by the string. Modifying this array modifies also the original string.

Returns
String converted to null-terminated character array.

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

Referenced by String::asSysString().

◆ asSysString()

const char * asSysString ( ) const
inline

Convert the current string to a null-terminated character array usable with the current OS calls. The ownership of the character array is retained by the string. Modifying this array modifies also the original string.

Returns
String compatible with the current OS calls.

References String::asNullTerminated().

Referenced by Element::parse().

◆ begin()

Iter begin ( ) const
inline

◆ charAt()

char charAt ( int  index) const
inline

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 String::ltrim(), String::operator[](), and String::rtrim().

◆ chars()

const char * chars ( void  ) const
inline

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 String::compare(), CString::concat(), String::concat(), CString::endsWith(), String::endsWith(), HashKey< String >::hash(), String::indexOf(), String::lastIndexOf(), String::operator=(), Output::print(), MD5::put(), ProcessBuilder::run(), CString::startsWith(), String::startsWith(), String::String(), and String::toCString().

◆ compare() [1/2]

int compare ( const CString  str) const
inline

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 String::chars(), String::length(), and elm::str().

◆ compare() [2/2]

int compare ( const String str) const
inline

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 String::chars(), and elm::str().

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

◆ concat() [1/2]

String concat ( const CString  str) const
inline

Concatenate a string with a C string.

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

References String::chars(), String::concat(), String::length(), and elm::str().

Referenced by String::concat().

◆ concat() [2/2]

String concat ( const String str) const
inline

Concatenate two strings.

Parameters
strString to concatenate after.
Returns
Result of concatenation.

References String::chars(), String::concat(), String::length(), and elm::str().

Referenced by String::concat().

◆ end()

Iter end ( ) const
inline

References String::length().

◆ endsWith() [1/3]

bool endsWith ( const char *  str) const
inline

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 String::CString, and elm::str().

Referenced by elm::sys::isLibrary().

◆ endsWith() [2/3]

bool endsWith ( const CString  str) const
inline

Test if the string ends with the given string.

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

References String::chars(), String::length(), and elm::str().

◆ endsWith() [3/3]

bool endsWith ( const String str) const
inline

Test if the string ends with the given string.

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

References String::chars(), and elm::str().

◆ indexOf() [1/3]

int indexOf ( char  chr) const
inline

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 String::indexOf().

Referenced by Section::getList(), String::indexOf(), File::load(), Version::operator=(), Manager::parse(), String::replace(), and VarExpander::write().

◆ indexOf() [2/3]

int indexOf ( char  chr,
int  pos 
) const
inline

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 String::chars(), and elm::io::p().

◆ indexOf() [3/3]

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

Find the first occurrence of a substring.

Parameters
stringString to look for.
posStart position.

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

◆ isEmpty()

bool isEmpty ( void  ) const
inline

Test if string is empty.

Returns
True if the string is empty, false else.

Referenced by Path::isEmpty(), and String::operator bool().

◆ join()

String join ( const C &  coll)
inline

Join the items of the given collection into a string where each item is separated by the current string. The items must be string or writable to an Output channel.

Parameters
collCollection of items to join (must be iterable).
CType of the collection.
Returns
Result of the join.

References StringBuffer::toString().

◆ lastIndexOf() [1/4]

int lastIndexOf ( char  chr) const
inline

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 String::lastIndexOf(), and String::length().

Referenced by Path::basePart(), Path::extension(), String::lastIndexOf(), Path::setExtension(), and Path::withoutExt().

◆ lastIndexOf() [2/4]

int lastIndexOf ( char  chr,
int  pos 
) const
inline

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 String::chars(), and elm::io::p().

◆ lastIndexOf() [3/4]

int lastIndexOf ( const String str)
inline

◆ lastIndexOf() [4/4]

int lastIndexOf ( const String string,
int  pos 
)

Find the last occurrence of a substring.

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

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

◆ length()

◆ ltrim()

string ltrim ( void  ) const

Remove blanks at left of the current string.

Returns
Left-trimmed string.

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

Referenced by String::trim().

◆ make() [1/2]

String make ( char  chr)
static

Build a string with a single character.

Parameters
chrCharacter containing the string.

References String::String().

◆ make() [2/2]

String make ( String  str,
int  n 
)
static

Build a string by repeating n times the argument string.

Parameters
strString to repeat.
nNumber of repetitions.

References elm::str(), and StringBuffer::toString().

◆ operator bool()

operator bool ( void  ) const
inline

Same as isEmpty().

References String::isEmpty().

◆ operator=() [1/3]

String & operator= ( const char *  str)
inline

Assign a C string to the current string.

Parameters
strC string to assign.
Returns
Current string.

References elm::str().

◆ operator=() [2/3]

String & operator= ( const CString  str)
inline

Assign a CString object to the current string.

Parameters
strCString object to assign.
Returns
Current string.

References String::chars(), String::length(), and elm::str().

◆ operator=() [3/3]

String & operator= ( const String str)
inline

Assign a string to the current one.

Parameters
strString to assign.
Returns
Current string.

References elm::str().

◆ operator[]()

char operator[] ( int  index) const
inline

Same as charAt().

References String::charAt().

◆ replace()

string replace ( String  pat,
String  sub 
)

Replace any instance of pat by sub in the current string.

References String::indexOf(), String::length(), elm::io::p(), String::substring(), and StringBuffer::toString().

◆ rtrim()

string rtrim ( void  ) const

Remove blanks at right of the current string.

Returns
Right-trimmed string.

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

Referenced by String::trim().

◆ startsWith() [1/3]

bool startsWith ( const char *  str) const
inline

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 String::CString, and elm::str().

Referenced by Path::isPrefixOf(), Plugger::plug(), and Path::subPathOf().

◆ startsWith() [2/3]

bool startsWith ( const CString  str) const
inline

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 String::chars(), String::length(), and elm::str().

◆ startsWith() [3/3]

bool startsWith ( const String str) const
inline

Test if the string starts with the given string.

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

References String::chars(), String::length(), and elm::str().

◆ substring() [1/2]

◆ substring() [2/2]

String substring ( int  _off,
int  _len 
) const
inline

References String::String().

◆ toCString()

CString toCString ( void  ) const
inline

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 String::chars().

Referenced by String::asNullTerminated(), Path::asSysString(), VarExpander::expand(), Attribute::getValue(), WinInStream::lastErrorMessage(), XOMElementSerializer::onValue(), Plugger::plugFile(), access_t< string >::set(), access_t< const string & >::set(), VarExpander::write(), Serializer::writeXMLDeclaration(), and XOMUnserializer::XOMUnserializer().

◆ trim()

string trim ( void  ) const

Remove blanks at left and right of the current string.

Returns
Trimmed string.

References String::ltrim(), and String::rtrim().


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