The Battle for Wesnoth  1.19.7+dev
Namespaces | Macros | Functions | Variables
string_utils.cpp File Reference

Various string-routines. More...

#include "gettext.hpp"
#include "log.hpp"
#include "serialization/string_utils.hpp"
#include "serialization/unicode.hpp"
#include "utils/charconv.hpp"
#include "utils/general.hpp"
#include <array>
#include <limits>
#include "utils/optional_fwd.hpp"
#include <stdexcept>
#include <boost/algorithm/string.hpp>
Include dependency graph for string_utils.cpp:

Go to the source code of this file.

Namespaces

 utils
 

Macros

#define ERR_GENERAL   LOG_STREAM(err, lg::general())
 
#define ERR_NG   LOG_STREAM(err, log_engine)
 

Functions

bool utils::isnewline (const char c)
 
bool utils::portable_isspace (const char c)
 
bool utils::notspace (const char c)
 
void utils::trim (std::string_view &s)
 
std::vector< std::string > utils::split (std::string_view s, const char sep, const int flags)
 Splits a (comma-)separated string into a vector of pieces. More...
 
std::set< std::string > utils::split_set (std::string_view s, char sep, const int flags)
 
std::vector< std::string_view > utils::split_view (std::string_view s, const char sep, const int flags)
 
std::vector< std::string > utils::square_parenthetical_split (const std::string &val, const char separator=',', const std::string &left="([", const std::string &right=")]", const int flags=REMOVE_EMPTY|STRIP_SPACES)
 Similar to parenthetical_split, but also expands embedded square brackets. More...
 
std::map< std::string, std::string > utils::map_split (const std::string &val, char major=',', char minor=':', int flags=REMOVE_EMPTY|STRIP_SPACES, const std::string &default_value="")
 Splits a string based on two separators into a map. More...
 
std::vector< std::string > utils::parenthetical_split (std::string_view val, const char separator=0, std::string_view left="(", std::string_view right=")", const int flags=REMOVE_EMPTY|STRIP_SPACES)
 Splits a string based either on a separator, except then the text appears within specified parenthesis. More...
 
int utils::apply_modifier (const int number, const std::string &amount, const int minimum)
 
std::string utils::escape (std::string_view str, const char *special_chars)
 Prepends a configurable set of characters with a backslash. More...
 
static void utils::si_string_impl_stream_write (std::stringstream &ss, double input)
 
static bool utils::is_username_char (char c)
 
static bool utils::is_wildcard_char (char c)
 
static bool utils::is_word_boundary (char c)
 
std::string utils::indent (const std::string &string, std::size_t indent_size=4)
 Indent a block of text. More...
 
std::vector< std::string > utils::quoted_split (const std::string &val, char c=',', int flags=REMOVE_EMPTY|STRIP_SPACES, char quote='\\')
 This function is identical to split(), except it does not split when it otherwise would if the previous character was identical to the parameter 'quote' (i.e. More...
 
std::pair< int, int > utils::parse_range (std::string_view str)
 Recognises the following patterns, and returns a {min, max} pair. More...
 
std::pair< double, double > utils::parse_range_real (std::string_view str)
 Recognises similar patterns to parse_range, and returns a {min, max} pair. More...
 
std::vector< std::pair< int, int > > utils::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 values. More...
 
std::vector< std::pair< double, double > > utils::parse_ranges_real (const std::string &str)
 
std::vector< std::pair< int, int > > utils::parse_ranges_int (const std::string &str)
 Handles a comma-separated list of inputs to parse_range. More...
 
std::string utils::unescape (std::string_view str)
 Remove all escape characters (backslash) More...
 
std::string utils::urlencode (std::string_view str)
 Percent-escape characters in a UTF-8 string intended to be part of a URL. More...
 
bool utils::string_bool (const std::string &str, bool def=false)
 Convert no, false, off, 0, 0.0 to false, empty to def, and others to true. More...
 
std::string utils::bool_string (const bool value)
 Converts a bool value to 'true' or 'false'. More...
 
std::string utils::signed_value (int val)
 Convert into a signed value (using the Unicode "−" and +0 convention. More...
 
std::string utils::half_signed_value (int val)
 Sign with Unicode "−" if negative. More...
 
std::string utils::si_string (double input, bool base2, const std::string &unit)
 Convert into a string with an SI-postfix. More...
 
bool utils::isvalid_username (const std::string &login)
 Check if the username contains only valid characters. More...
 
bool utils::isvalid_wildcard (const std::string &login)
 Check if the username pattern contains only valid characters. More...
 
bool utils::word_completion (std::string &text, std::vector< std::string > &wordlist)
 Try to complete the last word of 'text' with the 'wordlist'. More...
 
bool utils::word_match (const std::string &message, const std::string &word)
 Check if a message contains a word. More...
 
bool utils::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. More...
 
void utils::to_sql_wildcards (std::string &str, bool underscores=true)
 Converts '*' to '' and optionally escapes '_'. More...
 
void utils::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. More...
 

Variables

static lg::log_domain log_engine ("engine")
 

Detailed Description

Various string-routines.

Definition in file string_utils.cpp.

Macro Definition Documentation

◆ ERR_GENERAL

#define ERR_GENERAL   LOG_STREAM(err, lg::general())

Definition at line 37 of file string_utils.cpp.

◆ ERR_NG

#define ERR_NG   LOG_STREAM(err, log_engine)

Definition at line 38 of file string_utils.cpp.

Variable Documentation

◆ log_engine

lg::log_domain log_engine("engine") ( "engine"  )
static