german_floating_point.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <boost/spirit/include/qi.hpp>
  7. namespace qi = boost::spirit::qi;
  8. template <typename T>
  9. struct german_real_policies : qi::real_policies<T>
  10. {
  11. template <typename Iterator>
  12. static bool parse_dot(Iterator& first, Iterator const& last)
  13. {
  14. if (first == last || *first != ',')
  15. return false;
  16. ++first;
  17. return true;
  18. }
  19. };
  20. qi::real_parser<double, german_real_policies<double> > const german_double;
  21. ///////////////////////////////////////////////////////////////////////////////
  22. int main()
  23. {
  24. std::string input("123,456");
  25. std::string::iterator begin = input.begin();
  26. std::string::iterator end = input.end();
  27. double value = 0;
  28. if (!qi::parse(begin, end, german_double, value))
  29. {
  30. std::cout << "-------------------------------- \n";
  31. std::cout << "Parsing failed\n";
  32. std::cout << "-------------------------------- \n";
  33. }
  34. else
  35. {
  36. std::cout << "-------------------------------- \n";
  37. std::cout << "Parsing succeeded, got: " << value << "\n";
  38. std::cout << "---------------------------------\n";
  39. }
  40. return 0;
  41. }