The Battle for Wesnoth  1.19.0-dev
Namespaces | Macros | Functions
string_utils.hpp File Reference
#include "gettext.hpp"
#include "serialization/string_utils.hpp"
#include <ctime>
#include <string_view>
Include dependency graph for string_utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 utils
 
 utils::detail
 

Macros

#define VGETTEXT(msgid, ...)    vgettext_impl(GETTEXT_DOMAIN, msgid, __VA_ARGS__)
 Handy wrappers around interpolate_variables_into_string and gettext. More...
 
#define VNGETTEXT(msgid, msgid_plural, count, ...)    vngettext_impl(GETTEXT_DOMAIN, msgid, msgid_plural, count, __VA_ARGS__)
 

Functions

bool utils::might_contain_variables (const std::string &str)
 Determines if a string might contain variables to interpolate. More...
 
std::string utils::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...
 
std::string utils::interpolate_variables_into_string (const std::string &str, const std::map< std::string, std::string > *const symbols)
 
std::string utils::interpolate_variables_into_string (const std::string &str, const variable_set &variables)
 
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. More...
 
std::string utils::format_conjunct_list (const t_string &empty, const std::vector< t_string > &elems)
 Format a conjunctive list. More...
 
std::string utils::format_disjunct_list (const t_string &empty, const std::vector< t_string > &elems)
 Format a disjunctive list. More...
 
std::string utils::format_timespan (std::time_t time, bool detailed=false)
 Formats a timespan into human-readable text for player authentication functions. More...
 
std::string vgettext_impl (const char *domain, const char *msgid, const utils::string_map &symbols)
 Implementation functions for the VGETTEXT and VNGETTEXT macros. More...
 
std::string vngettext_impl (const char *domain, const char *singular, const char *plural, int count, const utils::string_map &symbols)
 
std::size_t edit_distance_approx (std::string_view str_1, std::string_view str_2) noexcept
 Calculate the approximate edit distance of two strings. More...
 

Macro Definition Documentation

◆ VGETTEXT

#define VGETTEXT (   msgid,
  ... 
)     vgettext_impl(GETTEXT_DOMAIN, msgid, __VA_ARGS__)

Handy wrappers around interpolate_variables_into_string and gettext.

These should cover most usecases. If you're not sure whether you want these macros or their implementation functions, use these. The only time you should need to use the implementation functions directly is to pass a different textdomain than the current value of GETTEXT_DOMAIN.

Definition at line 128 of file string_utils.hpp.

◆ VNGETTEXT

#define VNGETTEXT (   msgid,
  msgid_plural,
  count,
  ... 
)     vngettext_impl(GETTEXT_DOMAIN, msgid, msgid_plural, count, __VA_ARGS__)

Definition at line 131 of file string_utils.hpp.

Function Documentation

◆ edit_distance_approx()

std::size_t edit_distance_approx ( std::string_view  str_1,
std::string_view  str_2 
)
noexcept

Calculate the approximate edit distance of two strings.

Parameters
str_1First string to compare.
str_2Second string to compare.
Returns
A score indicating how different the two strings are–the lower the score, the more similar the strings are.
Note
To avoid dynamic allocation, this function limits the number of characters that participate in the comparison.

Definition at line 364 of file string_utils.cpp.

References i, and swap().

Referenced by events::map_command_handler< Worker >::dispatch().

◆ vgettext_impl()

std::string vgettext_impl ( const char *  domain,
const char *  msgid,
const utils::string_map symbols 
)

Implementation functions for the VGETTEXT and VNGETTEXT macros.

DO NOT USE DIRECTLY unless you really know what you're doing. See https://github.com/wesnoth/wesnoth/issues/2716 for more info.

Definition at line 344 of file string_utils.cpp.

References translation::dsgettext(), utils::interpolate_variables_into_string(), and wfl::msg().

Referenced by gui2::dialogs::mp_staging::pre_show().

◆ vngettext_impl()

std::string vngettext_impl ( const char *  domain,
const char *  singular,
const char *  plural,
int  count,
const utils::string_map symbols 
)