27 #include <boost/algorithm/string.hpp> 29 #include <boost/bind.hpp> 31 using boost::algorithm::trim_right_copy_if;
32 using boost::algorithm::is_any_of;
33 using boost::algorithm::is_alnum;
34 using boost::algorithm::is_space;
39 using std::regex_match;
47 using ChPredicate = function<bool(string::value_type)>;
48 ChPredicate operator! (ChPredicate p) {
return not bind(p,_1); }
51 ChPredicate
isValid (is_alnum() or is_any_of(
"-_.+$()@"));
52 ChPredicate
isPunct (is_space() or is_any_of(
",;:#*~´`?\\=/&%![]{}<>"));
58 string res (trim_right_copy_if(org, !
isValid ));
59 string::iterator j = res.begin();
60 string::const_iterator i = org.begin();
61 string::const_iterator e = i + (res.length());
64 while ( i != e && !
isValid (*i) ) ++i;
65 while ( i != e &&
isValid (*i) ) *(j++) = *(i++);
70 while ( i != e &&
isPunct (*i));
73 res.erase(j,res.end());
86 return boost::algorithm::trim_copy (org);
93 regex trueTokens {
"\\s*(true|yes|on|1|\\+)\\s*", regex::icase | regex::optimize };
94 regex falseTokens{
"\\s*(false|no|off|0|\\-)\\s*", regex::icase | regex::optimize };
100 if (regex_match (textForm, trueTokens))
return true;
101 if (regex_match (textForm, falseTokens))
return false;
107 isYes (
string const& textForm) noexcept
109 return regex_match (textForm, trueTokens);
114 isNo (
string const& textForm) noexcept
116 return isnil (textForm)
117 or regex_match (textForm, falseTokens);
ChPredicate isValid(is_alnum() or is_any_of("-_.+$()@"))
characters to be retained
bool isYes(string const &textForm) noexcept
check the given text if it can be interpreted as affirmative answer (bool true).
std::string sanitise(std::string const &)
produce an identifier based on the given string.
bool boolVal(string const &textForm)
interpret text representation of a boolean value.
A front-end for using printf-style formatting.
ChPredicate isPunct(is_space() or is_any_of(",;:#*~´`?\/&%![]{}<>"))
punctuation to be replaced by '_'
Derived specific exceptions within Lumiera's exception hierarchy.
bool isNo(string const &textForm) noexcept
check if the given text is empty or can be interpreted as rejection (bool false)- ...
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
string trim(string const &org)
remove leading and trailing whitespace
Lumiera error handling (C++ interface).