• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2014 Joel de Guzman
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 ==============================================================================*/
7 #if !defined(BOOST_SPIRIT_X3_STRING_PARSE_APR_18_2006_1125PM)
8 #define BOOST_SPIRIT_X3_STRING_PARSE_APR_18_2006_1125PM
9 
10 #include <boost/spirit/home/x3/support/traits/move_to.hpp>
11 
12 namespace boost { namespace spirit { namespace x3 { namespace detail
13 {
14     template <typename Char, typename Iterator, typename Attribute, typename CaseCompareFunc>
string_parse(Char const * str,Iterator & first,Iterator const & last,Attribute & attr,CaseCompareFunc const & compare)15     inline bool string_parse(
16         Char const* str
17       , Iterator& first, Iterator const& last, Attribute& attr, CaseCompareFunc const& compare)
18     {
19         Iterator i = first;
20         Char ch = *str;
21 
22         for (; !!ch; ++i)
23         {
24             if (i == last || (compare(ch, *i) != 0))
25                 return false;
26             ch = *++str;
27         }
28 
29         x3::traits::move_to(first, i, attr);
30         first = i;
31         return true;
32     }
33 
34     template <typename String, typename Iterator, typename Attribute, typename CaseCompareFunc>
string_parse(String const & str,Iterator & first,Iterator const & last,Attribute & attr,CaseCompareFunc const & compare)35     inline bool string_parse(
36         String const& str
37       , Iterator& first, Iterator const& last, Attribute& attr, CaseCompareFunc const& compare)
38     {
39         Iterator i = first;
40         typename String::const_iterator stri = str.begin();
41         typename String::const_iterator str_last = str.end();
42 
43         for (; stri != str_last; ++stri, ++i)
44             if (i == last || (compare(*stri, *i) != 0))
45                 return false;
46         x3::traits::move_to(first, i, attr);
47         first = i;
48         return true;
49     }
50 
51     template <typename Char, typename Iterator, typename Attribute>
string_parse(Char const * uc_i,Char const * lc_i,Iterator & first,Iterator const & last,Attribute & attr)52     inline bool string_parse(
53         Char const* uc_i, Char const* lc_i
54       , Iterator& first, Iterator const& last, Attribute& attr)
55     {
56         Iterator i = first;
57 
58         for (; *uc_i && *lc_i; ++uc_i, ++lc_i, ++i)
59             if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
60                 return false;
61         x3::traits::move_to(first, i, attr);
62         first = i;
63         return true;
64     }
65 
66     template <typename String, typename Iterator, typename Attribute>
string_parse(String const & ucstr,String const & lcstr,Iterator & first,Iterator const & last,Attribute & attr)67     inline bool string_parse(
68         String const& ucstr, String const& lcstr
69       , Iterator& first, Iterator const& last, Attribute& attr)
70     {
71         typename String::const_iterator uc_i = ucstr.begin();
72         typename String::const_iterator uc_last = ucstr.end();
73         typename String::const_iterator lc_i = lcstr.begin();
74         Iterator i = first;
75 
76         for (; uc_i != uc_last; ++uc_i, ++lc_i, ++i)
77             if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
78                 return false;
79         x3::traits::move_to(first, i, attr);
80         first = i;
81         return true;
82     }
83 }}}}
84 
85 #endif
86