![]() |
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
#include <elm/io/VarExpander.h>
Public Member Functions | |
VarExpander () | |
VarExpander (OutStream &out) | |
char | escape () const |
VarExpander & | escape (char e) |
VarExpander & | resetBrace () |
VarExpander & | brace (char o, char c) |
string | expand (string s) |
int | write (const char *buffer, int size) override |
int | write (char byte) override |
int | flush (void) override |
CString | lastErrorMessage (void) override |
bool | supportsANSI () const override |
![]() | |
virtual | ~OutStream (void) |
Protected Member Functions | |
virtual string | resolve (string name, bool &record) |
Additional Inherited Members | |
![]() | |
static OutStream & | null = _null |
This class a character flow filter replacing symbol invocation by the symbol value. Basically, a symbol invocation is of an escape character (default to '$') followed by a brace open character (one of '(', '{'), the symbol name and a brace close character (one of ')', '}'). This string is replaced in the character flow with the string associated with the symbol.
The association is implemented by a call to function VarExpander::resolve(). If required, the association is cached and no more call to this function is performed for this symbol. To specialize the variable expansion, one has to overload this function. The default implementation returns an empty string.
This class may be used as an OutStream or simply by passing a string and getting the result from the function VarExpander::expand().
The code below expands the variable of the chacter flow using OS environment variables:
VarExpander | ( | ) |
Default expander constructor: output is performed to starandard output.
VarExpander | ( | OutStream & | out | ) |
Expander constructor with the given output.
out | Output stream to use. |
|
inline |
Added the given set of brace characters.
o | Open brace character. |
c | Close brace character. |
|
inline |
Get escape character.
|
inline |
Change the escape character.
e | new escape character. |
Expand the given string.
s | String to expand. |
References CString::chars(), Output::flush(), String::length(), StringBuffer::stream(), String::toCString(), StringBuffer::toString(), and VarExpander::write().
Referenced by elm::io::expandOSVars().
|
overridevirtual |
Cause the current stream to dump its buffer to the medium.
Implements OutStream.
References OutStream::flush().
Return a message for the last error.
Reimplemented from OutStream.
References OutStream::lastErrorMessage().
|
inline |
Reset the list of supported open-close characters.
This function has to be overridden to provide symbol definition. The default implementation just returns the empty string.
name | Symbol name to look for. |
record | If set to false, the symbol will not be cached. |
Reimplemented in OSExpander.
Referenced by VarExpander::write().
|
overridevirtual |
Test if the current stream knows how to decode ANSI special codes. The default implementation returns false.
Reimplemented from OutStream.
References OutStream::supportsANSI().
|
overridevirtual |
Write a byte to the stream.
byte | Byte to write. |
Reimplemented from OutStream.
References elm::io::byte(), CString::chars(), String::indexOf(), String::length(), elm::io::p(), StringBuffer::reset(), VarExpander::resolve(), String::toCString(), StringBuffer::toString(), and OutStream::write().
|
overridevirtual |
This is the main method of an output stream: the given buffer is put on the stream.
buffer | Byte buffer to write. |
size | Size of the byte buffer. |
Implements OutStream.
Referenced by VarExpander::expand().