The Battle for Wesnoth  1.15.0+dev
Namespaces | Typedefs | Enumerations | Functions
string_utils.hpp File Reference
#include "font/constants.hpp"
#include "serialization/string_view.hpp"
#include <algorithm>
#include <map>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
Include dependency graph for string_utils.hpp:

Go to the source code of this file.

Namespaces

 utils
 

Typedefs

using utils::string_map = std::map< std::string, t_string >
 

Enumerations

enum  { utils::REMOVE_EMPTY = 0x01, utils::STRIP_SPACES = 0x02 }
 

Functions

bool utils::isnewline (const char c)
 
bool utils::portable_isspace (const char c)
 
bool utils::notspace (const char c)
 
std::vector< std::string > utils::split (const std::string &val, const char c, const int flags)
 Splits a (comma-)separated string into a vector of pieces. 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::set< std::string > utils::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. 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 (const std::string &val, const char separator=0, const std::string &left="(", const std::string &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...
 
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::pair< string_view, string_view > utils::vertical_split (const std::string &val)
 Splits a string into two parts as evenly as possible based on lines. More...
 
template<typename T >
std::string utils::join (const T &v, const std::string &s=",")
 Generates a new string joining container items in a list. More...
 
template<typename T >
std::string utils::join_map (const T &v, const std::string &major=",", const std::string &minor=":")
 
template<typename T >
std::string utils::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. More...
 
std::string utils::indent (const std::string &string, std::size_t indent_size=4)
 Indent a block of text. More...
 
std::pair< int, int > utils::parse_range (const std::string &str)
 
std::vector< std::pair< int, int > > utils::parse_ranges (const std::string &str)
 
int utils::apply_modifier (const int number, const std::string &amount, const int minimum)
 
std::string utils::print_modifier (const std::string &mod)
 Add a "+" or replace the "-" par Unicode minus. More...
 
std::string utils::escape (const std::string &str, const char *special_chars)
 Prepends a configurable set of characters with a backslash. More...
 
std::string utils::escape (const std::string &str)
 Prepend all special characters with a backslash. More...
 
std::string utils::unescape (const std::string &str)
 Remove all escape characters (backslash) More...
 
std::string utils::urlencode (const std::string &str)
 Percent-escape characters in a UTF-8 string intended to be part of a URL. More...
 
std::string utils::quote (const std::string &str)
 Surround the string 'str' with double quotes. 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::signed_percent (int val)
 Convert into a percentage (using the Unicode "−" and +0% convention. 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::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...
 
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...
 
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...