The Battle for Wesnoth  1.19.7+dev
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
utils Namespace Reference

Namespaces

 charconv
 
 config_filters
 Utility functions for implementing [filter], [filter_ability], [filter_weapon], etc.
 
 detail
 
 implementation
 

Classes

class  string_map_variable_set
 
struct  hash_error
 
class  hash_base
 
class  hash_digest
 
class  md5
 
class  bcrypt
 
struct  res_compare
 
class  back_edge_detector
 A helper for boost::depth_first_search (DFS) usage with the purpose of detecting cycles. More...
 
struct  charconv_buffer
 
struct  const_clone
 Helper struct to clone the constness of one type to another. More...
 
class  guard_value
 Data-based RAII scope guard. More...
 
class  irdya_date
 Calendar for handling and comparing dates using the common epoches of the storyline. More...
 
struct  optimer
 Reports time elapsed at the end of an object scope. More...
 
class  optional_reference
 A simple wrapper class for optional reference types. More...
 
class  rate_counter
 
class  scope_exit
 
struct  scope_exit_syntax_support
 
class  shared_reference
 
struct  wesnoth_epoch_defines
 Reference points for the dates that define the storyline's calendar. More...
 

Typedefs

using byte_string_view = std::basic_string_view< uint8_t >
 
using string_map = std::map< std::string, t_string >
 
using string_map_res = std::map< std::string, t_string, res_compare >
 
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
 
using ms_optimer = optimer< std::chrono::milliseconds >
 Time elapsed with millisecond resolution. More...
 
using wesnoth_epoch = string_enums::enum_base< wesnoth_epoch_defines >
 

Enumerations

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

Functions

std::vector< std::string > split (const config_attribute_value &val)
 
std::string format_time_summary (std::time_t t)
 
template<typename Rep , typename Period >
static std::string format_timespan (const std::chrono::duration< Rep, Period > &span, bool detailed=false)
 Formats a timespan into human-readable text for player authentication functions. More...
 
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...
 
std::string interpolate_variables_into_string (const std::string &str, const std::map< std::string, t_string > *const symbols)
 Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent symbols in the given symbol table. More...
 
bool isnewline (const char c)
 
bool portable_isspace (const char c)
 
bool notspace (const char c)
 
void trim (std::string_view &s)
 
std::vector< std::string > 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 > split_set (std::string_view s, char sep, const int flags)
 
std::vector< std::string_view > split_view (std::string_view s, const char sep, const int flags)
 
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 (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 apply_modifier (const int number, const std::string &amount, const int minimum)
 
std::string escape (std::string_view 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 (std::string_view str)
 Recognises the following patterns, and returns a {min, max} pair. More...
 
std::pair< double, double > 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 > > 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 > > parse_ranges_real (const std::string &str)
 
std::vector< std::pair< int, int > > parse_ranges_int (const std::string &str)
 Handles a comma-separated list of inputs to parse_range. More...
 
template<typename F >
void split_foreach_impl (std::string_view s, char sep, const F &f)
 
template<typename F >
void split_foreach (std::string_view s, char sep, const int flags, const F &f)
 
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...
 
void trim_for_from_chars (std::string_view &v)
 
double stod (std::string_view str)
 Same interface as std::stod and meant as a drop in replacement, except: More...
 
int stoi (std::string_view str)
 Same interface as std::stoi and meant as a drop in replacement, except: More...
 
template<typename T >
utils::optional< T > from_chars (std::string_view str, int base=10)
 
std::string get_unknown_exception_type ()
 Utility function for finding the type of thing caught with catch(...). More...
 
template<typename Enum >
constexpr std::underlying_type_t< Enum > to_underlying (Enum e) noexcept
 
template<typename Container , typename Value >
bool contains (const Container &container, const Value &value)
 Returns true iff value is found in container. More...
 
template<typename Container , typename Predicate >
void erase_if (Container &container, const Predicate &predicate)
 Convenience wrapper for using std::remove_if on a container. More...
 
template<typename Container , typename Value >
std::size_t erase (Container &container, const Value &value)
 Convenience wrapper for using std::remove on a container. More...
 
template<typename Container , typename Predicate >
void sort_if (Container &container, const Predicate &predicate)
 Convenience wrapper for using std::sort on a container. More...
 
template<typename Container , typename Value >
auto * find (Container &container, const Value &value)
 Convenience wrapper for using find on a container without needing to comare to end() More...
 
bool operator< (const irdya_date &a, const irdya_date &b)
 
bool operator<= (const irdya_date &a, const irdya_date &b)
 
bool operator> (const irdya_date &a, const irdya_date &b)
 
bool operator>= (const irdya_date &a, const irdya_date &b)
 
bool operator== (const irdya_date &a, const irdya_date &b)
 
bool operator!= (const irdya_date &a, const irdya_date &b)
 
std::ostream & operator<< (std::ostream &s, const irdya_date &d)
 
template<typename... OpTimerArgs>
std::ostream & operator<< (std::ostream &o, const optimer< OpTimerArgs... > &tm)
 Formats time elapsed for writing to a stream. More...
 
template<typename T >
auto reversed_view (T &container)
 
template<typename T , typename... Types>
shared_reference< T > make_shared_reference (Types &&...args)
 
template<typename... Types>
std::size_t variant_index (const variant< Types... > &var)
 
std::string unescape (std::string_view str)
 Remove all escape characters (backslash) More...
 
std::string urlencode (std::string_view 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 to_sql_wildcards (std::string &str, bool underscores=true)
 Converts '*' to '' and optionally escapes '_'. 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 (std::string_view str)
 Prepend all special characters with a backslash. More...
 
std::string quote (std::string_view 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

const std::vector< std::string > res_order = {"blade", "pierce", "impact", "fire", "cold", "arcane"}
 
template<typename T1 , typename T2 >
constexpr bool decayed_is_same = std::is_same_v<std::decay_t<T1>, std::decay_t<T2>>
 Equivalent to as std::is_same_v except both types are passed through std::decay first. More...
 
template<typename >
constexpr bool dependent_false_v = false
 Workaround for the fact that static_assert(false) is invalid. More...
 

Typedef Documentation

◆ byte_string_view

using utils::byte_string_view = typedef std::basic_string_view<uint8_t>

Definition at line 25 of file base64.hpp.

◆ const_clone_ptr

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

Definition at line 66 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 63 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 60 of file const_clone.hpp.

◆ ms_optimer

using utils::ms_optimer = typedef optimer<std::chrono::milliseconds>

Time elapsed with millisecond resolution.

Definition at line 119 of file optimer.hpp.

◆ string_map

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

Definition at line 35 of file string_utils.hpp.

◆ string_map_res

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

Definition at line 52 of file string_utils.hpp.

◆ wesnoth_epoch

Definition at line 34 of file wesnoth_epoch.hpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
REMOVE_EMPTY 
STRIP_SPACES 

REMOVE_EMPTY: remove empty elements.

Definition at line 58 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 247 of file string_utils.hpp.

References i, and indent().

Referenced by addons_client::do_check_before_overwriting_addon(), addons_client::do_resolve_addon_dependencies(), gui2::dialogs::faction_select::on_faction_select(), and gui2::dialogs::terrain_layers::pre_show().

◆ 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 86 of file general.hpp.

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

Referenced by ai::readonly_context_impl::applies_to_leader(), unit_type::apply_scenario_fix(), BOOST_AUTO_TEST_CASE(), events::menu_handler::can_recruit(), ng::depcheck::manager::change_era(), ng::depcheck::manager::change_modifications(), ng::depcheck::manager::change_scenario(), play_controller::check_next_scenario_is_known(), actions::check_recruit_location(), ng::depcheck::manager::does_conflict(), ng::depcheck::manager::does_require(), game_display::draw_invalidated(), help::generate_terrain_sections(), gui2::dialogs::addon_manager::get_lang_filter_visibility(), ng::depcheck::manager::get_required_not_enabled(), gui2::dialogs::addon_manager::get_tag_filter_visibility(), gui::scrollarea::handle_event(), editor::palette_manager::handle_event(), controller_base::handle_scroll(), impl_sndsrc_get(), wesnothd::server::is_ip_banned(), controller_base::long_touch_callback(), display::minimap_location_on(), gui2::dialogs::drop_down_menu::mouse_up_callback(), events::mouse_handler_base::mouse_wheel(), arrow::path_contains(), events::mouse_handler::touch_motion(), unit::update_variables_recursion(), and attack_type::update_variables_recursion().

◆ 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 953 of file string_utils.cpp.

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

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

◆ erase()

template<typename Container , typename Value >
std::size_t utils::erase ( Container &  container,
const Value &  value 
)

◆ erase_if()

template<typename Container , typename Predicate >
void utils::erase_if ( Container &  container,
const Predicate &  predicate 
)

◆ escape() [1/2]

std::string utils::escape ( std::string_view  str)
inline

Prepend all special characters with a backslash.

Special characters are: #}+-,*=

Definition at line 330 of file string_utils.hpp.

References escape().

◆ escape() [2/2]

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

Prepends a configurable set of characters with a backslash.

Definition at line 416 of file string_utils.cpp.

Referenced by escape(), and get_file_code().

◆ find()

template<typename Container , typename Value >
auto* utils::find ( Container &  container,
const Value &  value 
)

Convenience wrapper for using find on a container without needing to comare to end()

Definition at line 140 of file general.hpp.

Referenced by pathfind::a_star_search(), unit::ability_affects_adjacent(), prefs::achievement(), achievement_group::achievement_group(), game_data::activate_scope_variable(), replay::add_chat_message_location(), game_events::manager::add_events(), gui2::window::add_linked_widget(), add_string_to_vector(), gui2::window::add_to_tab_order(), append_special_note(), unit_type_data::apply_base_unit(), unit::apply_builtin_effect(), attack_type::apply_modification(), events::generic_event::attach_handler(), wesnothd::server::authenticate(), wesnothd::server::ban_handler(), wesnothd::server::bans_handler(), team::calculate_is_enemy(), gui2::dialogs::campaign_selection::campaign_selected(), lua_fileops::canonical_path(), events::chat_handler::change_logging(), wb::attack::check_validity(), wb::recall::check_validity(), wb::recruit::check_validity(), savegame::save_index_class::clean_up_index(), wesnothd::server::cleanup_game(), persist_file_context::clear_var(), gui2::event::sdl_event_handler::connect(), ng::connect_engine::connect_engine(), pathfind::paths::dest_vect::contains(), gui2::dialogs::mp_create_game::convert_to_game_filtered_index(), default_map_generator_job::default_generate_map(), draw_manager::deregister_drawable(), events::generic_event::detach_handler(), gui2::event::sdl_event_handler::disconnect(), ai::ai_default_rca::get_villages_phase::dispatch_complex(), gui2::dialogs::mp_options_helper::display_custom_options(), ai::move_result::do_execute(), events::console_handler::do_set_alias(), events::console_handler::do_set_var(), wb::side_actions_container::erase(), utils::detail::contains_impl< Container, Value >::eval(), ai::ai_default_rca::retreat_phase::evaluate(), ai::lua_sticky_candidate_action_wrapper::evaluate(), ng::flg_manager::faction_index(), unit_filter_impl::unit_filter_compound::fill(), unit_animation::fill_initial_animations(), terrain_filterimpl::filter_xy(), schema_validation::wml_tag::find_key(), schema_validation::schema_validator::find_mandatory_keys(), ng::flg_manager::find_suitable_faction(), schema_validation::wml_tag::find_tag(), wesnothd::game::find_user(), ai::ai_default_rca::get_villages_phase::find_villages(), footsteps_images(), mp::game_info::game_info(), wesnothd::server::gban_handler(), ng::flg_manager::gender_index(), help::generate_terrain_sections(), video::get_available_resolutions(), wfl::function_symbol_table::get_builtins(), wfl::variant_callable::get_debug_string(), gui2::rich_label::get_parsed_text(), pathfind::paths::dest_vect::get_path(), wb::side_actions::get_position_of(), savegame::save_index_class::get_saves_list(), wesnothd::server::handle_join_game(), wesnothd::server::handle_player_in_game(), wesnothd::server::handle_player_in_lobby(), wesnothd::server::handle_whisper(), unit_type::has_gender_variation(), events::context::has_handler(), terrain_label::hidden(), impl_namedtuple_get(), gui2::dialogs::preferences_dialog::initialize_callbacks(), game_lua_kernel::intf_get_time_area(), ai::aspect_factory::is_duplicate(), ai::engine_factory::is_duplicate(), ai::goal_factory::is_duplicate(), ai::candidate_action_factory::is_duplicate(), ai::stage_factory::is_duplicate(), wesnothd::server::is_login_allowed(), ng::depcheck::manager::is_modification_active(), wesnothd::game::is_muted_observer(), wesnothd::game::is_observer(), wesnothd::game::is_player(), sound::is_sound_playing(), gui2::event::distributor::keyboard_add_to_chain(), gui2::event::distributor::keyboard_remove_from_chain(), wesnothd::server::kick_handler(), wesnothd::server::kickban_handler(), ng::flg_manager::leader_index(), ai::default_recruitment::recruitment::leader_matches_job(), campaignd::server::load_config(), prefs::load_preferences(), ng::connect_engine::load_previous_sides_users(), wesnothd::server::login_client(), wesnothd::make_change_diff(), wesnothd::make_delete_diff(), markov_generate_name(), terrain_filter::match_internal(), side_filter::match_internal(), unit_animation::matches(), gui::floating_textbox::memorize_command(), ai::ai_default_rca::move_to_targets_phase::move_group(), unit_type::musthave_status(), gui2::dialogs::faction_select::on_leader_select(), fake_unit_manager::place_temporary_unit(), wesnothd::game::player_is_banned(), wesnothd::server::pm_handler(), ai::readonly_context_impl::power_projection(), gui2::dialogs::campaign_selection::pre_show(), gui2::dialogs::editor_edit_pbl::pre_show(), gui2::dialogs::mp_create_game::pre_show(), gui2::dialogs::campaign_selection::proceed(), wesnothd::server::process_command(), ng::connect_engine::process_network_data(), wesnothd::game::process_turn(), draw_manager::raise_drawable(), draw_manager::register_drawable(), unit::remove_attack(), events::context::remove_handler(), gui2::window::remove_linked_widget(), wesnothd::server::remove_player(), unit_type::resistance_filter_matches(), unit::resistance_filter_matches(), ng::flg_manager::resolve_random(), wesnothd::server::roll_handler(), synced_context::run(), wesnothd::server::searchlog_handler(), help::section_is_referenced(), prefs::set_achievement(), events::context::set_focus(), gui::button::set_label(), gui2::dialogs::preferences_dialog::set_resolution_list(), prefs::set_sub_achievement(), ng::side_engine::side_engine(), gui2::event::distributor::signal_handler_notify_removal(), gui2::window::signal_handler_sdl_key_down(), wesnothd::server::stopgame(), wfl::string_expression::string_expression(), utils::config_filters::string_matches_if_present(), prefs::sub_achievement(), ai::readonly_context_impl::suitable_keep(), gui2::dialogs::file_dialog::sync_bookmarks_bar(), synced_command::synced_command(), SYNCED_COMMAND_HANDLER_FUNCTION(), play_controller::textbox_move_vertically(), help::topic_is_referenced(), wesnothd::game::transfer_side_control(), ng::depcheck::manager::try_modification_by_id(), wb::side_actions::unit_has_actions(), ng::flg_manager::update_choosable_genders(), ng::flg_manager::update_choosable_leaders(), schema_validation::schema_self_validator::validate_key(), schema_validation::schema_validator::validate_mandatory_keys(), and unit::~unit().

◆ 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 260 of file string_utils.cpp.

References i, and VGETTEXT.

Referenced by unit::describe_builtin_effect(), attack_type::describe_modification(), format_timespan(), lua_stringx::intf_format_list(), help::terrain_topic_generator::operator()(), events::menu_handler::recruit(), and gui2::multimenu_button::update_label().

◆ 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 278 of file string_utils.cpp.

References i, and VGETTEXT.

Referenced by lua_stringx::intf_format_list().

◆ format_time_summary()

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

◆ format_timespan()

template<typename Rep , typename Period >
static std::string utils::format_timespan ( const std::chrono::duration< Rep, Period > &  span,
bool  detailed = false 
)
static

Formats a timespan into human-readable text for player authentication functions.

This is generally meant for player-facing text rather than lightweight tasks like debug logging. The resulting output may differ based on current language settings.

This is intentionally not a very thorough representation of time intervals. See https://github.com/wesnoth/wesnoth/issues/6036 for more information.

Parameters
spanThe timespan to format
detailedWhether to display more specific values such as "3 months, 2 days, 30 minutes, and 1 second". If not specified or set to false, the return value will ONLY include most significant time unit (e.g. "3 months").
Returns
A human-readable timespan description.
Note
The implementation formats the given timespan according to periods defined by the C++ chrono standard. As such, a year is defined as its average Gregorian length of 365.2425 days, while months are exactly 1/12 of a year. Furthermore, it doesn't take into account leap years or leap seconds. If you need to account for those, you are better off importing a new library and providing it with more specific information about the start and end times of the interval; otherwise your next best option is to hire a fortune teller to manually service your requests every time instead of this function.

Definition at line 86 of file format_timespan.hpp.

References _(), chrono::deconstruct_duration(), utils::implementation::deconstruct_format, utils::implementation::descriptors, format_conjunct_list(), i, and VNGETTEXT.

Referenced by BOOST_AUTO_TEST_CASE().

◆ from_chars()

template<typename T >
utils::optional<T> utils::from_chars ( std::string_view  str,
int  base = 10 
)

Definition at line 22 of file from_chars.hpp.

References _().

◆ get_unknown_exception_type()

std::string utils::get_unknown_exception_type ( )

◆ half_signed_value()

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

Sign with Unicode "−" if negative.

Definition at line 502 of file string_utils.cpp.

References font::unicode_minus.

Referenced by frame_parsed_parameters::debug_strings(), gui2::dialogs::game_stats::pre_show(), and REPORT_GENERATOR().

◆ 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 760 of file string_utils.cpp.

References draw::line(), and split().

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

◆ interpolate_variables_into_string() [1/4]

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

Definition at line 238 of file string_utils.cpp.

References do_interpolation(), and cursor::set().

◆ interpolate_variables_into_string() [2/4]

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

◆ interpolate_variables_into_string() [3/4]

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

◆ interpolate_variables_into_string() [4/4]

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

Definition at line 244 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 249 of file string_utils.cpp.

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

Referenced by lua_stringx::intf_format(), and terrain_label::read().

◆ is_username_char()

static bool utils::is_username_char ( char  c)
static

Definition at line 607 of file string_utils.cpp.

References c.

Referenced by isvalid_username(), and isvalid_wildcard().

◆ is_wildcard_char()

static bool utils::is_wildcard_char ( char  c)
static

Definition at line 611 of file string_utils.cpp.

References c.

Referenced by isvalid_wildcard().

◆ is_word_boundary()

static bool utils::is_word_boundary ( char  c)
static

Definition at line 689 of file string_utils.cpp.

References c.

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 615 of file string_utils.cpp.

References is_username_char().

Referenced by wesnothd::server::is_login_allowed(), 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 627 of file string_utils.cpp.

References is_username_char(), and is_wildcard_char().

Referenced by prefs::add_acquaintance().

◆ 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 204 of file string_utils.hpp.

References i, and s.

Referenced by schema_validation::schema_validator::active_tag_path(), mp::add_multiplayer_classification(), gui2::dialogs::add_unit_entry(), prefs::aes_decrypt(), prefs::aes_encrypt(), team::allied_human_teams(), attack_info(), BOOST_AUTO_TEST_CASE(), ng::depcheck::manager::change_era(), ng::depcheck::manager::change_scenario(), gui2::chatbox::chat_input_keypress_callback(), gui2::dialogs::file_dialog::check_filename(), addons_client::connect(), gui2::dialogs::editor_edit_pbl::create_cfg(), schema_validation::schema_self_validator::current_path(), gui2::dialogs::depcheck_confirm_change::depcheck_confirm_change(), saved_game::expand_mp_events(), campaignd::control_line::full(), ai::holder::get_ai_overview(), prefs::get_ignored_delim(), hotkey::get_names(), carryover::get_recruits(), wesnothd::server::handle_join_game(), wesnothd::server::handle_player_in_game(), wesnothd::server::handle_player_in_lobby(), campaignd::server::handle_server_id(), events::map_command_handler< Worker >::help_command(), impl_mp_settings_get(), impl_namedtuple_tostring(), impl_source_set(), game_lua_kernel::intf_add_tile_overlay(), lua_stringx::intf_str_join(), terrain_type_data::lazy_initialization(), game_config_manager::load_addons_cfg(), game_config_manager::load_game_config(), gui2::dialogs::editor_edit_unit::load_unit_type(), wesnothd::server::login_client(), ai::leader_aspects_visitor::operator()(), gui2::dialogs::end_credits::pre_show(), gui2::dialogs::unit_list::pre_show(), read_event_name(), gui2::unit_preview_pane::set_display_data(), prefs::set_modifications(), gui::floating_textbox::tab(), schema_validation::schema_self_validator::tag_path_exists(), editor::map_context::to_config(), ai::default_recruitment::recruit_job::to_config(), ai::default_recruitment::recruit_limit::to_config(), game_classification::to_config(), carryover::transfer_all_recruits_to(), unit_helper::unit_level_tooltip(), gui2::dialogs::end_credits::update(), gui2::dialogs::mp_match_history::update_display(), addons_client::upload_addon(), gui2::dialogs::editor_edit_pbl::validate(), campaignd::server::validate_addon(), ai::config_value_translator< std::vector< std::string > >::value_to_cfg(), addon_info::write(), team::team_info::write(), unit::write(), game_events::manager::write_events(), addon_info::write_minimal(), game_data::write_snapshot(), statistics_record::write_str_int_map(), and prefs::~prefs().

◆ join_map()

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

◆ make_shared_reference()

template<typename T , typename... Types>
shared_reference<T> utils::make_shared_reference ( Types &&...  args)

Definition at line 84 of file shared_reference.hpp.

◆ 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 280 of file string_utils.cpp.

References i, and split().

Referenced by BOOST_AUTO_TEST_CASE(), lua_stringx::intf_str_map_split(), ng::connect_engine::load_previous_sides_users(), and ng::connect_engine::save_reserved_sides_information().

◆ 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 45 of file string_utils.hpp.

Referenced by game_events::event_handlers::finish_adding_event_handler(), and game_events::event_handler::names().

◆ notspace()

bool utils::notspace ( const char  c)

Definition at line 59 of file string_utils.cpp.

References c, and portable_isspace().

◆ operator!=()

bool utils::operator!= ( const irdya_date a,
const irdya_date b 
)

Definition at line 121 of file irdya_datetime.cpp.

References b.

◆ operator<()

bool utils::operator< ( const irdya_date a,
const irdya_date b 
)

◆ operator<<() [1/2]

template<typename... OpTimerArgs>
std::ostream& utils::operator<< ( std::ostream &  o,
const optimer< OpTimerArgs... > &  tm 
)
inline

Formats time elapsed for writing to a stream.

Note
The resulting output does not include a time unit suffix.

Definition at line 110 of file optimer.hpp.

References utils::optimer< ResolutionType, ClockType >::elapsed().

◆ operator<<() [2/2]

std::ostream & utils::operator<< ( std::ostream &  s,
const irdya_date d 
)

Definition at line 126 of file irdya_datetime.cpp.

References d, and s.

◆ operator<=()

bool utils::operator<= ( const irdya_date a,
const irdya_date b 
)

Definition at line 106 of file irdya_datetime.cpp.

References b.

◆ operator==()

bool utils::operator== ( const irdya_date a,
const irdya_date b 
)

◆ operator>()

bool utils::operator> ( const irdya_date a,
const irdya_date b 
)

Definition at line 101 of file irdya_datetime.cpp.

References b.

◆ operator>=()

bool utils::operator>= ( const irdya_date a,
const irdya_date b 
)

Definition at line 111 of file irdya_datetime.cpp.

References b.

◆ parenthetical_split()

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.

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 311 of file string_utils.cpp.

References ERR_GENERAL, i, portable_isspace(), REMOVE_EMPTY, STRIP_SPACES, and trim().

Referenced by unit::apply_builtin_effect(), BOOST_AUTO_TEST_CASE(), image::modification::decode(), wfl::string_callable::get_value(), unit::init(), ai::manager::internal_evaluate_command(), intf_name_generator(), lua_stringx::intf_str_paren_split(), lua_stringx::intf_str_split(), and image::load_image_sub_file().

◆ parse_range()

std::pair< int, int > utils::parse_range ( std::string_view  str)

Recognises the following patterns, and returns a {min, max} pair.

  • "1" returns {1, 1}
  • "1-3" returns {1, 3}
  • "1-infinity" returns {1, maximum int}
  • "-1" returns {-1, -1}
  • "-3--1" returns {-3, -1}

Note that:

  • "3-1" returns {3, 3} and does not log an error
  • "-1--3" returns {-1, -1} and does not log an error
  • Although "-infinity--1", "2-infinity" and "-infinity-infinity" are all supported,
  • ranges that can't match a reasonable number, e.g. "-infinity" or "infinity..infinity", may be treated as errors.

Definition at line 860 of file string_utils.cpp.

References b, ERR_GENERAL, and stoi().

Referenced by lua_stringx::intf_parse_range(), ai::readonly_context_impl::is_active(), map_location::matches_range(), gamemap_base::parse_location_range(), and parse_ranges_int().

◆ parse_range_real()

std::pair< double, double > utils::parse_range_real ( std::string_view  str)

Recognises similar patterns to parse_range, and returns a {min, max} pair.

For this function, "infinity" results in std::numeric_limits<double>::infinity.

Definition at line 890 of file string_utils.cpp.

References b, ERR_GENERAL, and stod().

Referenced by lua_stringx::intf_parse_range(), and parse_ranges_real().

◆ parse_ranges_int()

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

Handles a comma-separated list of inputs to parse_range.

Definition at line 943 of file string_utils.cpp.

References parse_range(), and split().

Referenced by utils::config_filters::int_matches_if_present(), utils::config_filters::int_matches_if_present_or_negative(), matches_simple_filter(), and parse_ranges_unsigned().

◆ parse_ranges_real()

std::vector< std::pair< double, double > > utils::parse_ranges_real ( const std::string &  str)

Definition at line 933 of file string_utils.cpp.

References parse_range_real(), and split().

Referenced by utils::config_filters::double_matches_if_present().

◆ parse_ranges_unsigned()

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.

Will return an empty list if any of the ranges have a minimum that's below zero.

Definition at line 922 of file string_utils.cpp.

References ERR_GENERAL, and parse_ranges_int().

Referenced by unit::ability_active_impl(), check_side_number(), game_events::builtin_conditions::have_location(), game_events::builtin_conditions::have_unit(), terrain_filter::match_internal(), matches_simple_filter(), and attack_type::special_active_impl().

◆ 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 316 of file string_utils.hpp.

References font::unicode_minus.

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

◆ quote()

std::string utils::quote ( std::string_view  str)
inline

Surround the string 'str' with double quotes.

Definition at line 342 of file string_utils.hpp.

Referenced by quoted_split().

◆ 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 793 of file string_utils.cpp.

References c, quote(), REMOVE_EMPTY, STRIP_SPACES, and trim().

Referenced by BOOST_AUTO_TEST_CASE(), help::generate_contents_links(), preprocessor_data::get_chunk(), preprocessor_streambuf::get_current_file(), get_location(), lua_stringx::intf_str_split(), lineno_string(), help::parse_config_internal(), help::section_is_referenced(), and help::topic_is_referenced().

◆ reversed_view()

template<typename T >
auto utils::reversed_view ( T &  container)
inline

◆ 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 540 of file string_utils.cpp.

References _(), si_string_impl_stream_write(), and font::unicode_minus.

Referenced by gui2::dialogs::network_transmission::pump_monitor::process(), gui2::dialogs::screenshot_notification::save_screenshot(), 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 511 of file string_utils.cpp.

Referenced by si_string().

◆ signed_percent()

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

Convert into a percentage (using the Unicode "−" and +0% convention.

Definition at line 360 of file string_utils.hpp.

References signed_value().

Referenced by attack_type::accuracy_parry_description(), attack_info(), gui2::get_hp_tooltip(), gui2::dialogs::attack_predictions::set_data(), time_of_day_at(), unit_alignment(), unit_box_at(), and unit_hp().

◆ signed_value()

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

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

Definition at line 495 of file string_utils.cpp.

References font::unicode_minus.

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

◆ sort_if()

template<typename Container , typename Predicate >
void utils::sort_if ( Container &  container,
const Predicate &  predicate 
)

Convenience wrapper for using std::sort on a container.

Definition at line 130 of file general.hpp.

Referenced by attack_type::overwrite_special_overwriter().

◆ split() [1/2]

std::vector< std::string > utils::split ( const config_attribute_value val)

Definition at line 424 of file config_attribute_value.cpp.

References config_attribute_value::str().

Referenced by prefs::achievement(), halo::halo_impl::add(), unit_animation::add_anims(), game_config::add_color_info(), terrain_builder::add_images_from_config(), name_generator_factory::add_name_generator_from_config(), terrain_builder::add_rotated_rules(), schema_validation::wml_tag::add_switch(), ng::flg_manager::append_leaders_from_faction(), unit::apply_builtin_effect(), attack_type::apply_modification(), unit_type::apply_scenario_fix(), BOOST_AUTO_TEST_CASE(), unit_type::build_created(), unit_type::build_help_index(), team::calculate_is_enemy(), ai::config_value_translator< utils::variant< bool, std::vector< std::string > > >::cfg_to_value(), ai::config_value_translator< std::vector< std::string > >::cfg_to_value(), schema_validation::schema_self_validator::check_for_duplicates(), game_events::event_handlers::clean_up_expired_handlers(), game_config::color_info(), campaignd::command_line::command_line(), commandline_options::commandline_options(), addons_client::connect(), savegame::convert_old_saves_1_13_1(), ai::default_recruitment::recruitment_aspect::create_job(), ai::default_recruitment::recruitment_aspect::create_limit(), events::menu_handler::custom_command(), default_map_generator_job::default_generate_map(), events::menu_handler::do_search(), events::console_handler::do_unit(), ng::depcheck::manager::does_conflict(), ng::depcheck::manager::does_require(), gui2::text_shape::draw(), gui2::dialogs::game_load::evaluate_summary_string(), schema_validation::wml_tag::expand(), combatant::fight(), unit_filter_impl::unit_filter_compound::fill(), terrain_filterimpl::filter_special_loc(), gui2::dialogs::campaign_selection::filter_text_changed(), unit_creator::find_location(), ng::flg_manager::find_suitable_faction(), gui2::dialogs::mp_lobby::game_filter_init(), cave_map_generator::cave_map_generator_job::generate_chambers(), help::generate_faction_topics(), help::generate_sections(), help::generate_topic_text(), help::generate_topics(), unit::generate_traits(), ai::unit_advancements_aspect::get_advancements(), preprocessor_data::get_chunk(), filesystem::get_localized_path(), terrain_filter::get_locs_impl(), unit::get_modification_advances(), gui2::dialogs::addon_manager::get_name_filter_visibility(), ai::default_recruitment::recruitment::get_random_pattern_type_if_exists(), ng::depcheck::manager::get_required(), wfl::string_callable::get_value(), get_variations(), wesnothd::server::handle_create_game(), campaignd::server::handle_read_from_fifo(), campaignd::server::handle_upload(), gui2::dialogs::preferences_dialog::hotkey_filter_callback(), impl_source_get(), indent(), unit::init(), game_lua_kernel::intf_clear_menu_item(), intf_name_generator(), lua_stringx::intf_str_split(), ai::readonly_context_impl::is_active(), terrain_type_data::lazy_initialization(), 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(), prefs::load_credentials(), terrain_builder::load_images(), prefs::load_preferences(), translation::make_ci_matcher(), map_split(), terrain_filter::match_internal(), side_filter::match_internal(), map_location::matches_range(), matches_simple_filter(), theme::menu::menu(), prefs::modifications(), theme::object::modify_location(), unit_type::musthave_status(), schema_validation::schema_self_validator::name_matches(), game_events::event_handler::names(), ai::formula_ai::on_create(), gui2::dialogs::faction_select::on_faction_select(), help::unit_topic_generator::operator()(), terrain_builder::parse_config(), map_location::parse_directions(), wesnothd::parse_ip(), gamemap_base::parse_location_range(), commandline_options::parse_log_domains_(), parse_ranges_int(), parse_ranges_real(), 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_(), gui2::dialogs::addon_auth::pre_show(), gui2::dialogs::editor_edit_pbl::pre_show(), gui2::dialogs::end_credits::pre_show(), ng::create_engine::prepare_for_campaign(), team_builder::previous_recruits(), playmp_controller::process_oos(), addon_info::read(), team::team_info::read(), gui2::implementation::read_flags(), unit_type_data::read_hide_help(), read_locations(), read_rect(), game_events::manager::read_scenario(), statistics_record::read_str_int_map(), ai::default_recruitment::recruitment::recruit_matches_job(), display::reinit_flags_for_team(), unit_type::remove_scenario_fixes(), unit_type::resistance_filter_matches(), unit::resistance_filter_matches(), sound::music_track::resolve(), ng::flg_manager::resolve_random(), tod_manager::resolve_random(), resolve_rect(), terrain_builder::rule_image_variant::rule_image_variant(), game_lua_kernel::run_filter(), prefs::set_achievement(), gui::button::set_label(), prefs::set_sub_achievement(), editor::terrain_palette::setup(), show_deprecated_warnings(), gui2::dialogs::game_version::show_manual(), square_parenthetical_split(), utils::config_filters::string_matches_if_present(), prefs::sub_achievement(), SYNCED_COMMAND_HANDLER_FUNCTION(), schema_validation::schema_self_validator::tag_path_exists(), game_config::tc_info(), unit_animation::unit_animation(), gui2::dialogs::mp_match_history::update_display(), schema_validation::schema_validator::validate(), campaignd::server::validate_addon(), schema_validation::schema_validator::validate_key(), schema_validation::schema_self_validator::validate_key(), version_info::version_info(), and game_events::WML_HANDLER_FUNCTION().

◆ split() [2/2]

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.

Parameters
[in]sA (comma-)separated string.
[in]sepThe 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.

Definition at line 84 of file string_utils.cpp.

References s, and split_foreach().

◆ split_foreach()

template<typename F >
void utils::split_foreach ( std::string_view  s,
char  sep,
const int  flags,
const F &  f 
)

◆ split_foreach_impl()

template<typename F >
void utils::split_foreach_impl ( std::string_view  s,
char  sep,
const F &  f 
)

Definition at line 66 of file string_utils.hpp.

References f, and s.

Referenced by split_foreach().

◆ split_set()

std::set< std::string > utils::split_set ( std::string_view  s,
char  sep,
const int  flags 
)

◆ split_view()

std::vector< std::string_view > utils::split_view ( std::string_view  s,
const char  sep,
const int  flags 
)

◆ 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[3,1].png") RETURNS: {"abc3.png", "abc1.png"}

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

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

Definition at line 111 of file string_utils.cpp.

References ERR_GENERAL, i, p, portable_isspace(), REMOVE_EMPTY, split(), stoi(), STRIP_SPACES, and trim().

Referenced by halo::halo_impl::add(), terrain_builder::add_constraints(), BOOST_AUTO_TEST_CASE(), lua_stringx::intf_str_split(), terrain_builder::load_images(), pick_one(), and display::reinit_flags_for_team().

◆ stod()

double utils::stod ( std::string_view  str)
inline

Same interface as std::stod and meant as a drop in replacement, except:

  • It takes a std::string_view
  • It is locale independent

Definition at line 141 of file charconv.hpp.

References utils::charconv::from_chars(), and trim_for_from_chars().

Referenced by parse_range_real().

◆ stoi()

int utils::stoi ( std::string_view  str)
inline

Same interface as std::stoi and meant as a drop in replacement, except:

  • It takes a std::string_view

Definition at line 154 of file charconv.hpp.

References utils::charconv::from_chars(), and trim_for_from_chars().

Referenced by halo::halo_impl::add(), terrain_builder::add_images_from_config(), attack_type::apply_modification(), apply_modifier(), unit::describe_builtin_effect(), attack_type::describe_modification(), ai::find_component(), cave_map_generator::cave_map_generator_job::generate_chambers(), preprocessor_data::get_chunk(), gui2::spinner::get_value(), ai::manager::internal_evaluate_command(), game_lua_kernel::intf_set_floating_label(), gamemap_base::is_starting_position(), language_def::language_def(), terrain_builder::load_images(), editor::loc_id_comp(), map_location::map_location(), gamemap_base::num_valid_starting_positions(), help::unit_topic_generator::operator()(), wfl::parse_expression(), parse_range(), commandline_options::parse_resolution_(), cave_map_generator::cave_map_generator_job::place_passage(), gui2::dialogs::label_settings::pre_show(), utils::irdya_date::read_date(), read_locations_helper(), statistics_record::read_str_int_map(), display::reinit_flags_for_team(), wesnothd::server::roll_handler(), gui2::dialogs::variable_mode_controller::show_array(), gui2::dialogs::unit_mode_controller::show_array(), gui2::dialogs::team_mode_controller::show_array(), square_parenthetical_split(), SYNCED_COMMAND_HANDLER_FUNCTION(), and campaignd::server::validate_addon().

◆ 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 475 of file string_utils.cpp.

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

◆ to_sql_wildcards()

void utils::to_sql_wildcards ( std::string &  str,
bool  underscores = true 
)

Converts '*' to '' and optionally escapes '_'.

Parameters
strThe original string.
underscoresWhether to escape underscore characters as well.

Definition at line 746 of file string_utils.cpp.

References n.

Referenced by wesnothd::server::searchlog_handler().

◆ to_underlying()

template<typename Enum >
constexpr std::underlying_type_t<Enum> utils::to_underlying ( Enum  e)
constexprnoexcept

◆ trim()

void utils::trim ( std::string_view &  s)

◆ trim_for_from_chars()

void utils::trim_for_from_chars ( std::string_view &  v)
inline

◆ unescape()

std::string utils::unescape ( std::string_view  str)

Remove all escape characters (backslash)

Definition at line 431 of file string_utils.cpp.

◆ urlencode()

std::string utils::urlencode ( std::string_view  str)

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

Definition at line 446 of file string_utils.cpp.

References c.

Referenced by campaignd::format_addon_feedback_url().

◆ variant_index()

template<typename... Types>
std::size_t utils::variant_index ( const variant< Types... > &  var)

Definition at line 80 of file variant.hpp.

◆ 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 642 of file string_utils.cpp.

References b.

Referenced by gui2::chatbox::chat_input_keypress_callback(), gui2::dialogs::lua_interpreter::controller::tab(), and gui::floating_textbox::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 693 of file string_utils.cpp.

References is_word_boundary().

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

Variable Documentation

◆ decayed_is_same

template<typename T1 , typename T2 >
constexpr bool utils::decayed_is_same = std::is_same_v<std::decay_t<T1>, std::decay_t<T2>>
inlineconstexpr

Equivalent to as std::is_same_v except both types are passed through std::decay first.

Template Parameters
T1The first type to compare.
T2The second type to compare.

Definition at line 30 of file general.hpp.

Referenced by advance_unit(), ai::readonly_context_impl::applies_to_leader(), wesnothd::server::disconnect_player(), ai::lua_object< T >::from_type(), log_address(), and server_base::serve().

◆ dependent_false_v

template<typename >
constexpr bool utils::dependent_false_v = false
inlineconstexpr

Workaround for the fact that static_assert(false) is invalid.

See https://devblogs.microsoft.com/oldnewthing/20200311-00/?p=103553

Definition at line 37 of file general.hpp.

Referenced by gui2::event::dispatcher::get_signal_queue().

◆ res_order

const std::vector<std::string> utils::res_order = {"blade", "pierce", "impact", "fire", "cold", "arcane"}

Definition at line 37 of file string_utils.hpp.

Referenced by utils::res_compare::operator()().