]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/include/boost/spirit/home/classic/utility/impl/regex.ipp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / classic / utility / impl / regex.ipp
1 /*=============================================================================
2 Copyright (c) 2002-2003 Hartmut Kaiser
3 http://spirit.sourceforge.net/
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #ifndef BOOST_SPIRIT_REGEX_IPP
10 #define BOOST_SPIRIT_REGEX_IPP
11
12 ///////////////////////////////////////////////////////////////////////////////
13 #include <boost/spirit/home/classic/core/primitives/impl/primitives.ipp>
14
15 ///////////////////////////////////////////////////////////////////////////////
16 namespace boost { namespace spirit {
17
18 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
19
20 namespace impl {
21
22 ///////////////////////////////////////////////////////////////////////////////
23 //
24 inline const char* rx_prefix(char) { return "\\A"; }
25 inline const wchar_t* rx_prefix(wchar_t) { return L"\\A"; }
26
27 ///////////////////////////////////////////////////////////////////////////////
28 //
29 // rx_parser class
30 //
31 ///////////////////////////////////////////////////////////////////////////////
32 template <typename CharT = char>
33 class rx_parser : public parser<rx_parser<CharT> > {
34
35 public:
36 typedef std::basic_string<CharT> string_t;
37 typedef rx_parser<CharT> self_t;
38
39 rx_parser(CharT const *first, CharT const *last)
40 {
41 rxstr = string_t(rx_prefix(CharT())) + string_t(first, last);
42 }
43
44 rx_parser(CharT const *first)
45 {
46 rxstr = string_t(rx_prefix(CharT())) +
47 string_t(first, impl::get_last(first));
48 }
49
50 template <typename ScannerT>
51 typename parser_result<self_t, ScannerT>::type
52 parse(ScannerT const& scan) const
53 {
54 boost::match_results<typename ScannerT::iterator_t> what;
55 boost::regex_search(scan.first, scan.last, what, rxstr,
56 boost::match_default);
57
58 if (!what[0].matched)
59 return scan.no_match();
60
61 scan.first = what[0].second;
62 return scan.create_match(what[0].length(), nil_t(),
63 what[0].first, scan.first);
64 }
65
66 private:
67 #if BOOST_VERSION >= 013300
68 boost::basic_regex<CharT> rxstr; // regular expression to match
69 #else
70 boost::reg_expression<CharT> rxstr; // regular expression to match
71 #endif
72 };
73
74 } // namespace impl
75
76 ///////////////////////////////////////////////////////////////////////////////
77 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
78
79 }} // namespace boost::spirit
80
81 #endif // BOOST_SPIRIT_REGEX_IPP