r38987 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r38986‎ | r38987 | r38988 >
Date:10:33, 9 August 2008
Author:river
Status:old
Tags:
Comment:
support string escapes: \b \t \n \f \r \\ \" \' \xHH \OOO
Modified paths:
  • /trunk/extensions/AbuseFilter/parser_native/parser.cpp (modified) (history)

Diff [purge]

Index: trunk/extensions/AbuseFilter/parser_native/parser.cpp
@@ -151,8 +151,22 @@
152152 return datum::from_double(args[0].toFloat());
153153 }
154154
 155+datum
 156+f_append(datum const &a, char b)
 157+{
 158+ return datum::from_string(a.toString() + b);
155159 }
156160
 161+datum
 162+f_strip_last(datum const &a)
 163+{
 164+ std::string s(a.toString());
 165+ s.resize(s.size() - 1);
 166+ return datum::from_string(s);
 167+}
 168+
 169+}
 170+
157171 /*
158172 * This is the closure types for functions. 'val' stores the final result of
159173 * the function call; func and args store the function object and the parsed
@@ -261,9 +275,15 @@
262276 | bin_p[value.val = bind(&datum::from_int)(arg1)] >> 'b'
263277 | int_p[value.val = bind(&datum::from_int)(arg1)]
264278 ]
265 - | confix_p('"', *c_escape_ch_p, '"')[
266 - value.val = bind(&datum::from_string)(construct_<std::string>(arg1 + 1, arg2 - 1))
267 - ]
 279+ /*
 280+ * config_p can't be used here, because it will rewrite
 281+ * *(c_escape_ch_p[x]) into (*c_escape_ch_p)[x]
 282+ */
 283+ | (
 284+ ch_p('"')[value.val = ""]
 285+ >> *((c_escape_ch_p[value.val = bind(&f_append)(value.val, arg1)] - '"'))
 286+ >> ch_p('"')[value.val = bind(&f_strip_last)(value.val)]
 287+ )
268288 ;
269289
270290 /*

Status & tagging log