26 #include <string_view> 45 void trim(std::string_view&
s);
55 int partend = s.find(sep);
56 if(partend ==
int(std::string_view::npos)) {
59 f(s.substr(0, partend));
60 s.remove_prefix(partend + 1);
100 std::vector<std::string> vec_split =
split(val,
c, flags);
101 return std::set< std::string >(vec_split.begin(), vec_split.end());
115 std::map<std::string, std::string>
map_split(
116 const std::string& val,
120 const std::string& default_value =
"");
143 const std::string& val,
144 const char separator = 0,
145 const std::string&
left =
"(",
146 const std::string&
right =
")",
183 const std::string& val,
184 const char separator =
',',
185 const std::string&
left =
"([",
186 const std::string&
right =
")]",
195 template <
typename T>
196 std::string
join(
const T& v,
const std::string&
s =
",")
198 std::stringstream str;
200 for(
typename T::const_iterator
i = v.begin();
i != v.end(); ++
i) {
210 template <
typename T>
213 const std::string& major =
",",
214 const std::string& minor =
":")
216 std::stringstream str;
218 for(
typename T::const_iterator
i = v.begin();
i != v.end(); ++
i) {
219 str <<
i->first << minor <<
i->second;
241 std::ostringstream str;
243 for(
typename T::const_iterator
i = v.begin();
i != v.end(); ++
i) {
248 str << std::string(
indent,
' ') << bullet <<
' ' << *
i;
264 std::string
indent(
const std::string&
string, std::size_t indent_size = 4);
266 std::pair<int, int>
parse_range(
const std::string& str);
268 std::vector<std::pair<int, int>>
parse_ranges(
const std::string& str);
270 int apply_modifier(
const int number,
const std::string &amount,
const int minimum = 0);
275 return mod[0] ==
'-' ? (
font::unicode_minus + std::string(mod.begin() + 1, mod.end())) : (
"+" + mod);
279 std::string
escape(
const std::string &str,
const char *special_chars);
287 inline std::string
escape(
const std::string &str)
289 return escape(str,
"#@{}+-,\\*=");
293 std::string
unescape(
const std::string &str);
296 std::string
urlencode(
const std::string &str);
299 inline std::string
quote(
const std::string &str)
301 return '"' + str +
'"';
305 bool string_bool(
const std::string& str,
bool def=
false);
328 std::string
si_string(
double input,
bool base2,
const std::string&
unit);
344 bool word_completion(std::string& text, std::vector<std::string>& wordlist);
347 bool word_match(
const std::string& message,
const std::string& word);
bool isvalid_wildcard(const std::string &username)
Check if the username pattern contains only valid characters.
std::pair< int, int > parse_range(const std::string &str)
std::string join_map(const T &v, const std::string &major=",", const std::string &minor=":")
std::string urlencode(const std::string &str)
Percent-escape characters in a UTF-8 string intended to be part of a URL.
bool isvalid_username(const std::string &username)
Check if the username contains only valid characters.
std::map< std::string, t_string > string_map
This class represents a single unit of a specific type.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::set< std::string > split_set(std::string_view s, char sep, const int flags)
std::string unescape(const std::string &str)
Remove all escape characters (backslash)
bool wildcard_string_match(const std::string &str, const std::string &match)
Match using '*' as any number of characters (including none), '+' as one or more characters, and '?' as any one character.
void ellipsis_truncate(std::string &str, const std::size_t size)
Truncates a string to a given utf-8 character count and then appends an ellipsis. ...
bool notspace(const char c)
std::map< std::string, std::string > map_split(const std::string &val, char major, char minor, int flags, const std::string &default_value)
Splits a string based on two separators into a map.
std::string quote(const std::string &str)
Surround the string 'str' with double quotes.
std::string half_signed_value(int val)
Sign with Unicode "−" if negative.
std::string bullet_list(const T &v, std::size_t indent=4, const std::string &bullet=font::unicode_bullet)
Generates a new string containing a bullet list.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
const std::string unicode_minus
std::vector< std::pair< int, int > > parse_ranges(const std::string &str)
std::string si_string(double input, bool base2, const std::string &unit)
Convert into a string with an SI-postfix.
void to_sql_wildcards(std::string &str, bool underscores)
Converts '*' to '' and optionally escapes '_'.
std::string escape(const std::string &str, const char *special_chars)
Prepends a configurable set of characters with a backslash.
static map_location::DIRECTION s
void split_foreach_impl(std::string_view s, char sep, const F &f)
std::vector< std::string > quoted_split(const std::string &val, char c, int flags, char quote)
This function is identical to split(), except it does not split when it otherwise would if the previo...
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
std::string bool_string(const bool value)
Converts a bool value to 'true' or 'false'.
bool string_bool(const std::string &str, bool def)
Convert no, false, off, 0, 0.0 to false, empty to def, and others to true.
const std::string unicode_bullet
bool isnewline(const char c)
REMOVE_EMPTY: remove empty elements.
void split_foreach(std::string_view s, char sep, const int flags, const F &f)
std::vector< std::string > split(const config_attribute_value &val)
int apply_modifier(const int number, const std::string &amount, const int minimum)
std::string indent(const std::string &string, std::size_t indent_size)
Indent a block of text.
static const char * match(MatchState *ms, const char *s, const char *p)
void trim(std::string_view &s)
std::set< std::string > set_split(const std::string &val, const char c=',', const int flags=REMOVE_EMPTY|STRIP_SPACES)
Splits a (comma-)separated string into a set of pieces.
bool portable_isspace(const char c)
std::string signed_value(int val)
Convert into a signed value (using the Unicode "−" and +0 convention.
std::string print_modifier(const std::string &mod)
Add a "+" or replace the "-" par Unicode minus.
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of 'text' with the 'wordlist'.
std::vector< std::string > square_parenthetical_split(const std::string &val, const char separator, const std::string &left, const std::string &right, const int flags)
Similar to parenthetical_split, but also expands embedded square brackets.
std::pair< std::string, unsigned > item
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
std::vector< std::string > parenthetical_split(const std::string &val, const char separator, const std::string &left, const std::string &right, const int flags)
Splits a string based either on a separator, except then the text appears within specified parenthesi...