1 // Copyright (c) 2001-2011 Hartmut Kaiser 2 // Copyright (c) 2011 Michael Caisse 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <boost/spirit/include/qi.hpp> 8 9 namespace qi = boost::spirit::qi; 10 11 template <typename T> 12 struct german_real_policies : qi::real_policies<T> 13 { 14 template <typename Iterator> parse_dotgerman_real_policies15 static bool parse_dot(Iterator& first, Iterator const& last) 16 { 17 if (first == last || *first != ',') 18 return false; 19 ++first; 20 return true; 21 } 22 }; 23 24 qi::real_parser<double, german_real_policies<double> > const german_double; 25 26 /////////////////////////////////////////////////////////////////////////////// main()27int main() 28 { 29 std::string input("123,456"); 30 std::string::iterator begin = input.begin(); 31 std::string::iterator end = input.end(); 32 33 double value = 0; 34 if (!qi::parse(begin, end, german_double, value)) 35 { 36 std::cout << "-------------------------------- \n"; 37 std::cout << "Parsing failed\n"; 38 std::cout << "-------------------------------- \n"; 39 } 40 else 41 { 42 std::cout << "-------------------------------- \n"; 43 std::cout << "Parsing succeeded, got: " << value << "\n"; 44 std::cout << "---------------------------------\n"; 45 } 46 return 0; 47 } 48 49