Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/boost/spirit/utility/regex.hpp @ 13

Last change on this file since 13 was 12, checked in by landauf, 17 years ago

added boost

File size: 3.8 KB
RevLine 
[12]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_HPP
10#define BOOST_SPIRIT_REGEX_HPP
11
12#include <boost/version.hpp>
13
14///////////////////////////////////////////////////////////////////////////////
15//
16//  Include the regular expression library of boost (Boost.Regex)
17//
18//  Note though, that this library is not distributed with Spirit. You have to
19//  obtain a separate copy from http://www.boost.org.
20//
21///////////////////////////////////////////////////////////////////////////////
22#if defined(BOOST_SPIRIT_NO_REGEX_LIB) && BOOST_VERSION < 103300
23//
24//  Include all the Boost.regex library. Please note that this will not work,
25//  if you are using the boost/spirit/regex.hpp header from more than one
26//  translation units.
27//
28#define BOOST_REGEX_NO_LIB
29#define BOOST_REGEX_STATIC_LINK
30#define BOOST_REGEX_NO_EXTERNAL_TEMPLATES
31#include <boost/regex.hpp>
32#include <boost/regex/src.cpp>
33
34#else
35//
36//  Include the Boost.Regex headers only. Note, that you will have to link your
37//  application against the Boost.Regex library as described in the related
38//  documentation.
39//  This is the only way for Boost newer than V1.32.0
40//
41#include <boost/regex.hpp>
42#endif // defined(BOOST_SPIRIT_NO_REGEX_LIB)
43
44#include <boost/static_assert.hpp>
45
46///////////////////////////////////////////////////////////////////////////////
47#include <boost/spirit/meta/as_parser.hpp>
48#include <boost/spirit/core/parser.hpp>
49#include <boost/spirit/utility/impl/regex.ipp>
50#include <boost/detail/iterator.hpp> // for boost::detail::iterator_traits
51
52///////////////////////////////////////////////////////////////////////////////
53namespace boost { namespace spirit {
54
55///////////////////////////////////////////////////////////////////////////////
56// rxstrlit class
57template <typename CharT = char>
58struct rxstrlit : public parser<rxstrlit<CharT> > {
59
60    typedef rxstrlit self_t;
61
62    rxstrlit(CharT const *first, CharT const *last)
63    : rx(first, last) {}
64    rxstrlit(CharT const *first)
65    : rx(first) {}
66
67    template <typename ScannerT>
68    typename parser_result<self_t, ScannerT>::type
69    parse(ScannerT const& scan) const
70    {
71    //  Due to limitations in the boost::regex library the iterators wrapped in
72    //  the ScannerT object should be at least bidirectional iterators. Plain
73    //  forward iterators do not work here.
74        typedef typename ScannerT::iterator_t iterator_t;
75        typedef
76            typename boost::detail::iterator_traits<iterator_t>::iterator_category
77            iterator_category;
78
79        BOOST_STATIC_ASSERT((
80            boost::is_convertible<iterator_category,
81                std::bidirectional_iterator_tag>::value
82        ));
83
84        typedef typename parser_result<self_t, ScannerT>::type result_t;
85        return impl::contiguous_parser_parse<result_t>(rx, scan, scan);
86    }
87
88private:
89    impl::rx_parser<CharT> rx;   // contains the boost regular expression parser
90};
91
92///////////////////////////////////////////////////////////////////////////////
93// Generator functions
94template <typename CharT>
95inline rxstrlit<CharT>
96regex_p(CharT const *first)
97{ return rxstrlit<CharT>(first); }
98
99//////////////////////////////////
100template <typename CharT>
101inline rxstrlit<CharT>
102regex_p(CharT const *first, CharT const *last)
103{ return rxstrlit<CharT>(first, last); }
104
105///////////////////////////////////////////////////////////////////////////////
106}} // namespace boost::spirit
107
108#endif // BOOST_SPIRIT_REGEX_HPP
Note: See TracBrowser for help on using the repository browser.