The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Enumerations | Functions | Variables
utils Namespace Reference

Classes

class  smart_list
 This is a variant on a list that never invalidates iterators (unless, of course, the list ceases to exist). More...
 
class  string_map_variable_set
 
struct  tconst_clone
 Helper struct to clone the constness of one type to another. More...
 
struct  tconst_clone< D, S, typename boost::enable_if< boost::is_const< typename boost::remove_pointer< typename boost::remove_reference< S >::type >::type > >::type >
 The specialised version of tconst_clone. More...
 

Enumerations

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

Functions

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 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...
 
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::stringsplit (std::string const &val, const char c, const int flags)
 Splits a (comma-)separated string into a vector of pieces. More...
 
std::vector< std::stringsquare_parenthetical_split (std::string const &val, const char separator= ',', std::string const &left="([", std::string const &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 (std::string const &val, char major= ',', char minor= ':', int flags=REMOVE_EMPTY|STRIP_SPACES, std::string const &default_value="")
 Splits a string based on two separators into a map. More...
 
std::vector< std::stringparenthetical_split (std::string const &val, const char separator=0, std::string const &left="(", std::string const &right=")", const int flags=REMOVE_EMPTY|STRIP_SPACES)
 Splits a string based either on a separator where text within parenthesis is protected from splitting (Note that one can use the same character for both the left and right parenthesis. 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, size_t indent_size=4)
 Indent a block of text. More...
 
std::vector< std::stringquoted_split (std::string const &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'. More...
 
std::pair< int, intparse_range (std::string const &str)
 
std::vector< std::pair< int,
int > > 
parse_ranges (std::string const &str)
 
std::set< std::stringset_split (std::string const &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 (T const &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, size_t indent=4, const std::string &bullet=unicode_bullet)
 Generates a new string containing a bullet list. More...
 
std::string print_modifier (const std::string &mod)
 
template<class Data >
bool operator== (const smart_list< Data > &a, const smart_list< Data > &b)
 Equality, if lists contain equal elements in the same order. More...
 
template<class Data >
bool operator< (const smart_list< Data > &a, const smart_list< Data > &b)
 Lexicographical order. More...
 

Variables

const std::string ellipsis = "..."
 
const std::string unicode_minus = "−"
 
const std::string unicode_en_dash = "–"
 
const std::string unicode_em_dash = "—"
 
const std::string unicode_figure_dash = "‒"
 
const std::string unicode_multiplication_sign = "×"
 
const std::string unicode_bullet = "•"
 
typedef std::map< std::string,
t_string
string_map
 
std::string replace (std::string str, const std::string &src, const std::string &dst)
 Replace all instances of src in str with dst. More...
 
std::stringstrip (std::string &str)
 Remove whitespace from the front and back of the string 'str'. More...
 
std::stringstrip_end (std::string &str)
 Remove whitespace from the back of the string 'str'. 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 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, 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), and '?' as any one character. More...
 
void ellipsis_truncate (std::string &str, const 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...
 

Typedef Documentation

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

Definition at line 312 of file string_utils.hpp.

Enumeration Type Documentation

anonymous enum
Enumerator
REMOVE_EMPTY 

REMOVE_EMPTY : remove empty elements.

STRIP_SPACES 

STRIP_SPACES : strips leading and trailing blank spaces.

Definition at line 42 of file string_utils.hpp.

Function Documentation

int utils::apply_modifier ( const int  number,
const std::string amount,
const int  minimum 
)
template<typename T >
std::string utils::bullet_list ( const T &  v,
size_t  indent = 4,
const std::string bullet = 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 169 of file string_utils.hpp.

References i, and indent().

void utils::ellipsis_truncate ( std::string str,
const size_t  size 
)

Truncates a string to a given utf-8 character count and then appends an ellipsis.

Definition at line 850 of file string_utils.cpp.

References ellipsis, and utf8::truncate().

Referenced by windows_tray_notification::adjust_length(), and gui2::tgame_load::fill_game_list().

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

Prepend all special characters with a backslash.

Special characters are: #}+-,*=

Definition at line 225 of file string_utils.hpp.

References escape().

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

Prepends a configurable set of characters with a backslash.

Definition at line 455 of file string_utils.cpp.

References pos.

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

std::string utils::half_signed_value ( int  val)
std::string utils::indent ( const std::string string,
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 754 of file string_utils.cpp.

References split().

Referenced by bullet_list(), and gui2::twml_error::twml_error().

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

Definition at line 220 of file string_utils.cpp.

References do_interpolation().

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

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

Referenced by terrain_label::read().

static bool utils::is_username_char ( char  c)
static

Definition at line 621 of file string_utils.cpp.

Referenced by isvalid_username(), and isvalid_wildcard().

static bool utils::is_wildcard_char ( char  c)
static

Definition at line 625 of file string_utils.cpp.

Referenced by isvalid_wildcard().

static bool utils::is_word_boundary ( char  c)
static

Definition at line 703 of file string_utils.cpp.

Referenced by word_match().

bool utils::isnewline ( const char  c)
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 629 of file string_utils.cpp.

References is_username_char().

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

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

References is_username_char(), and is_wildcard_char().

Referenced by preferences::add_friend(), and preferences::add_ignore().

template<typename T >
std::string utils::join ( T const &  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 130 of file string_utils.hpp.

References i, and next.

Referenced by team::allied_human_teams(), attack_info(), BOOST_AUTO_TEST_CASE(), gui2::tlobby_main::chat_input_keypress_callback(), create_terrain_maps(), font::del_tags(), gui2::tlobby_main::do_game_join(), events::console_handler::do_layers(), campaignd::control_line::full(), help::generate_about_text(), ai::holder::get_ai_overview(), dialogs::units_list_preview_pane::get_details(), hotkey::get_names(), carryover::get_recruits(), mp::ui::handle_key_event(), wesnothd::server::handle_player_in_lobby(), events::map_command_handler< chat_command_handler >::help_command(), help::help_button::join(), game_config_manager::load_addons_cfg(), editor::mouse_action_unit::move(), wesnothd::server::read_version(), preferences::set_modifications(), dialogs::show_unit_list(), gui::floating_textbox::tab(), gui2::tdepcheck_confirm_change::tdepcheck_confirm_change(), 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(), 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(), and preferences::manager::~manager().

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

Definition at line 143 of file string_utils.hpp.

References i, and next.

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

std::map< std::string, std::string > utils::map_split ( std::string const &  val,
char  major = ',',
char  minor = ':',
int  flags = REMOVE_EMPTY|STRIP_SPACES,
std::string const &  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 319 of file string_utils.cpp.

References i, pos, and split().

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

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

Referenced by game_events::t_event_handlers::add_event_handler().

bool utils::notspace ( const char  c)

Definition at line 65 of file string_utils.cpp.

References portable_isspace().

Referenced by strip(), and strip_end().

template<class Data >
bool utils::operator< ( const smart_list< Data > &  a,
const smart_list< Data > &  b 
)
inline

Lexicographical order.

Definition at line 732 of file smart_list.hpp.

template<class Data >
bool utils::operator== ( const smart_list< Data > &  a,
const smart_list< Data > &  b 
)
inline

Equality, if lists contain equal elements in the same order.

Definition at line 713 of file smart_list.hpp.

References utils::smart_list< Data >::begin(), and utils::smart_list< Data >::end().

std::vector< std::string > utils::parenthetical_split ( std::string const &  val,
const char  separator = 0,
std::string const &  left = "(",
std::string const &  right = ")",
const int  flags = REMOVE_EMPTY|STRIP_SPACES 
)

Splits a string based either on a separator where text within parenthesis is protected from splitting (Note that one can use the same character for both the left and right parenthesis.

In this mode it usually makes only sense to have one character for the left and right parenthesis.) or if the separator == 0 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 this will find the first matching char in the left string and match against the corresponding char in the right string. In this mode, a correctly processed string should return with an odd number of elements to the vector and an empty elements are never removed as they are placeholders. hence REMOVE EMPTY only works for the separator split.

parenthetical_split("a(b)c{d}e(f{g})h",0,"({",")}") should return a vector of <"a","b","c","d","e","f{g}","h">

Definition at line 350 of file string_utils.cpp.

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

Referenced by unit::apply_builtin_effect(), image::modification::decode(), ai::manager::internal_evaluate_command(), intf_name_generator(), about::show_about(), and unit::unit().

std::pair< int, int > utils::parse_range ( std::string const &  str)
std::vector< std::pair< int, int > > utils::parse_ranges ( std::string const &  str)
bool utils::portable_isspace ( const char  c)
std::string utils::print_modifier ( const std::string mod)
inline
std::string utils::quote ( const std::string str)
inline

Surround the string 'str' with double quotes.

Definition at line 244 of file string_utils.hpp.

Referenced by main().

std::vector< std::string > utils::quoted_split ( std::string const &  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 will not cause visual problems in menus.

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

Definition at line 787 of file string_utils.cpp.

References REMOVE_EMPTY, strip(), and STRIP_SPACES.

Referenced by gui::menu::fill_items(), help::generate_contents_links(), preprocessor_data::get_chunk(), preprocessor_streambuf::get_current_file(), get_location(), lineno_string(), help::parse_config_internal(), help::section_is_referenced(), and help::topic_is_referenced().

std::string utils::replace ( std::string  str,
const std::string src,
const std::string dst 
)
std::set< std::string > utils::set_split ( std::string const &  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 50 of file string_utils.hpp.

References split().

Referenced by game_lua_kernel::intf_modify_side().

std::string utils::si_string ( double  input,
bool  base2,
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 560 of file string_utils.cpp.

References _(), and si_string_impl_stream_write().

Referenced by gui2::tnetwork_transmission::pump_monitor::process(), size_display_string(), gui2::tscreenshot_notification::tscreenshot_notification(), and gui2::tgame_cache_options::update_cache_size_display().

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

Definition at line 541 of file string_utils.cpp.

Referenced by si_string().

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

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

Definition at line 259 of file string_utils.hpp.

References signed_value().

Referenced by attack_type::accuracy_parry_description(), attack_info(), battle_prediction_pane::get_unit_strings(), time_of_day_at(), unit_alignment(), unit_box_at(), and unit_hp().

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

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

Definition at line 525 of file string_utils.cpp.

References unicode_minus.

Referenced by attack_info(), attack_type::describe_modification(), signed_percent(), and events::menu_handler::status_table().

std::vector< std::string > utils::split ( std::string const &  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.

Definition at line 110 of file string_utils.cpp.

References portable_isspace(), REMOVE_EMPTY, strip_end(), and STRIP_SPACES.

Referenced by halo::halo_impl::add(), unit_animation::add_anims(), game_events::t_event_handlers::add_event_handler(), terrain_builder::add_images_from_config(), about::add_lines(), terrain_builder::add_rotated_rules(), cutter::add_sub_image(), 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(), commandline_options::commandline_options(), savegame::convert_old_saves_1_13_1(), gui::menu::create_help_strings(), ai::default_recruitment::recruitment_aspect::create_job(), ai::default_recruitment::recruitment_aspect::create_limit(), create_terrain_maps(), events::menu_handler::custom_command(), gui2::decode_color(), default_map_generator_job::default_generate_map(), font::del_tags(), events::menu_handler::do_search(), events::console_handler::do_unit(), mp::wait::leader_preview_pane::draw_contents(), dialogs::unit_preview_pane::draw_contents(), gui::menu::draw_row(), exploder_point::exploder_point(), exploder_rect::exploder_rect(), combatant::fight(), unit_animation::fill_initial_animations(), gui2::tgame_load::filter_text_changed(), gui2::tunit_create::filter_text_changed(), unit_creator::find_location(), ng::flg_manager::find_suitable_faction(), frame_builder::frame_builder(), gui2::tlobby_main::game_filter_reload(), mp::gamebrowser::game_matches_filter(), cave_map_generator::cave_map_generator_job::generate_chambers(), help::generate_faction_topics(), default_map_generator_job::generate_name(), help::generate_sections(), help::generate_topic_text(), help::generate_topics(), ai::unit_advancements_aspect::get_advancements(), preprocessor_data::get_chunk(), image::get_localized_path(), unit::get_modification_advances(), ng::flg_manager::get_original_recruits(), ai::default_recruitment::recruitment::get_random_pattern_type_if_exists(), get_variations(), gui::filter_textbox::handle_text_changed(), indent(), display::init_flags_for_side_internal(), basic_unit_filter_impl::internal_matches_filter(), game_lua_kernel::intf_clear_menu_item(), intf_name_generator(), ai::readonly_context_impl::is_active(), gui::menu::style::item_size(), theme::label::label(), ai::default_recruitment::recruitment::leader_matches_job(), ai::default_recruitment::recruitment::limit_ok(), wesnothd::server::load_config(), game_config::load_config(), font::load_font_config(), 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::object::modify_location(), unit_type::musthave_status(), ai::formula_ai::on_create(), gui2::taddon_list::on_filtertext_changed(), help::unit_topic_generator::operator()(), terrain_builder::parse_config(), map_location::parse_directions(), gui::parse_fraction(), 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_(), mp::gamebrowser::populate_game_item_campaign_or_scenario_info(), ng::create_engine::prepare_for_campaign(), team_builder::previous_recruits(), playmp_controller::process_oos(), progressive_< T >::progressive_(), progressive_image::progressive_image(), progressive_string::progressive_string(), random_generate_map(), random_generate_scenario(), 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(), ai::default_recruitment::recruitment::recruit_matches_job(), font::render_text(), 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(), ng::create_engine::select_campaign_difficulty(), about::set_about(), play_controller::set_defeat_music_list(), gui::button::set_label(), set_split(), play_controller::set_victory_music_list(), editor::terrain_palette::setup(), square_parenthetical_split(), theme::status_item::status_item(), string2rgb(), font::subset_descriptor::subset_descriptor(), SYNCED_COMMAND_HANDLER_FUNCTION(), gui2::tcampaign_difficulty::tcampaign_difficulty(), tfilter_description::tfilter_description(), unit::unit(), unit_animation::unit_animation(), unit_race::unit_race(), version_info::version_info(), and game_events::WML_HANDLER_FUNCTION().

std::vector< std::string > utils::square_parenthetical_split ( std::string const &  val,
const char  separator = ',',
std::string const &  left = "([",
std::string const &  right = ")]",
const int  flags = REMOVE_EMPTY|STRIP_SPACES 
)

Similar to parenthetical_split, but also expands embedded square brackets.

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 to expand animation WML code. Examples: square_parenthetical_split("a[1-3](1,[5,6,7]),b[8,9]",",") should return <"a1(1,5)","a2(1,6)","a3(1,7)","b8","b9"> square_parenthetical_split("abc[07-10]") should return <"abc07","abc08","abc09","abc10"> square_parenthetical_split("a[1,2]b[3-4]:c[5,6]") should return <"a1b3:c5","a2b4:c6"> square_parenthetical_split("abc[3,1].png") should return <"abc3.png","abc2.png","abc1.png"> square_parenthetical_split("abc[de,xyz]") should return <"abcde","abcxyz"> square_parenthetical_split("abc[1*3]") should return <"abc1","abc1","abc1">

Definition at line 150 of file string_utils.cpp.

References ERR_GENERAL, i, itor, portable_isspace(), REMOVE_EMPTY, right, split(), strip(), strip_end(), and STRIP_SPACES.

Referenced by halo::halo_impl::add(), terrain_builder::add_constraints(), display::init_flags_for_side_internal(), terrain_builder::load_images(), pick_one(), progressive_image::progressive_image(), and progressive_string::progressive_string().

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

Referenced by gui2::tformula< T >::convert(), tod_manager::is_start_ToD(), campaignd::server::run(), and gui2::tcontrol::set_members().

std::string & utils::strip ( std::string str)
std::string & utils::strip_end ( std::string str)

Remove whitespace from the back of the string 'str'.

Definition at line 94 of file string_utils.cpp.

References notspace().

Referenced by parenthetical_split(), split(), and square_parenthetical_split().

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

Remove all escape characters (backslash)

Definition at line 470 of file string_utils.cpp.

References pos.

Referenced by font::draw_text().

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

References c.

Referenced by campaignd::format_addon_feedback_url().

bool utils::wildcard_string_match ( const std::string str,
const std::string match 
)
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 656 of file string_utils.cpp.

References chars_equal_insensitive().

Referenced by gui2::tlobby_main::chat_input_keypress_callback(), mp::ui::handle_key_event(), gui::floating_textbox::tab(), and gui2::tlua_interpreter::controller::tab().

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

Check if a message contains a word.

Definition at line 707 of file string_utils.cpp.

References is_word_boundary(), and next.

Referenced by display_chat_manager::add_chat_message(), gui2::tlobby_main::add_chat_room_message_received(), and mp::ui::process_message().

Variable Documentation

const std::string utils::ellipsis = "..."

Definition at line 39 of file string_utils.cpp.

Referenced by ellipsis_truncate().

const std::string utils::unicode_bullet = "•"

Definition at line 46 of file string_utils.cpp.

const std::string utils::unicode_em_dash = "—"
const std::string utils::unicode_en_dash = "–"
const std::string utils::unicode_figure_dash = "‒"

Definition at line 44 of file string_utils.cpp.

Referenced by help::unit_topic_generator::operator()(), and unit_moves().

const std::string utils::unicode_minus = "−"
const std::string utils::unicode_multiplication_sign = "×"