/*============================================================================= Copyright (c) 2002-2003 Hartmut Kaiser http://spirit.sourceforge.net/ Use, modification and distribution is subject to 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) =============================================================================*/ #ifndef BOOST_SPIRIT_REGEX_IPP #define BOOST_SPIRIT_REGEX_IPP /////////////////////////////////////////////////////////////////////////////// #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { namespace impl { /////////////////////////////////////////////////////////////////////////////// // inline const char* rx_prefix(char) { return "\\A"; } inline const wchar_t* rx_prefix(wchar_t) { return L"\\A"; } /////////////////////////////////////////////////////////////////////////////// // // rx_parser class // /////////////////////////////////////////////////////////////////////////////// template class rx_parser : public parser > { public: typedef std::basic_string string_t; typedef rx_parser self_t; rx_parser(CharT const *first, CharT const *last) { rxstr = string_t(rx_prefix(CharT())) + string_t(first, last); } rx_parser(CharT const *first) { rxstr = string_t(rx_prefix(CharT())) + string_t(first, impl::get_last(first)); } template typename parser_result::type parse(ScannerT const& scan) const { boost::match_results what; boost::regex_search(scan.first, scan.last, what, rxstr, boost::match_default); if (!what[0].matched) return scan.no_match(); scan.first = what[0].second; return scan.create_match(what[0].length(), nil_t(), what[0].first, scan.first); } private: boost::reg_expression rxstr; // regular expression to match }; } // namespace impl /////////////////////////////////////////////////////////////////////////////// }} // namespace boost::spirit #endif // BOOST_SPIRIT_REGEX_IPP