diff options
author | David Tardon <dtardon@redhat.com> | 2017-05-16 12:26:25 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2017-05-16 15:01:58 +0200 |
commit | 39a8567ff10e2b3ca4c7a3be0d6604cb881819f4 (patch) | |
tree | 4d6b1dabf8e634fe7ccfc726230a53706feded67 | |
parent | dba3da11773e10ee672be3a91ef523eb82c57932 (diff) |
replace Spirit.Classic by Qi
Change-Id: I9314e123dbd8346fa7e484f9dede3a0379574bd6
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | src/lib/ABWCollector.cpp | 88 | ||||
-rw-r--r-- | src/lib/ABWContentCollector.cpp | 31 | ||||
-rw-r--r-- | src/lib/ABWParser.cpp | 31 |
4 files changed, 53 insertions, 100 deletions
diff --git a/configure.ac b/configure.ac index 19deca2..8ad877d 100644 --- a/configure.ac +++ b/configure.ac @@ -265,7 +265,8 @@ AC_SUBST(ZLIB_LIBS) AC_CHECK_HEADERS( boost/algorithm/string.hpp \ boost/optional.hpp \ - boost/spirit/include/classic.hpp, + boost/spirit/include/qi.hpp \ + , [], [AC_MSG_ERROR([Required boost headers not found.])], [] diff --git a/src/lib/ABWCollector.cpp b/src/lib/ABWCollector.cpp index 7a38735..1bfb918 100644 --- a/src/lib/ABWCollector.cpp +++ b/src/lib/ABWCollector.cpp @@ -8,23 +8,20 @@ */ #include <boost/algorithm/string.hpp> -#include <boost/spirit/include/classic.hpp> +#include <boost/optional.hpp> +#include <boost/spirit/include/qi.hpp> + #include "ABWCollector.h" bool libabw::findInt(const std::string &str, int &res) { - using namespace boost::spirit::classic; + using namespace boost::spirit::qi; if (str.empty()) return false; - return parse(str.c_str(), - // Begin grammar - ( - int_p[assign_a(res)] - ) >> end_p, - // End grammar - space_p).full; + auto it = str.cbegin(); + return phrase_parse(it, str.cend(), int_, space, res) && it == str.cend(); } void libabw::parsePropString(const std::string &str, ABWPropertyMap &props) @@ -47,67 +44,38 @@ void libabw::parsePropString(const std::string &str, ABWPropertyMap &props) bool libabw::findDouble(const std::string &str, double &res, ABWUnit &unit) { - using namespace boost::spirit::classic; + using namespace boost::spirit::qi; if (str.empty()) return false; - unit = ABW_NONE; - - if (!parse(str.c_str(), - // Begin grammar - ( - real_p[assign_a(res)] >> - ( - str_p("cm")[assign_a(unit,ABW_CM)] - | - str_p("inch")[assign_a(unit,ABW_IN)] - | - str_p("in")[assign_a(unit,ABW_IN)] - | - str_p("mm")[assign_a(unit,ABW_MM)] - | - str_p("pi")[assign_a(unit,ABW_PI)] - | - str_p("pt")[assign_a(unit,ABW_PT)] - | - str_p("px")[assign_a(unit,ABW_PT)] - | - str_p("%")[assign_a(unit,ABW_PERCENT)] - | - eps_p - ) - ) >> end_p, - // End grammar - space_p).full) - { + symbols<char, std::pair<ABWUnit, double>> units; + units.add + ("cm", {ABW_IN, 2.54}) + ("inch", {ABW_IN, 1.0}) + ("in", {ABW_IN, 1.0}) + ("mm", {ABW_IN, 25.4}) + ("pi", {ABW_IN, 6.0}) + ("pt", {ABW_IN, 72.0}) + ("px", {ABW_IN, 72.0}) + ("%", {ABW_PERCENT, 100.0}) + ; + + boost::optional<std::pair<ABWUnit, double>> u; + + auto it = str.cbegin(); + if (!phrase_parse(it, str.cend(), double_ >> -units, space, res, u) || it != str.cend()) return false; - } - if (unit == ABW_PERCENT) - res /= 100.0; - if (unit == ABW_PI) - { - res = res / 6.0; - unit = ABW_IN; - } - if (unit == ABW_PT || unit == ABW_PX) + if (u) { - res = res / 72.0; - unit = ABW_IN; + unit = get(u).first; + res /= get(u).second; } - if (unit == ABW_CM) + else { - res = res / 2.54; - unit = ABW_IN; - } - if (unit == ABW_MM) - { - res = res / 25.4; - unit = ABW_IN; - } - if (unit == ABW_NONE) unit = ABW_PERCENT; + } return true; } diff --git a/src/lib/ABWContentCollector.cpp b/src/lib/ABWContentCollector.cpp index 725195a..a28bc08 100644 --- a/src/lib/ABWContentCollector.cpp +++ b/src/lib/ABWContentCollector.cpp @@ -12,7 +12,7 @@ #include <memory> #include <sstream> -#include <boost/spirit/include/classic.hpp> +#include <boost/spirit/include/qi.hpp> #include <boost/algorithm/string.hpp> #include <boost/optional.hpp> #include <librevenge/librevenge.h> @@ -244,31 +244,22 @@ void parseLang(const std::string &langStr, optional<std::string> &lang, optional static std::string decodeUrl(const std::string &str) { - using namespace boost::spirit::classic; + using namespace boost::spirit::qi; if (str.empty()) return str; // look for a hexadecimal number of 2 digits - uint_parser<char,16,2,2> urlhex_p; + uint_parser<char,16,2,2> urlhex; std::string decoded_string; - if (parse(str.c_str(), - // Begin grammar - *( - (ch_p('%') >> - ( - urlhex_p[push_back_a(decoded_string)] - | - ch_p('%')[push_back_a(decoded_string)] - ) - ) - | - ( - (~ch_p('%'))[push_back_a(decoded_string)] - ) - ) >> end_p, - // End grammar - space_p).full) + auto it = str.cbegin(); + if (parse(it, str.cend(), + +( + (lit('%') >> (char_('%') | urlhex)) + | (!lit('%') >> char_) + ), + decoded_string) + && it == str.cend()) return decoded_string; return str; diff --git a/src/lib/ABWParser.cpp b/src/lib/ABWParser.cpp index a56018f..16826e2 100644 --- a/src/lib/ABWParser.cpp +++ b/src/lib/ABWParser.cpp @@ -16,7 +16,7 @@ #include <libxml/xmlIO.h> #include <libxml/xmlstring.h> #include <librevenge-stream/librevenge-stream.h> -#include <boost/spirit/include/classic.hpp> +#include <boost/spirit/include/qi.hpp> #include "ABWParser.h" #include "ABWContentCollector.h" #include "ABWStylesCollector.h" @@ -33,28 +33,21 @@ namespace static bool findBool(const std::string &str, bool &res) { - using namespace boost::spirit::classic; + using namespace boost::spirit::qi; if (str.empty()) return false; - return parse(str.c_str(), - // Begin grammar - ( - str_p("true")[assign_a(res,true)] - | - str_p("false")[assign_a(res,false)] - | - str_p("yes")[assign_a(res,true)] - | - str_p("no")[assign_a(res,false)] - | - str_p("TRUE")[assign_a(res,true)] - | - str_p("FALSE")[assign_a(res,false)] - ) >> end_p, - // End grammar - space_p).full; + symbols<char, bool> bools; + bools.add + ("true", true) + ("false", false) + ("yes", true) + ("no", false) + ; + + auto it = str.cbegin(); + return phrase_parse(it, str.cend(), no_case[bools], space, res) && it == str.cend(); } // small function needed to call the xml BAD_CAST on a char const * |