string_compare.hpp 1.9 KB

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