36 #include <boost/algorithm/string.hpp> 38 #include <boost/bind.hpp> 40 using boost::algorithm::trim_right_copy_if;
41 using boost::algorithm::is_any_of;
42 using boost::algorithm::is_alnum;
43 using boost::algorithm::is_space;
48 using std::regex_match;
56 using ChPredicate = function<bool(string::value_type)>;
57 ChPredicate operator! (ChPredicate p) {
return not bind(p,_1); }
60 ChPredicate
isValid (is_alnum() or is_any_of(
"-_.+$()@"));
61 ChPredicate
isPunct (is_space() or is_any_of(
",;:#*~´`?\\=/&%![]{}<>"));
67 string res (trim_right_copy_if(org, !
isValid ));
68 string::iterator j = res.begin();
69 string::const_iterator i = org.begin();
70 string::const_iterator e = i + (res.length());
73 while ( i != e && !
isValid (*i) ) ++i;
74 while ( i != e &&
isValid (*i) ) *(j++) = *(i++);
79 while ( i != e &&
isPunct (*i));
82 res.erase(j,res.end());
95 return boost::algorithm::trim_copy (org);
102 regex trueTokens {
"\\s*(true|yes|on|1|\\+)\\s*", regex::icase | regex::optimize };
103 regex falseTokens{
"\\s*(false|no|off|0|\\-)\\s*", regex::icase | regex::optimize };
109 if (regex_match (textForm, trueTokens))
return true;
110 if (regex_match (textForm, falseTokens))
return false;
116 isYes (
string const& textForm) noexcept
118 return regex_match (textForm, trueTokens);
123 isNo (
string const& textForm) noexcept
125 return isnil (textForm)
126 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).