bpp-core3  3.0.0
bpp::KeyvalTools Class Reference

Tools to deal with the keyval syntax. More...

#include <Bpp/Text/KeyvalTools.h>

Public Member Functions

 KeyvalTools ()
 
virtual ~KeyvalTools ()
 

Static Public Member Functions

static void singleKeyval (const std::string &desc, std::string &key, std::string &val, const std::string &split="=")
 Split a string into a key and a value (General purpose function). More...
 
static void multipleKeyvals (const std::string &desc, std::map< std::string, std::string > &keyvals, const std::string &split=",", bool nested=true)
 Split a string into several keys and corresponding values (General purpose function). More...
 
static std::string changeKeyvals (const std::string &desc, const std::map< std::string, std::string > &newkeyvals, const std::string &split=",", bool nested=true)
 Change several keys to new corresponding values (General purpose function). More...
 
static void parseProcedure (const std::string &desc, std::string &name, std::map< std::string, std::string > &args)
 Parse (not recursively) a procedure string. More...
 

Detailed Description

Tools to deal with the keyval syntax.

This class contains method to deal with parameter=value syntax procedure. A keyval procedure takes the form

proc(p1=v1,p2=v2,p3=v3,etc)

where 'p' are parameter names, and 'v' are the corresponding values. These values can be nested keyval procedures.

Definition at line 39 of file KeyvalTools.h.

Constructor & Destructor Documentation

◆ KeyvalTools()

bpp::KeyvalTools::KeyvalTools ( )

◆ ~KeyvalTools()

virtual bpp::KeyvalTools::~KeyvalTools ( )
virtual

Member Function Documentation

◆ changeKeyvals()

std::string KeyvalTools::changeKeyvals ( const std::string &  desc,
const std::map< std::string, std::string > &  newkeyvals,
const std::string &  split = ",",
bool  nested = true 
)
static

Change several keys to new corresponding values (General purpose function).

Parameters
desc[in] A string descibing the keyval, with format key1=val1,key2=val2,etc (space are considered normal character, that's up to you to deal with that afterwards!).
newkeyvals[in] contains the text of the keys to be changed and their new corresponding values. If a key is not in desc, it is not added.
split[in] The keyval delimiter. The default is a coma, but a space character can be used for instance.
nested[in] Tell if nested keyval procedures are expected.
Returns
the string with the changed values.
Exceptions
KeyvalExceptionIf the syntax describing the keyval is not correct.

Definition at line 63 of file KeyvalTools.cpp.

References bpp::StringTokenizer::hasMoreToken(), bpp::TextTools::isEmpty(), bpp::StringTokenizer::nextToken(), bpp::TextTools::removeFirstWhiteSpaces(), and bpp::TextTools::removeSurroundingWhiteSpaces().

◆ multipleKeyvals()

void KeyvalTools::multipleKeyvals ( const std::string &  desc,
std::map< std::string, std::string > &  keyvals,
const std::string &  split = ",",
bool  nested = true 
)
static

Split a string into several keys and corresponding values (General purpose function).

Parameters
desc[in] A string descibing the keyval, with format key1=val1,key2=val2,etc (space are considered normal character, that's up to you to deal with that afterward!).
keyvals[out] Will contain the text of the keys and their corresponding values.
split[in] The keyval delimiter.the default is a coma, but a space character can be used for instance.
nested[in] Tell if nested keyval procedures are expected.
Exceptions
KeyvalExceptionIf the syntax describing the keyval is not correct.

Definition at line 23 of file KeyvalTools.cpp.

References bpp::StringTokenizer::hasMoreToken(), bpp::StringTokenizer::nextToken(), and bpp::TextTools::removeSurroundingWhiteSpaces().

Referenced by bpp::NumCalcApplicationTools::getVector().

◆ parseProcedure()

void KeyvalTools::parseProcedure ( const std::string &  desc,
std::string &  name,
std::map< std::string, std::string > &  args 
)
static

Parse (not recursively) a procedure string.

Parameters
desc[in] A string descibing the keyval procedure.
name[out] Outputs the name of the procedure.
args[out] Fills a map with all keys and values for parameters.
Exceptions
KeyvalExceptionIf the description is invalid (one parenthesis is missing for instance).

Definition at line 137 of file KeyvalTools.cpp.

References bpp::TextTools::isEmpty(), and bpp::TextTools::removeFirstWhiteSpaces().

Referenced by bpp::BppODiscreteDistributionFormat::readDiscreteDistribution().

◆ singleKeyval()

void KeyvalTools::singleKeyval ( const std::string &  desc,
std::string &  key,
std::string &  val,
const std::string &  split = "=" 
)
static

Split a string into a key and a value (General purpose function).

Parameters
desc[in] A string descibing the keyval, with format key=val (space are considered normal character, that's up to you to deal with that afterward!).
key[out] Will contain the text of the key.
val[out] Will contain the text of the value.
split[in] The delimiter. Default is '=' but ':' can be used.
Exceptions
KeyvalExceptionIf the syntax describing the keyval is not correct.

Definition at line 14 of file KeyvalTools.cpp.


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