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

This module provides classes making easier the use of character string. There is basically two classes: String and CString. Other classes provides more services like StringBuffer. More...

Classes

class  Char
 
class  String
 
class  CString
 
class  StringSplit
 
class  StringBuffer
 
class  Char
 
class  Iter
 
class  Formatter
 

Variables

AutoStringStartup autostr
 
AutoStringStartup_ = autostr
 

Detailed Description

This module provides classes making easier the use of character string. There is basically two classes: String and CString. Other classes provides more services like StringBuffer.

Notice that typedefs "string" and "cstring" are only scalar-type-like shortcuts to String and CString classes.

Base Classes

The CString is a simple wrapper around the original C "char *" null-terminated C string. It provides an interface very similar to the String class as possible. The operator "&" may be used to get the hidden "const char *" buffer. When CString operation requires memory allocation, a String object is instead returned as this class has automatic memory management facilities. The CString is either useful to interact with the OS, or to handle constant litteral strings.

The String provides a lot of facilities to handle strings as any other scalar type:

String Operations

The string classes implements the concept concept::Array<char>.

The following operators are also available:

Some automatic conversions are also available:

Finally, there some methods to perform tests or retrieval of strings:

And some methods to build strings:

StringBuffer Class

String building is very costly because it requires a memory copy of both involved strings. Usually, a string building operation involves many concatenation. The StringBuffer class may be used to reduce this cost.

The string is built in a large buffer that is expanded (inducing a copy operation) less often than the original String class. To makes things easier, this class provides also the same interface as IO io::Output class. To get the completed string, one has only to call the toString() method as in the example below.

for(int i = 0; i < 10; i++) {
StringBuffer buffer;
buffer << "Hello world: " << i << io:endl;
string str = buffer.toString();
my_function(str);
}

To make things even easier, the ELM library provides an auto-builder and frier of string buffer called elm::_ that avoids the need to declare the string buffer. The previous example uses below this feature:

for(int i = 0; i < 10; i++)
my_function(_ << "Hello world: " << i << io:endl);
Tool Classes

Other classes provide several facilities:

Variable Documentation

◆ _

#include <include/elm/string/AutoString.h>

This little object make easier the construction of strings. There is no more to explictely construct a string buffer, concatenates items and buid the string to pass it to a parameter. Just perform the concatenation on the autostr object and all work is done automatically as in the example below.

void call(const String& message);
for(int i = 0; i < 100; i++)
call(autostr << "Hello world, " << i << " times !");

As the autostr keyword is a bit long, you may replaced it by "_".

for(int i = 0; i < 100; i++)
call(_ << "Hello world, " << i << " times !");

Referenced by BiDiList< T, E, A >::BackIter::BackIter(), XOMElementSerializer::beginCompound(), XOMElementSerializer::beginObject(), BiDiList< T, E, A >::clear(), System::createRandomFile(), Debug::debugPrefix(), Debug::debugPrefixFunction(), Debug::debugPrefixWrapped(), Path::DirIter::DirIter(), BiDiList< T, E, A >::first(), XOMUnserializer::flush(), Class< T, B, I >::instantiate(), TreeBag< T, C, A >::Iter::Iter(), Saver::key(), BiDiList< T, E, A >::last(), File::load(), GroupedGC::mark(), SimpleGC::mark(), BiDiList< T, E, A >::Iter::next(), TreeBag< T, C, A >::Iter::next(), BiDiList< T, E, A >::BackIter::next(), XOMUnserializer::onEnum(), XOMElementSerializer::onPointer(), XOMElementSerializer::onValue(), XOMUnserializer::onValue(), System::openRandomFile(), Manager::parse(), Parser::parse(), Plugger::plugFile(), EnumOption< T >::process(), IDAttribute::process(), RefAttribute< T >::process(), BiDiList< T, E, A >::remove(), BiDiList< T, E, A >::removeAfter(), BiDiList< T, E, A >::removeBefore(), BiDiList< T, E, A >::removeFirst(), BiDiList< T, E, A >::removeLast(), and elm::single().

◆ autostr

#include <include/elm/string/AutoString.h>

Refer to elm::_.

Referenced by elm::operator<<().

elm::autostr
AutoStringStartup autostr
Definition: string_AutoString.cpp:32
elm::_
AutoStringStartup & _
Definition: debug_CrashHandler.cpp:232
elm::io::endl
const EOL endl
Definition: io_Output.cpp:880
elm::str
string str(const char *s)
Definition: String.h:150