cxxtools::EnvSubst Class Reference

This class parses a character data and replaces environment variables. More...

#include <cxxtools/envsubst.h>

Classes

struct  Ev

Public Member Functions

 EnvSubst (Ev &ev)
 ~EnvSubst ()
void parse (char ch)
void parseEnd ()
void reset ()

Detailed Description

This class parses a character data and replaces environment variables.

To use the class, characters are pushed to the class and the class executes a callback method to pass the processed data back.

These replacements are done:

  • A sequence of '$' followed by a sequence of alphanumeric characters or underscore is replaced with the content of the environment variable. When the variable is not set, it is replaced by a empty sequence.
  • The sequence of alphanumeric characters or underscore can be bracketed with curly brackets.
  • In curly brackets a default value can be specified by using the sequence ":-". The characters before that are the environment variable and after it the replacement. Environment variables in the replacement are processed with the same rules.

Examples: The environment variable USER is set to "tommi"

String sequence output


The user $USER The user tommi The user ${USER} The user tommi The user ${USER:-whoever} The user tommi The user ${UNKNOWN_VAR:-whoever} The user whoever

Constructor & Destructor Documentation

cxxtools::EnvSubst::EnvSubst ( Ev ev)
inlineexplicit
cxxtools::EnvSubst::~EnvSubst ( )
inline

Member Function Documentation

void cxxtools::EnvSubst::parse ( char  ch)
void cxxtools::EnvSubst::parseEnd ( )
void cxxtools::EnvSubst::reset ( )
inline

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