20 char toLowerCh(
char c) {
21 return static_cast<char>( std::tolower( c ) );
25 bool startsWith( std::string
const&
s, std::string
const& prefix ) {
26 return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(),
s.begin());
29 return !
s.empty() &&
s[0] == prefix;
31 bool endsWith( std::string
const&
s, std::string
const& suffix ) {
32 return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(),
s.rbegin());
34 bool endsWith( std::string
const&
s,
char suffix ) {
35 return !
s.empty() &&
s[
s.size()-1] == suffix;
37 bool contains( std::string
const&
s, std::string
const& infix ) {
38 return s.find( infix ) != std::string::npos;
41 std::transform(
s.begin(),
s.end(),
s.begin(), toLowerCh );
48 std::string
trim( std::string
const& str ) {
49 static char const* whitespaceChars =
"\n\r\t ";
50 std::string::size_type start = str.find_first_not_of( whitespaceChars );
51 std::string::size_type end = str.find_last_not_of( whitespaceChars );
53 return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
56 bool replaceInPlace( std::string& str, std::string
const& replaceThis, std::string
const& withThis ) {
57 bool replaced =
false;
58 std::size_t i = str.find( replaceThis );
59 while( i != std::string::npos ) {
61 str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
62 if( i < str.size()-withThis.size() )
63 i = str.find( replaceThis, i+withThis.size() );
65 i = std::string::npos;
71 std::vector<StringRef> subStrings;
72 std::size_t start = 0;
73 for(std::size_t pos = 0; pos < str.size(); ++pos ) {
74 if( str[pos] == delimiter ) {
76 subStrings.push_back( str.substr( start, pos-start ) );
80 if( start < str.size() )
81 subStrings.push_back( str.substr( start, str.size()-start ) );
void toLowerInPlace(std::string &s)
std::string trim(std::string const &str)
std::vector< StringRef > splitStringRef(StringRef str, char delimiter)
bool startsWith(std::string const &s, std::string const &prefix)
bool contains(std::string const &s, std::string const &infix)
auto operator<<(std::ostream &os, LazyExpression const &lazyExpr) -> std::ostream &
std::string toLower(std::string const &s)
bool endsWith(std::string const &s, std::string const &suffix)
bool replaceInPlace(std::string &str, std::string const &replaceThis, std::string const &withThis)
pluralise(std::size_t count, std::string const &label)