string_compare.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  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. #if !defined(BOOST_SPIRIT_KARMA_STRING_COMPARE_AUG_08_2009_0756PM)
  6. #define BOOST_SPIRIT_KARMA_STRING_COMPARE_AUG_08_2009_0756PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <string>
  11. #include <boost/spirit/home/support/char_class.hpp>
  12. #include <boost/spirit/home/karma/detail/generate_to.hpp>
  13. #include <boost/range/iterator_range.hpp>
  14. namespace boost { namespace spirit { namespace karma { namespace detail
  15. {
  16. template <typename Char>
  17. bool string_compare(Char const* attr, Char const* lit)
  18. {
  19. Char ch_attr = *attr;
  20. Char ch_lit = *lit;
  21. while (!!ch_lit && !!ch_attr)
  22. {
  23. if (ch_attr != ch_lit)
  24. return false;
  25. ch_attr = *++attr;
  26. ch_lit = *++lit;
  27. }
  28. return !ch_lit && !ch_attr;
  29. }
  30. template <typename Char>
  31. bool string_compare(Char const* attr, Char const* lit, unused_type, unused_type)
  32. {
  33. return string_compare(attr, lit);
  34. }
  35. template <typename Char>
  36. bool string_compare(unused_type, Char const*, unused_type, unused_type)
  37. {
  38. return true;
  39. }
  40. template <typename Char, typename CharEncoding, typename Tag>
  41. bool string_compare(Char const* attr, Char const* lit, CharEncoding, Tag)
  42. {
  43. Char ch_attr = *attr;
  44. Char ch_lit = spirit::char_class::convert<CharEncoding>::to(Tag(), *lit);
  45. while (!!ch_lit && !!ch_attr)
  46. {
  47. if (ch_attr != ch_lit)
  48. return false;
  49. ch_attr = *++attr;
  50. ch_lit = spirit::char_class::convert<CharEncoding>::to(Tag(), *++lit);
  51. }
  52. return !ch_lit && !ch_attr;
  53. }
  54. template <typename Char, typename CharEncoding, typename Tag>
  55. bool string_compare(unused_type, Char const*, CharEncoding, Tag)
  56. {
  57. return true;
  58. }
  59. }}}}
  60. #endif