24 #define ERR_NG LOG_STREAM(err, log_engine)
26 static bool two_dots(
char a,
char b) {
return a ==
'.' && b ==
'.'; }
38 const string_map::const_iterator
itor =
map_.find(key);
39 if (itor !=
map_.end())
54 int rfind_dollars_sign_from = res.size();
55 while(rfind_dollars_sign_from >= 0) {
58 const std::string::size_type var_begin_loc = res.rfind(
'$', rfind_dollars_sign_from);
61 if(var_begin_loc == std::string::npos) {
67 rfind_dollars_sign_from =
int(var_begin_loc) - 1;
76 if(var_name_begin == res.end()) {
79 }
else if(*var_name_begin ==
'(') {
81 int paren_nesting_level = 0;
82 bool in_string =
false,
87 if(!in_string && !in_comment) {
88 ++paren_nesting_level;
92 if(!in_string && !in_comment) {
93 --paren_nesting_level;
98 in_comment = !in_comment;
103 in_string = !in_string;
108 }
while(++var_end != res.end() && paren_nesting_level > 0);
109 if(paren_nesting_level > 0) {
110 ERR_NG <<
"Formula in WML string cannot be evaluated due to "
111 <<
"a missing closing parenthesis:\n\t--> \""
113 res.replace(var_begin, var_end,
"");
120 ERR_NG <<
"Formula in WML string cannot be evaluated due to "
121 << e.
type <<
"\n\t--> \""
123 res.replace(var_begin, var_end,
"");
129 for(
int bracket_nesting_level = 0; var_end != res.end(); ++var_end) {
130 const char c = *var_end;
132 ++bracket_nesting_level;
135 if(--bracket_nesting_level < 0) {
140 else if (!(((c) & ~0x7f) == 0) || (!isalnum(c) && c !=
'.' && c !=
'_')) {
147 var_end = std::adjacent_find(var_name_begin, var_end,
two_dots);
149 const std::string::iterator default_start = var_end < res.end() && *var_end ==
'?' ? var_end + 1 : res.end();
156 if(*(var_end-1) ==
'.'
163 && *(var_end-2) !=
']') {
167 const std::string var_name(var_name_begin, var_end);
168 if(default_start == res.end()) {
169 if(var_end != res.end() && *var_end ==
'|') {
179 if (var_name ==
"") {
182 res.replace(var_begin, var_end,
"$");
186 res.replace(var_begin, var_end,
191 var_end = default_start;
192 while(var_end != res.end() && *var_end !=
'|') {
197 if(var_end == res.end()) {
198 res.replace(var_begin, default_start - 1, val);
200 else if(!val.
blank()) {
201 res.replace(var_begin, var_end + 1, val);
204 res.replace(var_begin, var_end + 1,
std::string(default_start, default_end));
227 if(!tstr.
str().empty()) {
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 ...
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
std::string dgettext(const char *domain, const char *msgid)
GLuint const GLfloat * val
Definitions for the interface to Wesnoth Markup Language (WML).
Variant for storing WML attributes.
bool blank() const
Tests for an attribute that was never set.
GLdouble GLdouble GLdouble b
static UNUSEDNOWARN std::string _(const char *str)
std::map< std::string, t_string > string_map
GLboolean GLboolean GLboolean GLboolean a
static UNUSEDNOWARN std::string _n(const char *str1, const char *str2, int n)
std::string string_cast() const
string_map_variable_set(const string_map &map)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
std::map< std::string, tfilter >::iterator itor
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
virtual config::attribute_value get_variable_const(const std::string &id) const =0
Standard logging facilities (interface).
virtual config::attribute_value get_variable_const(const std::string &key) const
const std::string & str() const
t_string interpolate_variables_into_tstring(const t_string &tstr, const variable_set &variables)
Function that does the same as the above, for t_stringS.
GLsizei const GLcharARB ** string