Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Implementation of widely used helper functions.
The helpers implemented here are typically accessed by including util.hpp, so the reason of pushing down the implementation into a separate translation unit (this one here) is to avoid more heavyweight includes (e.g. boost).
Definition in file util.cpp.
#include "error.hpp"
#include "lib/util.hpp"
#include "lib/format-string.hpp"
#include <boost/algorithm/string.hpp>
#include <functional>
#include <boost/bind.hpp>
#include <regex>
Typedefs | |
using | ChPredicate = function< bool(string::value_type)> |
Functions | |
bool | boolVal (string const &) |
interpret text representation of a boolean value. More... | |
bool | isNo (string const &) noexcept |
check if the given text is empty or can be interpreted as rejection (bool false )- More... | |
ChPredicate | isPunct (is_space() or is_any_of(",;:#*~´`?\/&%![]{}<>")) |
punctuation to be replaced by '_' | |
ChPredicate | isValid (is_alnum() or is_any_of("-_.+$()@")) |
characters to be retained | |
bool | isYes (string const &) noexcept |
check the given text if it can be interpreted as affirmative answer (bool true ). More... | |
ChPredicate | operator! (ChPredicate p) |
std::string | sanitise (string const &org) |
produce an identifier based on the given string. More... | |
string | trim (string const &org) |
remove leading and trailing whitespace More... | |
Variables | |
regex | falseTokens { "\\s*(false|no|off|0|\\-)\\s*", regex::icase | regex::optimize } |
regex | trueTokens { "\\s*(true|yes|on|1|\\+)\\s*", regex::icase | regex::optimize } |
Namespaces |
string sanitise | ( | string const & | org | ) |
produce an identifier based on the given string.
remove non-standard-chars, reduce sequences of punctuation and whitespace to single underscores. The sanitised string will start with an alphanumeric character.
"Word" --> "Word" "a Sentence" --> "a_Sentence" "trailing Withespace \t \n" --> "trailing_Withespace" "with a lot \nof Whitespace" --> "with_a_lot_of_Whitespace" "@with\".\'much ($punctuation)[]!" --> "@with.much_($punctuation)" "§&Ω%€ leading garbage" --> "leading_garbage" "mixed Ω garbage" --> "mixed_garbage" "Bääääh!!" --> "Bh"
Definition at line 56 of file util.cpp.
References util::isValid(), and util::sanitise().
Referenced by util::sanitise().
string trim | ( | string const & | org | ) |
remove leading and trailing whitespace
Definition at line 84 of file util.cpp.
References util::trim().
Referenced by util::trim().
bool boolVal | ( | string const & | ) |
interpret text representation of a boolean value.
true
for the tokens "true", "True", "TRUE", "yes", "Yes", "YES", "1", "+"false
for the tokens "false", "False", "FALSE", "no", "No, "NO", "0", "-"lumiera::error::Invalid | for any other text content |
Definition at line 98 of file util.cpp.
References util::boolVal().
Referenced by util::boolVal().
|
noexcept |
check the given text if it can be interpreted as affirmative answer (bool true
).
true
tokens and interprets all other content as false
, including empty strings. Never throws. Definition at line 107 of file util.cpp.
References util::isYes().
Referenced by util::isYes().
|
noexcept |
check if the given text is empty or can be interpreted as rejection (bool false
)-
false
tokens; any other non-empty content counts as not no. Definition at line 114 of file util.cpp.
References util::isNo().
Referenced by util::isNo().