string_parse.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 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_STRING_PARSE_APR_18_2006_1125PM)
  7. #define BOOST_SPIRIT_STRING_PARSE_APR_18_2006_1125PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/qi/detail/assign_to.hpp>
  12. namespace boost { namespace spirit { namespace qi { namespace detail
  13. {
  14. template <typename Char, typename Iterator, typename Attribute>
  15. inline bool string_parse(
  16. Char const* str
  17. , Iterator& first, Iterator const& last, Attribute& attr)
  18. {
  19. Iterator i = first;
  20. Char ch = *str;
  21. for (; !!ch; ++i)
  22. {
  23. if (i == last || (ch != *i))
  24. return false;
  25. ch = *++str;
  26. }
  27. spirit::traits::assign_to(first, i, attr);
  28. first = i;
  29. return true;
  30. }
  31. template <typename String, typename Iterator, typename Attribute>
  32. inline bool string_parse(
  33. String const& str
  34. , Iterator& first, Iterator const& last, Attribute& attr)
  35. {
  36. Iterator i = first;
  37. typename String::const_iterator stri = str.begin();
  38. typename String::const_iterator str_last = str.end();
  39. for (; stri != str_last; ++stri, ++i)
  40. if (i == last || (*stri != *i))
  41. return false;
  42. spirit::traits::assign_to(first, i, attr);
  43. first = i;
  44. return true;
  45. }
  46. template <typename Char, typename Iterator, typename Attribute>
  47. inline bool string_parse(
  48. Char const* uc_i, Char const* lc_i
  49. , Iterator& first, Iterator const& last, Attribute& attr)
  50. {
  51. Iterator i = first;
  52. for (; *uc_i && *lc_i; ++uc_i, ++lc_i, ++i)
  53. if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
  54. return false;
  55. spirit::traits::assign_to(first, i, attr);
  56. first = i;
  57. return true;
  58. }
  59. template <typename String, typename Iterator, typename Attribute>
  60. inline bool string_parse(
  61. String const& ucstr, String const& lcstr
  62. , Iterator& first, Iterator const& last, Attribute& attr)
  63. {
  64. typename String::const_iterator uc_i = ucstr.begin();
  65. typename String::const_iterator uc_last = ucstr.end();
  66. typename String::const_iterator lc_i = lcstr.begin();
  67. Iterator i = first;
  68. for (; uc_i != uc_last; ++uc_i, ++lc_i, ++i)
  69. if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
  70. return false;
  71. spirit::traits::assign_to(first, i, attr);
  72. first = i;
  73. return true;
  74. }
  75. }}}}
  76. #endif