rambrain
rambrain::regexMatcher Class Reference

Class to handle regex matching used for parsing configuration files. More...

#include <regexmatcher.h>

Public Types

enum  matchType {
  integer = 1 << 0, floating = 1 << 1, units = 1 << 2, text = 1 << 3,
  alphanumtext = 1 << 4, boolean = 1 << 5, swapfilename = 1 << 6
}
 An enum to caracterise what shall be matched in a specific case; flaggy. More...
 

Public Member Functions

 regexMatcher ()
 Create a new regex handler, basically a dummy. More...
 
bool matchConfigBlock (const string &str, const string &blockname="default") const
 Checks if a string matches the header of a configuration block. More...
 
pair< string, string > matchKeyEqualsValue (const string &str, int valueType=alphanumtext) const
 Checks if a string matches something like key = value. More...
 
pair< string, string > matchKeyEqualsValue (const string &str, const string &key, int valueType=alphanumtext) const
 Checks if a string matches something like key = value. More...
 
pair< double, string > splitDoubleValueUnit (const string &str) const
 Split a string containing value and possibly unit into both parts. More...
 
pair< long long int, string > splitIntegerValueUnit (const string &str) const
 Split a string containing value and possibly unit into both parts. More...
 
string substituteHomeDir (const string &source, const string &homedir) const
 Replace all occurences of a ~ by the absolute home directory. More...
 

Private Member Functions

string createRegexMatching (int type) const
 Create a matching regex for a certain type. More...
 

Detailed Description

Class to handle regex matching used for parsing configuration files.

Definition at line 35 of file regexmatcher.h.

Member Enumeration Documentation

An enum to caracterise what shall be matched in a specific case; flaggy.

Warning
Negative integers currently not supported!
Enumerator
integer 
floating 
units 
text 
alphanumtext 
boolean 
swapfilename 

Definition at line 44 of file regexmatcher.h.

Constructor & Destructor Documentation

rambrain::regexMatcher::regexMatcher ( )

Create a new regex handler, basically a dummy.

Definition at line 40 of file regexmatcher.cpp.

Member Function Documentation

string rambrain::regexMatcher::createRegexMatching ( int  type) const
private

Create a matching regex for a certain type.

Parameters
typeThe type
Returns
The partial regex to match the type

Definition at line 69 of file regexmatcher.cpp.

bool rambrain::regexMatcher::matchConfigBlock ( const string &  str,
const string &  blockname = "default" 
) const

Checks if a string matches the header of a configuration block.

Parameters
strThe source string
blocknameThe config block name to check for
Returns
Result of matching

Definition at line 44 of file regexmatcher.cpp.

pair<string, string> rambrain::regexMatcher::matchKeyEqualsValue ( const string &  str,
int  valueType = alphanumtext 
) const

Checks if a string matches something like key = value.

Parameters
strThe source string
valueTypeWhich matchType the value should be, does not match otherwise
Returns
Result key and value
pair<string, string> rambrain::regexMatcher::matchKeyEqualsValue ( const string &  str,
const string &  key,
int  valueType = alphanumtext 
) const

Checks if a string matches something like key = value.

Parameters
strThe source string
keyWhich key to match
valueTypeWhich matchType the value should be, does not match otherwise
Returns
Result key and value
pair< double, string > rambrain::regexMatcher::splitDoubleValueUnit ( const string &  str) const

Split a string containing value and possibly unit into both parts.

Parameters
strThe string containing double and unit
Returns
Value and unit

Definition at line 106 of file regexmatcher.cpp.

pair< long long, string > rambrain::regexMatcher::splitIntegerValueUnit ( const string &  str) const

Split a string containing value and possibly unit into both parts.

Parameters
strThe string containing integer and unit
Returns
Value and unit

Definition at line 122 of file regexmatcher.cpp.

string rambrain::regexMatcher::substituteHomeDir ( const string &  source,
const string &  homedir 
) const

Replace all occurences of a ~ by the absolute home directory.

Parameters
sourceThe input string
homedirThe home directory
Returns
The new string

Definition at line 138 of file regexmatcher.cpp.


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