33 std::string_view toReplace,std::string_view replaceWith)
38 buf.reserve(s.length());
40 while ((pos=s.find(toReplace, prevPos))!=std::string::npos)
42 buf.append(s, prevPos, pos - prevPos);
44 prevPos = pos + toReplace.length();
46 buf.append(s, prevPos, s.size() - prevPos);
54 std::string_view toReplace,std::string_view replaceWith)
59 buf.reserve(s.length());
61 while ((pos=s.find(toReplace, prevPos))!=std::string::npos)
63 buf.append(s, prevPos, pos - prevPos);
65 prevPos = pos + toReplace.length();
67 buf.append(s, prevPos, s.size() - prevPos);
77 static auto isspace = [](
char c){
return c==
' ' || c==
'\t' || c==
'\n' || c==
'\r'; };
78 size_t sl = s.length();
79 if (sl==0 || (!isspace(s[0]) && !isspace(s[sl-1])))
return s;
80 size_t start=0,
end=sl-1;
81 while (start<sl && isspace(s[start])) start++;
82 if (start==sl)
return s.substr(0,0);
83 while (
end>start && isspace(s[
end]))
end--;
84 return s.substr(start,
end+1-start);
95 if (s[s.length()-1]!=c) s+=c;
104 return data!=
nullptr && data[0]==str[0] &&
dstrncmp(data+1,str+1,len-1)==0;
112 return len<=data.size() && data[0]==str[0] &&
dstrncmp(data.data()+1,str+1,len-1)==0;
120 size_t prev = 0, pos = 0, len = s.length();
123 pos = s.find(delimiter, prev);
124 if (pos == std::string::npos) pos = len;
125 if (pos>prev) result.push_back(s.substr(prev,pos-prev));
126 prev = pos + delimiter.length();
128 while (pos<len && prev<len);
140 for ( ; iter !=
end; ++iter)
142 const auto &match = *iter;
143 size_t i=match.position();
144 size_t l=match.length();
145 if (i>p) result.push_back(s.substr(p,i-p));
148 if (p<s.length()) result.push_back(s.substr(p));
157 for (
const auto &s : sv)
159 if (!first) result+=delimiter;
169 auto it = std::find(sv.begin(),sv.end(),s);
170 return it!=sv.end() ?
static_cast<size_t>(it-sv.begin()) : std::string::npos;
178 return reg::search(s,match,re) ?
static_cast<size_t>(match.position()) : std::string::npos;
184 out.reserve(s.length());
185 const char *p=s.data();
194 while (*e==
' ' || *e==
'\t') e++;
Class representing a regular expression.
Class to iterate through matches.
Object representing the matching results.
std::vector< std::string > StringVector
DirIterator end(const DirIterator &) noexcept
int dstrncmp(const char *str1, const char *str2, size_t len)
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
std::string join(const StringVector &sv, const std::string &delimiter)
create a string where the string in the vector are joined by the given delimiter
std::string substituteStringView(std::string_view s, std::string_view toReplace, std::string_view replaceWith)
Returns a new string where occurrences of substring toReplace in string s are replaced by string repl...
void addTerminalCharIfMissing(std::string &s, char c)
size_t findIndex(const StringVector &sv, const std::string &s)
find the index of a string in a vector of strings, returns std::string::npos if the string could not ...
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
std::string removeEmptyLines(const std::string &s)
void substituteInplace(std::string &s, std::string_view toReplace, std::string_view replaceWith)
Replaces occurrences of substring toReplace in string s with string replaceWith.
StringVector split(const std::string &s, const std::string &delimiter)
split input string s by string delimiter delimiter.
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...