The Battle for Wesnoth  1.15.0-dev
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
utils Namespace Reference

Namespaces

 detail
 

Classes

class  basic_string_view
 
class  bcrypt
 
struct  const_clone
 Helper struct to clone the constness of one type to another. More...
 
class  hash_base
 
class  hash_digest
 
struct  hash_error
 
class  md5
 
class  scope_exit
 
class  sha1
 
class  string_map_variable_set
 

Typedefs

using string_map = std::map< std::string, t_string >
 
typedef basic_string_view< char, std::char_traits< char > > string_view
 
typedef basic_string_view< uint8_t, std::char_traits< uint8_t > > byte_string_view
 
typedef basic_string_view< wchar_t, std::char_traits< wchar_t > > wstring_view
 
typedef basic_string_view< char16_t, std::char_traits< char16_t > > u16string_view
 
typedef basic_string_view< char32_t, std::char_traits< char32_t > > u32string_view
 
template<typename D , typename S >
using const_clone_t = typename const_clone< D, S >::type
 
template<typename D , typename S >
using const_clone_ref = typename const_clone< D, S >::reference
 
template<typename D , typename S >
using const_clone_ptr = typename const_clone< D, S >::pointer
 

Enumerations

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

Functions

std::string format_time_summary (std::time_t t)
 
std::string interpolate_variables_into_string (const std::string &str, const string_map *const symbols)
 Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent symbols in the given symbol table. More...
 
std::string interpolate_variables_into_string (const std::string &str, const std::map< std::string, std::string > *const symbols)
 
std::string interpolate_variables_into_string (const std::string &str, const variable_set &variables)
 
t_string interpolate_variables_into_tstring (const t_string &str, const variable_set &variables)
 Function that does the same as the above, for t_stringS. More...
 
std::string format_conjunct_list (const t_string &empty, const std::vector< t_string > &elems)
 Format a conjunctive list. More...
 
std::string format_disjunct_list (const t_string &empty, const std::vector< t_string > &elems)
 Format a disjunctive list. More...
 
bool might_contain_variables (const std::string &str)
 Determines if a string might contain variables to interpolate. More...
 
bool isnewline (const char c)
 
bool portable_isspace (const char c)
 
bool notspace (const char c)
 
std::vector< std::string > 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 > 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 > 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 > 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::pair< string_view, string_viewvertical_split (const std::string &val)
 Splits a string into two parts as evenly as possible based on lines. More...
 
int apply_modifier (const int number, const std::string &amount, const int minimum)
 
std::string escape (const std::string &str, const char *special_chars)
 Prepends a configurable set of characters with a backslash. More...
 
static void si_string_impl_stream_write (std::stringstream &ss, double input)
 
static bool is_username_char (char c)
 
static bool is_wildcard_char (char c)
 
static bool is_word_boundary (char c)
 
std::string indent (const std::string &string, std::size_t indent_size=4)
 Indent a block of text. More...
 
std::vector< std::string > 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 > parse_range (const std::string &str)
 
std::vector< std::pair< int, int > > parse_ranges (const std::string &str)
 
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. More...
 
template<typename T >
std::string join (const T &v, const std::string &s=",")
 Generates a new string joining container items in a list. More...
 
template<typename T >
std::string join_map (const T &v, const std::string &major=",", const std::string &minor=":")
 
template<typename T >
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. More...
 
std::string print_modifier (const std::string &mod)
 Add a "+" or replace the "-" par Unicode minus. More...
 
template<typename charT , typename traits >
bool operator== (basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator!= (basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator< (basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator> (basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator<= (basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator>= (basic_string_view< charT, traits > x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator== (basic_string_view< charT, traits > x, const std::basic_string< charT, traits, Allocator > &y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator== (const std::basic_string< charT, traits, Allocator > &x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator== (basic_string_view< charT, traits > x, const charT *y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator== (const charT *x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator!= (basic_string_view< charT, traits > x, const std::basic_string< charT, traits, Allocator > &y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator!= (const std::basic_string< charT, traits, Allocator > &x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator!= (basic_string_view< charT, traits > x, const charT *y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator!= (const charT *x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator< (basic_string_view< charT, traits > x, const std::basic_string< charT, traits, Allocator > &y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator< (const std::basic_string< charT, traits, Allocator > &x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator< (basic_string_view< charT, traits > x, const charT *y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator< (const charT *x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator> (basic_string_view< charT, traits > x, const std::basic_string< charT, traits, Allocator > &y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator> (const std::basic_string< charT, traits, Allocator > &x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator> (basic_string_view< charT, traits > x, const charT *y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator> (const charT *x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator<= (basic_string_view< charT, traits > x, const std::basic_string< charT, traits, Allocator > &y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator<= (const std::basic_string< charT, traits, Allocator > &x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator<= (basic_string_view< charT, traits > x, const charT *y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator<= (const charT *x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator>= (basic_string_view< charT, traits > x, const std::basic_string< charT, traits, Allocator > &y) BOOST_NOEXCEPT
 
template<typename charT , typename traits , typename Allocator >
bool operator>= (const std::basic_string< charT, traits, Allocator > &x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator>= (basic_string_view< charT, traits > x, const charT *y) BOOST_NOEXCEPT
 
template<typename charT , typename traits >
bool operator>= (const charT *x, basic_string_view< charT, traits > y) BOOST_NOEXCEPT
 
template<class charT , class traits >
std::basic_ostream< charT, traits > & operator<< (std::basic_ostream< charT, traits > &os, const basic_string_view< charT, traits > &str)
 
template<typename T >
constexpr const T & clamp (const T &value, const T &min, const T &max)
 
template<typename Container , typename Value >
bool contains (const Container &container, const Value &value)
 Returns true iff value is found in container. More...
 
std::string unescape (const std::string &str)
 Remove all escape characters (backslash) More...
 
std::string urlencode (const std::string &str)
 Percent-escape characters in a UTF-8 string intended to be part of a URL. More...
 
bool 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 bool_string (const bool value)
 Converts a bool value to 'true' or 'false'. More...
 
std::string signed_value (int val)
 Convert into a signed value (using the Unicode "−" and +0 convention. More...
 
std::string half_signed_value (int val)
 Sign with Unicode "−" if negative. More...
 
std::string si_string (double input, bool base2, const std::string &unit)
 Convert into a string with an SI-postfix. More...
 
bool isvalid_username (const std::string &login)
 Check if the username contains only valid characters. More...
 
bool isvalid_wildcard (const std::string &login)
 Check if the username pattern contains only valid characters. More...
 
bool word_completion (std::string &text, std::vector< std::string > &wordlist)
 Try to complete the last word of 'text' with the 'wordlist'. More...
 
bool word_match (const std::string &message, const std::string &word)
 Check if a message contains a word. More...
 
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. More...
 
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. More...
 
std::string escape (const std::string &str)
 Prepend all special characters with a backslash. More...
 
std::string quote (const std::string &str)
 Surround the string 'str' with double quotes. More...
 
std::string signed_percent (int val)
 Convert into a percentage (using the Unicode "−" and +0% convention. More...
 

Variables

template<typename Base , typename Derived >
static constexpr bool is_base_of_v = std::is_base_of<Base, Derived>::value
 
template<typename T , typename U >
static constexpr bool is_same_v = std::is_same<T, U>::value
 

Typedef Documentation

◆ byte_string_view

typedef basic_string_view<uint8_t, std::char_traits<uint8_t> > utils::byte_string_view

Definition at line 610 of file string_view.hpp.

◆ const_clone_ptr

template<typename D , typename S >
using utils::const_clone_ptr = typedef typename const_clone<D, S>::pointer

Definition at line 65 of file const_clone.hpp.

◆ const_clone_ref

template<typename D , typename S >
using utils::const_clone_ref = typedef typename const_clone<D, S>::reference

Definition at line 62 of file const_clone.hpp.

◆ const_clone_t

template<typename D , typename S >
using utils::const_clone_t = typedef typename const_clone<D, S>::type

Definition at line 59 of file const_clone.hpp.

◆ string_map

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

Definition at line 34 of file string_utils.hpp.

◆ string_view

typedef basic_string_view<char, std::char_traits<char> > utils::string_view

Definition at line 609 of file string_view.hpp.

◆ u16string_view

typedef basic_string_view<char16_t, std::char_traits<char16_t> > utils::u16string_view

Definition at line 614 of file string_view.hpp.

◆ u32string_view

typedef basic_string_view<char32_t, std::char_traits<char32_t> > utils::u32string_view

Definition at line 618 of file string_view.hpp.

◆ wstring_view

typedef basic_string_view<wchar_t, std::char_traits<wchar_t> > utils::wstring_view

Definition at line 611 of file string_view.hpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
REMOVE_EMPTY 
STRIP_SPACES 

REMOVE_EMPTY: remove empty elements.

Definition at line 40 of file string_utils.hpp.

Function Documentation

◆ apply_modifier()

int utils::apply_modifier ( const int  number,
const std::string &  amount,
const int  minimum 
)

◆ bool_string()

std::string utils::bool_string ( const bool  value)

◆ bullet_list()

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.

List items are preceded by the indentation blanks, a bullet string and another blank; all but the last item are followed by a newline.

Parameters
vA container with elements.
indentNumber of indentation blanks.
bulletThe leading bullet string.

Definition at line 213 of file string_utils.hpp.

References apply_modifier(), i, indent(), parse_range(), and parse_ranges().

Referenced by addons_client::do_check_before_overwriting_addon(), and addons_client::do_resolve_addon_dependencies().

◆ clamp()

template<typename T >
constexpr const T& utils::clamp ( const T &  value,
const T &  min,
const T &  max 
)

◆ contains()

template<typename Container , typename Value >
bool utils::contains ( const Container &  container,
const Value value 
)
inline

Returns true iff value is found in container.

This should work whenever Container "looks like" an STL container of Values. Normally this uses std::find(), but a simulated partial template specialization exists when Value is Container::key_type. In this case, Container is assumed an associative container, and the member function find() is used.

Definition at line 78 of file general.hpp.

References utils::detail::contains_impl< Container, Value >::eval().

Referenced by actions::check_recruit_location(), events::menu_handler::do_recruit(), and actions::find_recall_location().

◆ ellipsis_truncate()

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.

Definition at line 849 of file string_utils.cpp.

References font::ellipsis, and utf8::truncate().

Referenced by windows_tray_notification::adjust_length(), gui2::dialogs::game_load::pre_show(), gui2::dialogs::file_dialog::push_fileview_row(), and signed_percent().

◆ escape() [1/2]

std::string utils::escape ( const std::string &  str)
inline

Prepend all special characters with a backslash.

Special characters are: #}+-,*=

Definition at line 261 of file string_utils.hpp.

References escape(), unescape(), and urlencode().

◆ escape() [2/2]

std::string utils::escape ( const std::string &  str,
const char *  special_chars 
)

Prepends a configurable set of characters with a backslash.

Definition at line 437 of file string_utils.cpp.

Referenced by help::escape(), escape(), get_file_code(), and print_modifier().

◆ format_conjunct_list()

std::string utils::format_conjunct_list ( const t_string empty,
const std::vector< t_string > &  elems 
)

Format a conjunctive list.

Parameters
emptyThe string to return for an empty list
elemsThe list of entries in the list
Returns
The elements of the list joined by "and".

Definition at line 246 of file string_utils.cpp.

References i, and VGETTEXT.

Referenced by unit::add_modification(), unit::describe_builtin_effect(), attack_type::describe_modification(), intf_format_list(), might_contain_variables(), gui2::multimenu_button::update_label(), and user_choice_manager::update_local_choice().

◆ format_disjunct_list()

std::string utils::format_disjunct_list ( const t_string empty,
const std::vector< t_string > &  elems 
)

Format a disjunctive list.

Parameters
emptyThe string to return for an empty list
elemsThe list of entries in the list
Returns
The elements of the list joined or "and".

Definition at line 264 of file string_utils.cpp.

References i, and VGETTEXT.

Referenced by intf_format_list(), and might_contain_variables().

◆ format_time_summary()

std::string utils::format_time_summary ( std::time_t  t)

◆ half_signed_value()

std::string utils::half_signed_value ( int  val)

◆ indent()

std::string utils::indent ( const std::string &  string,
std::size_t  indent_size = 4 
)

Indent a block of text.

Only lines with content are changed; empty lines are left intact. However, if string is an empty string itself, the indentation unit with the specified indent_size will be returned instead.

Parameters
stringText to indent.
indent_sizeNumber of indentation units to use.

Definition at line 751 of file string_utils.cpp.

References split().

Referenced by bullet_list(), and gui2::dialogs::wml_error::wml_error().

◆ interpolate_variables_into_string() [1/3]

std::string utils::interpolate_variables_into_string ( const std::string &  str,
const string_map *const  symbols 
)

◆ interpolate_variables_into_string() [2/3]

std::string utils::interpolate_variables_into_string ( const std::string &  str,
const std::map< std::string, std::string > *const  symbols 
)

Definition at line 224 of file string_utils.cpp.

References do_interpolation().

◆ interpolate_variables_into_string() [3/3]

std::string utils::interpolate_variables_into_string ( const std::string &  str,
const variable_set variables 
)

Definition at line 230 of file string_utils.cpp.

References do_interpolation().

◆ interpolate_variables_into_tstring()

t_string utils::interpolate_variables_into_tstring ( const t_string str,
const variable_set variables 
)

Function that does the same as the above, for t_stringS.

If a change was made, then the t_string's translation is done in this function, rather than at use. This limitation is due to the use of create-time interpolation, rather than use-time.

Definition at line 235 of file string_utils.cpp.

References interpolate_variables_into_string(), and t_string::str().

Referenced by vconfig::has_child(), intf_format(), might_contain_variables(), and terrain_label::read().

◆ is_username_char()

static bool utils::is_username_char ( char  c)
static

Definition at line 612 of file string_utils.cpp.

Referenced by isvalid_username(), and isvalid_wildcard().

◆ is_wildcard_char()

static bool utils::is_wildcard_char ( char  c)
static

Definition at line 616 of file string_utils.cpp.

Referenced by isvalid_wildcard().

◆ is_word_boundary()

static bool utils::is_word_boundary ( char  c)
static

Definition at line 694 of file string_utils.cpp.

Referenced by word_match().

◆ isnewline()

bool utils::isnewline ( const char  c)

◆ isvalid_username()

bool utils::isvalid_username ( const std::string &  login)

Check if the username contains only valid characters.

(all alpha-numeric characters plus underscore and hyphen)

Definition at line 620 of file string_utils.cpp.

References is_username_char().

Referenced by suh::check_name(), suh::check_password(), wesnothd::server::is_login_allowed(), signed_percent(), and wesnothd::server::status_handler().

◆ isvalid_wildcard()

bool utils::isvalid_wildcard ( const std::string &  login)

Check if the username pattern contains only valid characters.

(all alpha-numeric characters plus underscore, hyphen, question mark and asterisk)

Definition at line 632 of file string_utils.cpp.

References is_username_char(), and is_wildcard_char().

Referenced by preferences::add_acquaintance(), and signed_percent().

◆ join()

template<typename T >
std::string utils::join ( const T &  v,
const std::string &  s = "," 
)

Generates a new string joining container items in a list.

Parameters
vA container with elements.
sList delimiter.

Definition at line 170 of file string_utils.hpp.

References i, next, and s.

Referenced by wesnothd::server::accepting_connections(), game_events::event_handlers::add_event_handler(), gui2::dialogs::add_unit_entry(), team::allied_human_teams(), attack_info(), BOOST_AUTO_TEST_CASE(), gui2::chatbox::chat_input_keypress_callback(), create_terrain_maps(), gui2::dialogs::depcheck_confirm_change::depcheck_confirm_change(), campaignd::control_line::full(), help::generate_faction_topics(), help::generate_unit_topics(), ai::holder::get_ai_overview(), hotkey::get_names(), carryover::get_recruits(), wesnothd::server::handle_player_in_lobby(), campaignd::server::handle_upload(), events::map_command_handler< chat_command_handler >::help_command(), game_config_manager::load_addons_cfg(), editor::mouse_action_unit::move(), gui2::dialogs::faction_select::on_faction_select(), operator<<(), gui2::dialogs::terrain_layers::pre_show(), gui2::dialogs::unit_list::pre_show(), wesnothd::server::read_version(), events::sdl_handler::requires_event_focus(), gui2::unit_preview_pane::set_displayed_unit(), preferences::set_modifications(), mp_game_settings::to_config(), game_classification::to_config(), ai::default_recruitment::recruit_job::to_config(), ai::default_recruitment::recruit_limit::to_config(), editor::map_context::to_config(), carryover::transfer_all_recruits_to(), unit_level(), unit_type_data::unit_type_data(), addons_client::upload_addon(), ai::config_value_translator< std::vector< std::string > >::value_to_cfg(), team::team_info::write(), addon_info::write(), unit::write(), game_events::manager::write_events(), addon_info::write_minimal(), game_data::write_snapshot(), write_str_int_map(), and preferences::manager::~manager().

◆ join_map()

template<typename T >
std::string utils::join_map ( const T &  v,
const std::string &  major = ",",
const std::string &  minor = ":" 
)

Definition at line 185 of file string_utils.hpp.

References i, and next.

Referenced by ng::connect_engine::save_reserved_sides_information(), and mp_game_settings::to_config().

◆ map_split()

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.

Major: the separator between elements of the map Minor: the separator between keys and values in one element

For example, the string 'a:b,c:d,e:f' would be parsed into: a => b c => d e => f

Definition at line 262 of file string_utils.cpp.

References i, and split().

Referenced by ng::connect_engine::load_previous_sides_users(), ng::connect_engine::save_reserved_sides_information(), and set_split().

◆ might_contain_variables()

bool utils::might_contain_variables ( const std::string &  str)
inline

Determines if a string might contain variables to interpolate.

This can allow one to skip future interpolations (plural – if there is only one interpolation, the savings are not worth this check). In this spirit, precision is sacrificed in the name of efficiency; the check is quick and allows false positives, but there are no false negatives. (A false negative would lead to incorrect behavior, whereas a false positive leads to merely inefficient behavior.) In practice, false positives should be uncommon enough to not worry about.

Definition at line 41 of file string_utils.hpp.

References format_conjunct_list(), format_disjunct_list(), interpolate_variables_into_string(), interpolate_variables_into_tstring(), vgettext_impl(), and vngettext_impl().

Referenced by game_events::event_handlers::add_event_handler(), and game_events::manager::execute_on_events().

◆ notspace()

bool utils::notspace ( const char  c)

Definition at line 56 of file string_utils.cpp.

References portable_isspace().

◆ operator!=() [1/5]

template<typename charT , typename traits >
bool utils::operator!= ( basic_string_view< charT, traits >  x,
basic_string_view< charT, traits >  y 
)
inline

◆ operator!=() [2/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator!= ( basic_string_view< charT, traits >  x,
const std::basic_string< charT, traits, Allocator > &  y 
)
inline

Definition at line 442 of file string_view.hpp.

◆ operator!=() [3/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator!= ( const std::basic_string< charT, traits, Allocator > &  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 448 of file string_view.hpp.

◆ operator!=() [4/5]

template<typename charT , typename traits >
bool utils::operator!= ( basic_string_view< charT, traits >  x,
const charT *  y 
)
inline

Definition at line 454 of file string_view.hpp.

◆ operator!=() [5/5]

template<typename charT , typename traits >
bool utils::operator!= ( const charT *  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 460 of file string_view.hpp.

◆ operator<() [1/5]

template<typename charT , typename traits >
bool utils::operator< ( basic_string_view< charT, traits >  x,
basic_string_view< charT, traits >  y 
)
inline

◆ operator<() [2/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator< ( basic_string_view< charT, traits >  x,
const std::basic_string< charT, traits, Allocator > &  y 
)
inline

Definition at line 466 of file string_view.hpp.

◆ operator<() [3/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator< ( const std::basic_string< charT, traits, Allocator > &  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 472 of file string_view.hpp.

◆ operator<() [4/5]

template<typename charT , typename traits >
bool utils::operator< ( basic_string_view< charT, traits >  x,
const charT *  y 
)
inline

Definition at line 478 of file string_view.hpp.

◆ operator<() [5/5]

template<typename charT , typename traits >
bool utils::operator< ( const charT *  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 484 of file string_view.hpp.

◆ operator<<()

template<class charT , class traits >
std::basic_ostream<charT, traits>& utils::operator<< ( std::basic_ostream< charT, traits > &  os,
const basic_string_view< charT, traits > &  str 
)
inline

Definition at line 595 of file string_view.hpp.

References utf8::size(), utils::detail::sv_insert_aligned(), and w.

◆ operator<=() [1/5]

template<typename charT , typename traits >
bool utils::operator<= ( basic_string_view< charT, traits >  x,
basic_string_view< charT, traits >  y 
)
inline

◆ operator<=() [2/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator<= ( basic_string_view< charT, traits >  x,
const std::basic_string< charT, traits, Allocator > &  y 
)
inline

Definition at line 514 of file string_view.hpp.

◆ operator<=() [3/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator<= ( const std::basic_string< charT, traits, Allocator > &  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 520 of file string_view.hpp.

◆ operator<=() [4/5]

template<typename charT , typename traits >
bool utils::operator<= ( basic_string_view< charT, traits >  x,
const charT *  y 
)
inline

Definition at line 526 of file string_view.hpp.

◆ operator<=() [5/5]

template<typename charT , typename traits >
bool utils::operator<= ( const charT *  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 532 of file string_view.hpp.

◆ operator==() [1/5]

template<typename charT , typename traits >
bool utils::operator== ( basic_string_view< charT, traits >  x,
basic_string_view< charT, traits >  y 
)
inline

◆ operator==() [2/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator== ( basic_string_view< charT, traits >  x,
const std::basic_string< charT, traits, Allocator > &  y 
)
inline

Definition at line 418 of file string_view.hpp.

◆ operator==() [3/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator== ( const std::basic_string< charT, traits, Allocator > &  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 424 of file string_view.hpp.

◆ operator==() [4/5]

template<typename charT , typename traits >
bool utils::operator== ( basic_string_view< charT, traits >  x,
const charT *  y 
)
inline

Definition at line 430 of file string_view.hpp.

◆ operator==() [5/5]

template<typename charT , typename traits >
bool utils::operator== ( const charT *  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 436 of file string_view.hpp.

◆ operator>() [1/5]

template<typename charT , typename traits >
bool utils::operator> ( basic_string_view< charT, traits >  x,
basic_string_view< charT, traits >  y 
)
inline

◆ operator>() [2/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator> ( basic_string_view< charT, traits >  x,
const std::basic_string< charT, traits, Allocator > &  y 
)
inline

Definition at line 490 of file string_view.hpp.

◆ operator>() [3/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator> ( const std::basic_string< charT, traits, Allocator > &  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 496 of file string_view.hpp.

◆ operator>() [4/5]

template<typename charT , typename traits >
bool utils::operator> ( basic_string_view< charT, traits >  x,
const charT *  y 
)
inline

Definition at line 502 of file string_view.hpp.

◆ operator>() [5/5]

template<typename charT , typename traits >
bool utils::operator> ( const charT *  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 508 of file string_view.hpp.

◆ operator>=() [1/5]

template<typename charT , typename traits >
bool utils::operator>= ( basic_string_view< charT, traits >  x,
basic_string_view< charT, traits >  y 
)
inline

◆ operator>=() [2/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator>= ( basic_string_view< charT, traits >  x,
const std::basic_string< charT, traits, Allocator > &  y 
)
inline

Definition at line 538 of file string_view.hpp.

◆ operator>=() [3/5]

template<typename charT , typename traits , typename Allocator >
bool utils::operator>= ( const std::basic_string< charT, traits, Allocator > &  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 544 of file string_view.hpp.

◆ operator>=() [4/5]

template<typename charT , typename traits >
bool utils::operator>= ( basic_string_view< charT, traits >  x,
const charT *  y 
)
inline

Definition at line 550 of file string_view.hpp.

◆ operator>=() [5/5]

template<typename charT , typename traits >
bool utils::operator>= ( const charT *  x,
basic_string_view< charT, traits >  y 
)
inline

Definition at line 556 of file string_view.hpp.

◆ parenthetical_split()

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.

If the separator is "0" (default), it splits a string into an odd number of parts:

  • The part before the first '(',
  • the part between the first '('
  • and the matching right ')', etc ... and the remainder of the string.

Note that one can use the same character for both the left and right parenthesis, which usually makes the most sense for this function.

Note that this will find the first matching char in the left string and match against the corresponding char in the right string. A correctly processed string should return a vector with an odd number of elements. Empty elements are never removed as they are placeholders, hence REMOVE EMPTY only works for the separator split.

INPUT: ("a(b)c{d}e(f{g})h", 0, "({", ")}") RETURNS: {"a", "b", "c", "d", "e", "f{g}", "h"}

Definition at line 293 of file string_utils.cpp.

References ERR_GENERAL, i, left, portable_isspace(), REMOVE_EMPTY, right, and STRIP_SPACES.

Referenced by unit::apply_builtin_effect(), image::create_texture_from_sub_file(), image::modification::decode(), wfl::string_callable::get_value(), unit::init(), ai::manager::internal_evaluate_command(), intf_name_generator(), image::load_image_sub_file(), set_split(), and image::modification_queue::top().

◆ parse_range()

std::pair< int, int > utils::parse_range ( const std::string &  str)

Definition at line 823 of file string_utils.cpp.

References a, and b.

Referenced by bullet_list(), gamemap::parse_location_range(), and parse_ranges().

◆ parse_ranges()

std::vector< std::pair< int, int > > utils::parse_ranges ( const std::string &  str)

◆ portable_isspace()

bool utils::portable_isspace ( const char  c)

◆ print_modifier()

std::string utils::print_modifier ( const std::string &  mod)
inline

Add a "+" or replace the "-" par Unicode minus.

Definition at line 247 of file string_utils.hpp.

References escape(), and font::unicode_minus.

Referenced by unit::describe_builtin_effect(), and attack_type::describe_modification().

◆ quote()

std::string utils::quote ( const std::string &  str)
inline

Surround the string 'str' with double quotes.

Definition at line 273 of file string_utils.hpp.

References bool_string(), half_signed_value(), signed_value(), and string_bool().

◆ quoted_split()

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.

it does not split quoted commas). This method was added to make it possible to quote user input, particularly so commas in user input would not cause visual problems in menus.

Todo:
Why not change split()? That would change the methods post condition.

Definition at line 784 of file string_utils.cpp.

References REMOVE_EMPTY, and STRIP_SPACES.

Referenced by preprocessor_data::get_chunk(), preprocessor_streambuf::get_current_file(), get_location(), help::section::initialize(), lineno_string(), and help::section::print_table_of_contents_for().

◆ set_split()

std::set<std::string> utils::set_split ( const std::string &  val,
const char  c = ',',
const int  flags = REMOVE_EMPTY | STRIP_SPACES 
)
inline

Splits a (comma-)separated string into a set of pieces.

See split() for the meanings of the parameters.

Definition at line 62 of file string_utils.hpp.

References c, left, map_split(), parenthetical_split(), REMOVE_EMPTY, right, split(), square_parenthetical_split(), STRIP_SPACES, and vertical_split().

◆ si_string()

std::string utils::si_string ( double  input,
bool  base2,
const std::string &  unit 
)

Convert into a string with an SI-postfix.

If the unit is to be translatable, a t_string should be passed as the third argument. _("unit_byte^B") is suggested as standard.

There are no default values because they would not be translatable.

Definition at line 551 of file string_utils.cpp.

References _(), and si_string_impl_stream_write().

Referenced by gui2::dialogs::network_transmission::pump_monitor::process(), gui2::dialogs::screenshot_notification::save_screenshot(), signed_percent(), size_display_string(), and gui2::dialogs::game_cache_options::update_cache_size_display().

◆ si_string_impl_stream_write()

static void utils::si_string_impl_stream_write ( std::stringstream &  ss,
double  input 
)
static

Definition at line 532 of file string_utils.cpp.

Referenced by si_string().

◆ signed_percent()

std::string utils::signed_percent ( int  val)
inline

◆ signed_value()

std::string utils::signed_value ( int  val)

Convert into a signed value (using the Unicode "−" and +0 convention.

Definition at line 516 of file string_utils.cpp.

References font::unicode_minus.

Referenced by attack_info(), gui2::dialogs::game_stats::pre_show(), quote(), and signed_percent().

◆ split()

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.

Parameters
[in]valA (comma-)separated string.
[in]cThe separator character (usually a comma).
[in]flagsFlags controlling how the split is done. This is a bit field with two settings (both on by default): REMOVE_EMPTY causes empty pieces to be skipped/removed. STRIP_SPACES causes the leading and trailing spaces of each piece to be ignored/stripped.

Basic method taken from http://stackoverflow.com/a/236803

Definition at line 72 of file string_utils.cpp.

References REMOVE_EMPTY, and STRIP_SPACES.

Referenced by halo::halo_impl::add(), game_config::add_color_info(), game_events::event_handlers::add_event_handler(), terrain_builder::add_images_from_config(), name_generator_factory::add_name_generator_from_config(), terrain_builder::add_rotated_rules(), add_simple_anim(), addons_client::addons_client(), ng::flg_manager::append_leaders_from_faction(), unit::apply_builtin_effect(), attack_type::apply_modification(), unit_type::build_created(), unit_type::build_help_index(), team::calculate_is_enemy(), ai::config_value_translator< std::vector< std::string > >::cfg_to_value(), game_events::event_handlers::clean_up_expired_handlers(), game_config::color_info(), commandline_options::commandline_options(), savegame::convert_old_saves_1_13_1(), ai::default_recruitment::recruitment_aspect::create_job(), ai::default_recruitment::recruitment_aspect::create_limit(), create_terrain_maps(), events::menu_handler::custom_command(), default_map_generator_job::default_generate_map(), events::menu_handler::do_search(), events::console_handler::do_unit(), combatant::fight(), unit_filter_impl::unit_filter_compound::fill(), gui2::dialogs::game_load::filter_text_changed(), gui2::dialogs::unit_recall::filter_text_changed(), gui2::dialogs::unit_create::filter_text_changed(), unit_creator::find_location(), ng::flg_manager::find_suitable_faction(), color_t::from_rgb_string(), color_t::from_rgba_string(), gui2::dialogs::mp_lobby::game_filter_reload(), help::unit_topic_generator::generate(), cave_map_generator::cave_map_generator_job::generate_chambers(), help::generate_faction_topics(), help::section::generate_sections(), help::section::generate_table_of_contents(), help::section::generate_topics(), ai::unit_advancements_aspect::get_advancements(), preprocessor_data::get_chunk(), image::get_localized_path(), unit::get_modification_advances(), gui2::dialogs::addon_manager::get_name_filter_visibility(), ai::default_recruitment::recruitment::get_random_pattern_type_if_exists(), wfl::string_callable::get_value(), get_variations(), indent(), unit::init(), display::init_flags(), game_lua_kernel::intf_clear_menu_item(), intf_name_generator(), ai::readonly_context_impl::is_active(), ai::default_recruitment::recruitment::leader_matches_job(), ai::default_recruitment::recruitment::limit_ok(), campaignd::server::load_config(), wesnothd::server::load_config(), game_config::load_config(), preferences::load_credentials(), terrain_builder::load_images(), image::localized_file_uptodate(), preferences::manager::manager(), map_split(), side_filter::match_internal(), terrain_filter::match_internal(), map_location::matches_range(), matches_simple_filter(), theme::menu::menu(), theme::object::modify_location(), unit_type::musthave_status(), ai::formula_ai::on_create(), gui2::dialogs::faction_select::on_faction_select(), terrain_builder::parse_config(), map_location::parse_directions(), wesnothd::parse_ip(), gamemap::parse_location_range(), commandline_options::parse_log_domains_(), parse_ranges(), commandline_options::parse_resolution_(), campaignd::blacklist::parse_str_to_globlist(), commandline_options::parse_to_uint_string_string_tuples_(), commandline_options::parse_to_uint_string_tuples_(), ng::create_engine::prepare_for_campaign(), team_builder::previous_recruits(), playmp_controller::process_oos(), progressive_pair< int >::progressive_pair(), progressive_single< image::locator >::progressive_single(), team::team_info::read(), addon_info::read(), gui2::implementation::read_flags(), unit_type_data::read_hide_help(), read_locations(), read_rect(), game_events::manager::read_scenario(), read_str_int_map(), ai::default_recruitment::recruitment::recruit_matches_job(), unit_type::resistance_filter_matches(), unit::resistance_filter_matches(), sound::music_track::resolve(), tod_manager::resolve_random(), ng::flg_manager::resolve_random(), resolve_rect(), terrain_builder::rule_image_variant::rule_image_variant(), game_lua_kernel::run_filter(), set_split(), editor::terrain_palette::setup(), square_parenthetical_split(), SYNCED_COMMAND_HANDLER_FUNCTION(), game_config::tc_info(), image::modification_queue::top(), unit_animation::unit_animation(), version_info::version_info(), and game_events::WML_HANDLER_FUNCTION().

◆ square_parenthetical_split()

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.

Notes:

  • The Separator must be specified and number of entries in each square bracket must match in each section.
  • Leading zeros are preserved if specified between square brackets.
  • An asterisk as in [a*n] indicates to expand 'a' n times

This is useful for expanding animation WML code.

Examples:

INPUT: ("a[1-3](1,[5,6,7]),b[8,9]", ",") RETURNS: {"a1(1,5)", "a2(1,6)", "a3(1,7)", "b8", "b9"}

INPUT: ("abc[07-10]") RETURNS: {"abc07", "abc08", "abc09", "abc10"}

INPUT: ("a[1,2]b[3-4]:c[5,6]") RETURNS: {"a1b3:c5", "a2b4:c6"}

INPUT: ("abc[3,1].png") RETURNS: {"abc3.png", "abc2.png", "abc1.png"}

INPUT: ("abc[de,xyz]") RETURNS: {"abcde", "abcxyz"}

INPUT: ("abc[1*3]") RETURNS: {"abc1", "abc1", "abc1"}

Definition at line 93 of file string_utils.cpp.

References ERR_GENERAL, i, left, p, portable_isspace(), REMOVE_EMPTY, right, split(), and STRIP_SPACES.

Referenced by halo::halo_impl::add(), terrain_builder::add_constraints(), display::init_flags(), terrain_builder::load_images(), pick_one(), progressive_single< image::locator >::progressive_single(), and set_split().

◆ string_bool()

bool utils::string_bool ( const std::string &  str,
bool  def 
)

Convert no, false, off, 0, 0.0 to false, empty to def, and others to true.

Definition at line 496 of file string_utils.cpp.

Referenced by gui2::typed_formula< bool >::convert(), campaignd::server::handle_read_from_fifo(), tod_manager::is_start_ToD(), quote(), and gui2::styled_widget::set_members().

◆ unescape()

std::string utils::unescape ( const std::string &  str)

Remove all escape characters (backslash)

Definition at line 452 of file string_utils.cpp.

Referenced by escape().

◆ urlencode()

std::string utils::urlencode ( const std::string &  str)

Percent-escape characters in a UTF-8 string intended to be part of a URL.

Definition at line 467 of file string_utils.cpp.

References c.

Referenced by escape(), and campaignd::format_addon_feedback_url().

◆ vertical_split()

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.

For example, if the string contains 3288 lines, then both parts will be 1644 lines long.

The line separator in between won't be in either of the parts the function returns.

Because this function is intended for extremely long strings (kilobytes long), it returns string_views for performance.

Definition at line 385 of file string_utils.cpp.

References i.

Referenced by set_split(), and font::pango_text::split_surface().

◆ wildcard_string_match()

bool utils::wildcard_string_match ( const std::string &  str,
const std::string &  match 
)

◆ word_completion()

bool utils::word_completion ( std::string &  text,
std::vector< std::string > &  wordlist 
)

Try to complete the last word of 'text' with the 'wordlist'.

Parameters
[in,out]textThe parameter's usage is:
  • Input: Text where we try to complete the last word of.
  • Output: Text with completed last word.
[in,out]wordlistThe parameter's usage is:
  • Inout: A vector of strings to complete against.
  • Output: A vector of strings that matched 'text'.
Return values
trueiff text is just one word (no spaces)

Definition at line 647 of file string_utils.cpp.

References chars_equal_insensitive().

Referenced by gui2::chatbox::chat_input_keypress_callback(), signed_percent(), and gui2::dialogs::lua_interpreter::controller::tab().

◆ word_match()

bool utils::word_match ( const std::string &  message,
const std::string &  word 
)

Check if a message contains a word.

Definition at line 698 of file string_utils.cpp.

References is_word_boundary(), and next.

Referenced by display_chat_manager::add_chat_message(), gui2::chatbox::add_chat_room_message_received(), and signed_percent().

Variable Documentation

◆ is_base_of_v

template<typename Base , typename Derived >
constexpr bool utils::is_base_of_v = std::is_base_of<Base, Derived>::value
static

Definition at line 36 of file type_trait_aliases.hpp.

◆ is_same_v

template<typename T , typename U >
constexpr bool utils::is_same_v = std::is_same<T, U>::value
static

Definition at line 40 of file type_trait_aliases.hpp.