Merge branch 'master' into spirit-x3
This commit is contained in:
commit
5994eb463a
3 changed files with 57 additions and 5 deletions
|
@ -710,14 +710,55 @@ struct to_unicode_impl
|
|||
|
||||
struct to_expression_string_impl
|
||||
{
|
||||
struct EscapingByteSink : U_NAMESPACE_QUALIFIER ByteSink
|
||||
{
|
||||
std::string dest_;
|
||||
char quote_;
|
||||
|
||||
explicit EscapingByteSink(char quote)
|
||||
: quote_(quote)
|
||||
{}
|
||||
|
||||
virtual void Append(const char* data, int32_t n)
|
||||
{
|
||||
// reserve enough room to hold the appended chunk and quotes;
|
||||
// if another chunk follows, or any character needs escaping,
|
||||
// the string will grow naturally
|
||||
if (dest_.empty())
|
||||
{
|
||||
dest_.reserve(2 + static_cast<std::size_t>(n));
|
||||
dest_.append(1, quote_);
|
||||
}
|
||||
else
|
||||
{
|
||||
dest_.reserve(dest_.size() + n + 1);
|
||||
}
|
||||
|
||||
for (auto end = data + n; data < end; ++data)
|
||||
{
|
||||
if (*data == '\\' || *data == quote_)
|
||||
dest_.append(1, '\\');
|
||||
dest_.append(1, *data);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Flush()
|
||||
{
|
||||
if (dest_.empty())
|
||||
dest_.append(2, quote_);
|
||||
else
|
||||
dest_.append(1, quote_);
|
||||
}
|
||||
};
|
||||
|
||||
explicit to_expression_string_impl(char quote = '\'')
|
||||
: quote_(quote) {}
|
||||
|
||||
std::string operator() (value_unicode_string const& val) const
|
||||
{
|
||||
std::string utf8;
|
||||
to_utf8(val,utf8);
|
||||
return quote_ + utf8 + quote_;
|
||||
EscapingByteSink sink(quote_);
|
||||
val.toUTF8(sink);
|
||||
return sink.dest_;
|
||||
}
|
||||
|
||||
std::string operator() (value_integer val) const
|
||||
|
|
|
@ -89,6 +89,8 @@ TEST_CASE("expressions")
|
|||
// unicode
|
||||
TRY_CHECK(parse_and_dump("'single-quoted string'") == "'single-quoted string'");
|
||||
TRY_CHECK(parse_and_dump("\"double-quoted string\"") == "'double-quoted string'");
|
||||
TRY_CHECK(parse_and_dump("'escaped \\' apostrophe'") == "'escaped \\' apostrophe'");
|
||||
TRY_CHECK(parse_and_dump("'escaped \\\\ backslash'") == "'escaped \\\\ backslash'");
|
||||
|
||||
// floating point constants
|
||||
TRY_CHECK(parse_and_dump("pi") == "3.14159");
|
||||
|
@ -159,8 +161,13 @@ TEST_CASE("expressions")
|
|||
// regex
|
||||
// replace
|
||||
TRY_CHECK(eval(" [foo].replace('(\\B)|( )','$1 ') ") == tr.transcode("b a r"));
|
||||
// 'foo' =~ s:(\w)\1:$1x:r
|
||||
TRY_CHECK(eval(" 'foo'.replace('(\\w)\\1', '$1x') ") == tr.transcode("fox"));
|
||||
TRY_CHECK(parse_and_dump(" 'foo'.replace('(\\w)\\1', '$1x') ") == "'foo'.replace('(\\w)\\1','$1x')");
|
||||
|
||||
// match
|
||||
TRY_CHECK(eval(" [name].match('Québec') ") == true);
|
||||
|
||||
// 'Québec' =~ m:^Q\S*$:
|
||||
TRY_CHECK(eval(" [name].match('^Q\\S*$') ") == true);
|
||||
TRY_CHECK(parse_and_dump(" [name].match('^Q\\S*$') ") == "[name].match('^Q\\S*$')");
|
||||
}
|
||||
|
|
|
@ -434,8 +434,11 @@ SECTION("test colorize-alpha - parsing correct input") {
|
|||
|
||||
std::string s("colorize-alpha(#0000ff 0%, #00ff00 100%)");
|
||||
std::vector<mapnik::filter::filter_type> f;
|
||||
CHECK(parse_image_filters(s, f));
|
||||
REQUIRE(parse_image_filters(s, f));
|
||||
mapnik::filter::colorize_alpha const & ca = mapnik::util::get<mapnik::filter::colorize_alpha>(f.front());
|
||||
CHECK(ca.size() == 2);
|
||||
|
||||
CHECKED_IF(ca.size() > 0)
|
||||
{
|
||||
mapnik::filter::color_stop const & s2 = ca[0];
|
||||
CHECK( s2.color.alpha() == 0xff );
|
||||
|
@ -445,6 +448,7 @@ SECTION("test colorize-alpha - parsing correct input") {
|
|||
CHECK( s2.offset == 0.0 );
|
||||
}
|
||||
|
||||
CHECKED_IF(ca.size() > 1)
|
||||
{
|
||||
mapnik::filter::color_stop const & s2 = ca[1];
|
||||
CHECK( s2.color.alpha() == 0xff );
|
||||
|
|
Loading…
Reference in a new issue