25 #include <boost/xpressive/xpressive.hpp>
26 #define COMPILE_RGX(name, rx) sregex name = sregex::compile ( rx )
32 #define COMPILE_RGX(name, rx) regex name( rx )
40 regexMatcher::regexMatcher()
44 bool regexMatcher::matchConfigBlock (
const string &str,
const string &blockname )
const
46 const COMPILE_RGX ( rgx,
"\\s*\\[" + blockname +
"\\]\\s*" );
47 return regex_match ( str, rgx );
50 pair<string, string> regexMatcher::matchKeyEqualsValue (
const string &str,
int valueType )
const
52 return matchKeyEqualsValue ( str,
"[a-zA-Z]+", valueType );
55 pair<string, string> regexMatcher::matchKeyEqualsValue (
const string &str,
const string &key,
int valueType )
const
57 pair<string, string> res;
59 const COMPILE_RGX ( rgx,
"\\s*(" + key +
")\\s*=\\s*(" + createRegexMatching ( valueType ) +
")\\s*" );
61 if ( regex_match ( str, match, rgx ) ) {
63 res.second = match[2];
69 string regexMatcher::createRegexMatching (
int type )
const
73 if ( type & swapfilename ) {
74 string ant =
"[\\/\\.0-9a-zA-Z-_\\\\]";
75 ss <<
"~?" << ant <<
"+\\%d" << ant <<
"*\\%d" << ant <<
"*";
77 if ( type &
boolean ) {
78 ss <<
"true|True|TRUE|false|False|FALSE";
79 if ( type & integer ) {
84 if ( type & integer || type & floating ) {
90 if ( type & alphanumtext ) {
91 ss <<
"\\/\\.0-9a-zA-Z-_\\%\\\\";
94 if ( type & floating ) {
98 ss <<
"\\s*[a-zA-Z]*";
106 pair<double, string> regexMatcher::splitDoubleValueUnit (
const string &str )
const
108 pair<double, string> res;
109 const COMPILE_RGX ( rgx,
"([0-9]+\\.?\\d*f?)\\s*([a-zA-Z]*)" );
112 if ( regex_match ( str, match, rgx ) ) {
113 res.first = atof ( static_cast<string> ( match[1] ).c_str() );
114 if ( match.size() > 2 ) {
115 res.second = match[2];
122 pair<long long, string> regexMatcher::splitIntegerValueUnit (
const string &str )
const
124 pair<unsigned long long, string> res;
125 const COMPILE_RGX ( rgx,
"([0-9]+)\\s*([a-zA-Z]*)" );
128 if ( regex_match ( str, match, rgx ) ) {
129 res.first = atoll ( static_cast<string> ( match[1] ).c_str() );
130 if ( match.length() > 2 ) {
131 res.second = match[2];
138 string regexMatcher::substituteHomeDir (
const string &source,
const string &homedir )
const
140 const COMPILE_RGX ( rgx,
"~" );
142 string res = regex_replace ( source, rgx, homedir );