liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*=============================================================================
    Copyright (c) 2001-2014 Joel de Guzman
 
    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(BOOST_SPIRIT_X3_NO_CASE_STRING_PARSE_APR_18_2014_1125PM)
#define BOOST_SPIRIT_X3_NO_CASE_STRING_PARSE_APR_18_2014_1125PM
 
#include <boost/spirit/home/x3/char/char.hpp>
#include <boost/spirit/home/x3/support/traits/move_to.hpp>
 
namespace boost { namespace spirit { namespace x3 { namespace detail
{
    template <typename Char, typename Encoding>
    struct no_case_string
    {
        typedef std::basic_string< Char >  string_type;
        typedef typename string_type::const_iterator const_iterator;
 
        no_case_string(char_type const* str)
          : lower(str)
          , upper(str)
        {
            typename string_type::iterator loi = lower.begin();
            typename string_type::iterator upi = upper.begin();
 
            typedef typename Encoding::char_type encoded_char_type;
            Encoding encoding;
            for (; loi != lower.end(); ++loi, ++upi)
            {
                *loi = static_cast<char_type>(encoding.tolower(encoded_char_type(*loi)));
                *upi = static_cast<char_type>(encoding.toupper(encoded_char_type(*upi)));
            }
        }
        string_type lower;
        string_type upper;
        
    };
 
    template <typename String, typename Iterator, typename Attribute>
    inline bool no_case_string_parse(
        String const& str
      , Iterator& first, Iterator const& last, Attribute& attr)
    {
        typename String::const_iterator uc_i = str.upper.begin();
        typename String::const_iterator uc_last = str.upper.end();
        typename String::const_iterator lc_i = str.lower.begin();
        Iterator i = first;
 
        for (; uc_i != uc_last; ++uc_i, ++lc_i, ++i)
            if (i == last || ((*uc_i != *i) && (*lc_i != *i)))
                return false;
        x3::traits::move_to(first, i, attr);
        first = i;
        return true;
    }
}}}}
 
#endif