27 #include <string_view>
37 const std::vector<std::string>
res_order = {
"blade",
"pierce",
"impact",
"fire",
"cold",
"arcane"};
41 bool operator()(
const std::string& a,
const std::string&
b)
const {
63 void trim(std::string_view&
s);
73 std::size_t partend =
s.find(sep);
74 if(partend == std::string_view::npos) {
77 f(
s.substr(0, partend));
78 s.remove_prefix(partend + 1);
123 std::map<std::string, std::string>
map_split(
124 const std::string& val,
128 const std::string& default_value =
"");
151 std::string_view val,
152 const char separator = 0,
153 std::string_view left =
"(",
154 std::string_view right =
")",
191 const std::string& val,
192 const char separator =
',',
193 const std::string& left =
"([",
194 const std::string& right =
")]",
203 template <
typename T>
204 std::string
join(
const T& v,
const std::string&
s =
",")
206 std::stringstream str;
208 for(
typename T::const_iterator
i = v.begin();
i != v.end(); ++
i) {
210 if(std::next(
i) != v.end()) {
218 template <
typename T>
221 const std::string& major =
",",
222 const std::string& minor =
":")
224 std::stringstream str;
226 for(
typename T::const_iterator
i = v.begin();
i != v.end(); ++
i) {
227 str <<
i->first << minor <<
i->second;
228 if(std::next(
i) != v.end()) {
249 std::ostringstream str;
251 for(
typename T::const_iterator
i = v.begin();
i != v.end(); ++
i) {
256 str << std::string(
indent,
' ') << bullet <<
' ' << *
i;
272 std::string
indent(
const std::string&
string, std::size_t indent_size = 4);
290 std::pair<int, int>
parse_range(
const std::string& str);
311 std::vector<std::pair<double, double>>
parse_ranges_real(
const std::string& str);
313 int apply_modifier(
const int number,
const std::string &amount,
const int minimum = 0);
318 return mod[0] ==
'-' ? (
font::unicode_minus + std::string(mod.begin() + 1, mod.end())) : (
"+" + mod);
322 std::string
escape(
const std::string &str,
const char *special_chars);
330 inline std::string
escape(
const std::string &str)
332 return escape(str,
"#@{}+-,\\*=");
336 std::string
unescape(
const std::string &str);
339 std::string
urlencode(
const std::string &str);
342 inline std::string
quote(
const std::string &str)
344 return '"' + str +
'"';
348 bool string_bool(
const std::string& str,
bool def=
false);
371 std::string
si_string(
double input,
bool base2,
const std::string&
unit);
387 bool word_completion(std::string& text, std::vector<std::string>& wordlist);
390 bool word_match(
const std::string& message,
const std::string& word);
This class represents a single unit of a specific type.
const std::string unicode_bullet
const std::string unicode_minus
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
@ STRIP_SPACES
REMOVE_EMPTY: remove empty elements.
std::vector< std::string_view > split_view(std::string_view s, const char sep, const int flags)
std::string si_string(double input, bool base2, const std::string &unit)
Convert into a string with an SI-postfix.
void trim(std::string_view &s)
std::string indent(const std::string &string, std::size_t indent_size)
Indent a block of text.
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.
bool isvalid_wildcard(const std::string &username)
Check if the username pattern contains only valid characters.
std::set< std::string > split_set(std::string_view s, char sep, const int flags)
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 join_map(const T &v, const std::string &major=",", const std::string &minor=":")
std::vector< std::pair< int, int > > parse_ranges_int(const std::string &str)
Handles a comma-separated list of inputs to parse_range.
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.
void split_foreach_impl(std::string_view s, char sep, const F &f)
std::pair< int, int > parse_range(const std::string &str)
Recognises the following patterns, and returns a {min, max} pair.
std::vector< std::string > parenthetical_split(std::string_view val, const char separator, std::string_view left, std::string_view right, const int flags)
Splits a string based either on a separator, except then the text appears within specified parenthesi...
const std::vector< std::string > res_order
std::string half_signed_value(int val)
Sign with Unicode "−" if negative.
std::string bool_string(const bool value)
Converts a bool value to 'true' or 'false'.
std::string urlencode(const std::string &str)
Percent-escape characters in a UTF-8 string intended to be part of a URL.
std::map< std::string, t_string, res_compare > string_map_res
std::string quote(const std::string &str)
Surround the string 'str' with double quotes.
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.
std::vector< std::pair< int, int > > parse_ranges_unsigned(const std::string &str)
Handles a comma-separated list of inputs to parse_range, in a context that does not expect negative v...
void to_sql_wildcards(std::string &str, bool underscores)
Converts '*' to '' and optionally escapes '_'.
void split_foreach(std::string_view s, char sep, const int flags, const F &f)
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,...
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.
bool isvalid_username(const std::string &username)
Check if the username contains only valid characters.
std::string unescape(const std::string &str)
Remove all escape characters (backslash)
bool portable_isspace(const char c)
int apply_modifier(const int number, const std::string &amount, const int minimum)
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.
bool isnewline(const char c)
bool notspace(const char c)
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::string escape(const std::string &str, const char *special_chars)
Prepends a configurable set of characters with a backslash.
std::vector< std::pair< double, double > > parse_ranges_real(const std::string &str)
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
std::string signed_value(int val)
Convert into a signed value (using the Unicode "−" and +0 convention.
std::map< std::string, t_string > string_map
std::string signed_percent(int val)
Convert into a percentage (using the Unicode "−" and +0% convention.
std::vector< std::string > split(const config_attribute_value &val)
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of 'text' with the 'wordlist'.
std::string print_modifier(const std::string &mod)
Add a "+" or replace the "-" par Unicode minus.
std::pair< double, double > parse_range_real(const std::string &str)
Recognises similar patterns to parse_range, and returns a {min, max} pair.
bool operator()(const std::string &a, const std::string &b) const
Returns whether a < b, considering res_order.
static map_location::direction s