string_parse.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_SPIRIT_X3_STRING_PARSE_APR_18_2006_1125PM)
  7. #define BOOST_SPIRIT_X3_STRING_PARSE_APR_18_2006_1125PM
  8. #include <boost/spirit/home/x3/support/traits/move_to.hpp>
  9. namespace boost { namespace spirit { namespace x3 { namespace detail
  10. {
  11. template <typename Char, typename Iterator, typename Attribute, typename CaseCompareFunc>
  12. inline bool string_parse(
  13. Char const* str
  14. , Iterator& first, Iterator const& last, Attribute& attr, CaseCompareFunc const& compare)
  15. {
  16. Iterator i = first;
  17. Char ch = *str;
  18. for (; !!ch; ++i)
  19. {
  20. if (i == last || (compare(ch, *i) != 0))
  21. return false;
  22. ch = *++str;
  23. }
  24. x3::traits::move_to(first, i, attr);
  25. first = i;
  26. return true;
  27. }
  28. template <typename String, typename Iterator, typename Attribute, typename CaseCompareFunc>
  29. inline bool string_parse(
  30. String const& str
  31. , Iterator& first, Iterator const& last, Attribute& attr, CaseCompareFunc const& compare)
  32. {
  33. Iterator i = first;
  34. typename String::const_iterator stri = str.begin();
  35. typename String::const_iterator str_last = str.end();
  36. for (; stri != str_last; ++stri, ++i)
  37. if (i == last || (compare(*stri, *i) != 0))
  38. return false;
  39. x3::traits::move_to(first, i, attr);
  40. first = i;
  41. return true;
  42. }
  43. template <typename Char, typename Iterator, typename Attribute>
  44. inline bool string_parse(
  45. Char const* uc_i, Char const* lc_i
  46. , Iterator& first, Iterator const& last, Attribute& attr)
  47. {
  48. Iterator i = first;
  49. for (; *uc_i && *lc_i; ++uc_i, ++lc_i, ++i)
  50. if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
  51. return false;
  52. x3::traits::move_to(first, i, attr);
  53. first = i;
  54. return true;
  55. }
  56. template <typename String, typename Iterator, typename Attribute>
  57. inline bool string_parse(
  58. String const& ucstr, String const& lcstr
  59. , Iterator& first, Iterator const& last, Attribute& attr)
  60. {
  61. typename String::const_iterator uc_i = ucstr.begin();
  62. typename String::const_iterator uc_last = ucstr.end();
  63. typename String::const_iterator lc_i = lcstr.begin();
  64. Iterator i = first;
  65. for (; uc_i != uc_last; ++uc_i, ++lc_i, ++i)
  66. if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
  67. return false;
  68. x3::traits::move_to(first, i, attr);
  69. first = i;
  70. return true;
  71. }
  72. }}}}
  73. #endif