Ticket #6585: wkt.patch

File wkt.patch, 2.8 KB (added by Aleksey Tulinov <aleksey.tulinov@…>, 11 years ago)

Patch for WKT parsing

  • multi/io/wkt/read.hpp

     
    5858
    5959            handle_close_parenthesis(it, tokens.end(), wkt);
    6060        }
     61       
     62        check_end(it, tokens.end(), wkt);
    6163    }
    6264};
    6365
     66template <typename P>
     67struct noparenthesis_point_parser
     68{
     69    static inline void apply(tokenizer::iterator& it, tokenizer::iterator end,
     70        std::string const& wkt, P& point)
     71    {
     72        parsing_assigner<P, 0, dimension<P>::value>::apply(it, end, point, wkt);
     73    }
     74};
     75
     76template <typename MultiGeometry, typename PrefixPolicy>
     77struct multi_point_parser
     78{
     79    static inline void apply(std::string const& wkt, MultiGeometry& geometry)
     80    {
     81        traits::clear<MultiGeometry>::apply(geometry);
     82
     83        tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
     84        tokenizer::iterator it;
     85
     86        if (initialize<MultiGeometry>(tokens, PrefixPolicy::apply(), wkt, it))
     87        {
     88            handle_open_parenthesis(it, tokens.end(), wkt);
     89
     90            // If first point definition starts with "(" then parse points as (x y)
     91            // otherwise as "x y"
     92            bool using_brackets = (it != tokens.end() && *it == "(");
     93           
     94            while(it != tokens.end() && *it != ")")
     95            {
     96                traits::resize<MultiGeometry>::apply(geometry, boost::size(geometry) + 1);
     97               
     98                if (using_brackets)
     99                {
     100                    point_parser
     101                        <
     102                            typename boost::range_value<MultiGeometry>::type
     103                        >::apply(it, tokens.end(), wkt, geometry.back());
     104                }
     105                else
     106                {
     107                    noparenthesis_point_parser
     108                        <
     109                            typename boost::range_value<MultiGeometry>::type
     110                        >::apply(it, tokens.end(), wkt, geometry.back());
     111                }
     112                   
     113                if (it != tokens.end() && *it == ",")
     114                {
     115                    // Skip "," after point is parsed
     116                    ++it;
     117                }
     118            }
     119           
     120            handle_close_parenthesis(it, tokens.end(), wkt);
     121        }
     122       
     123        check_end(it, tokens.end(), wkt);
     124    }
     125};
     126
    64127}} // namespace detail::wkt
    65128
    66129#ifndef DOXYGEN_NO_DISPATCH
     
    69132
    70133template <typename MultiGeometry>
    71134struct read_wkt<multi_point_tag, MultiGeometry>
    72     : detail::wkt::multi_parser
     135    : detail::wkt::multi_point_parser
    73136            <
    74137                MultiGeometry,
    75                 detail::wkt::point_parser,
    76138                detail::wkt::prefix_multipoint
    77139            >
    78140{};