source: NonGTP/Boost/boost/spirit/utility/impl/regex.ipp @ 857

Revision 857, 2.5 KB checked in by igarcia, 19 years ago (diff)
Line 
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/core/primitives/impl/primitives.ipp>
14
15///////////////////////////////////////////////////////////////////////////////
16namespace boost { namespace spirit {
17
18namespace impl {
19
20///////////////////////////////////////////////////////////////////////////////
21//
22inline const char* rx_prefix(char) { return "\\A"; }
23inline const wchar_t* rx_prefix(wchar_t) { return L"\\A"; }
24
25///////////////////////////////////////////////////////////////////////////////
26//
27//  rx_parser class
28//
29///////////////////////////////////////////////////////////////////////////////
30template <typename CharT = char>
31class rx_parser : public parser<rx_parser<CharT> > {
32
33public:
34    typedef std::basic_string<CharT> string_t;
35    typedef rx_parser<CharT> self_t;
36
37    rx_parser(CharT const *first, CharT const *last)
38    {
39        rxstr = string_t(rx_prefix(CharT())) + string_t(first, last);
40    }
41
42    rx_parser(CharT const *first)
43    {
44        rxstr = string_t(rx_prefix(CharT())) +
45            string_t(first, impl::get_last(first));
46    }
47
48    template <typename ScannerT>
49    typename parser_result<self_t, ScannerT>::type
50    parse(ScannerT const& scan) const
51    {
52        boost::match_results<typename ScannerT::iterator_t> what;
53        boost::regex_search(scan.first, scan.last, what, rxstr,
54            boost::match_default);
55
56        if (!what[0].matched)
57            return scan.no_match();
58
59        scan.first = what[0].second;
60        return scan.create_match(what[0].length(), nil_t(),
61            what[0].first, scan.first);
62    }
63
64private:
65#if BOOST_VERSION >= 013300
66    boost::basic_regex<CharT> rxstr;       // regular expression to match
67#else
68    boost::reg_expression<CharT> rxstr;    // regular expression to match
69#endif
70};
71
72}   // namespace impl
73
74///////////////////////////////////////////////////////////////////////////////
75}} // namespace boost::spirit
76
77#endif // BOOST_SPIRIT_REGEX_IPP
Note: See TracBrowser for help on using the repository browser.