merged changes in regex5 branch

[SVN r26692]
This commit is contained in:
John Maddock
2005-01-13 17:06:21 +00:00
parent de0ab9092a
commit 71a0e020e2
275 changed files with 37305 additions and 27154 deletions

View File

@ -24,11 +24,7 @@
#include <boost/regex/config.hpp>
#endif
#ifdef BOOST_REGEX_V3
#include <boost/regex/v3/cregex.hpp>
#else
#include <boost/regex/v4/cregex.hpp>
#endif
#endif /* include guard */

View File

@ -28,11 +28,7 @@
#include <boost/regex/config.hpp>
#endif
#ifdef BOOST_REGEX_V3
#include <boost/regex/v3/regex.hpp>
#else
#include <boost/regex/v4/regex.hpp>
#endif
#endif // include

View File

@ -0,0 +1,829 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE concepts.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares regular expression concepts.
*/
#ifndef BOOST_REGEX_CONCEPTS_HPP_INCLUDED
#define BOOST_REGEX_CONCEPTS_HPP_INCLUDED
#include <boost/concept_archetype.hpp>
#include <boost/concept_check.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/static_assert.hpp>
#include <boost/regex.hpp>
#include <bitset>
#include <vector>
namespace boost{
//
// bitmask_archetype:
// this can be either an integer type, an enum, or a std::bitset,
// we use the latter as the architype as it offers the "strictest"
// of the possible interfaces:
//
typedef std::bitset<512> bitmask_archetype;
//
// char_architype:
// A strict model for the character type interface.
//
struct char_architype
{
// default constructable:
char_architype();
// copy constructable / assignable:
char_architype(const char_architype&);
char_architype& operator=(const char_architype&);
// constructable from an integral value:
char_architype(unsigned long val);
// comparable:
bool operator==(const char_architype&)const;
bool operator!=(const char_architype&)const;
bool operator<(const char_architype&)const;
bool operator<=(const char_architype&)const;
bool operator>=(const char_architype&)const;
bool operator>(const char_architype&)const;
// conversion to integral type:
operator long()const;
};
//
// char_architype can not be used with basic_string:
//
} // namespace boost
namespace std{
template<> struct char_traits<boost::char_architype>{};
}
namespace boost{
//
// regex_traits_architype:
// A strict interpretation of the regular expression traits class requirements.
//
template <class charT>
struct regex_traits_architype
{
public:
regex_traits_architype();
typedef charT char_type;
typedef std::size_t size_type;
typedef std::vector<char_type> string_type;
typedef copy_constructible_archetype<assignable_archetype<> > locale_type;
typedef bitmask_archetype char_class_type;
static size_type length(const char_type* ) { return 0; }
charT translate(charT ) const { return charT(); }
charT translate_nocase(charT ) const { return static_object<charT>::get(); }
template <class ForwardIterator>
string_type transform(ForwardIterator , ForwardIterator ) const
{ return static_object<string_type>::get(); }
template <class ForwardIterator>
string_type transform_primary(ForwardIterator , ForwardIterator ) const
{ return static_object<string_type>::get(); }
template <class ForwardIterator>
char_class_type lookup_classname(ForwardIterator , ForwardIterator ) const
{ return static_object<char_class_type>::get(); }
template <class ForwardIterator>
string_type lookup_collatename(ForwardIterator , ForwardIterator ) const
{ return static_object<string_type>::get(); }
bool isctype(charT, char_class_type) const
{ return false; }
int value(charT, int) const
{ return 0; }
locale_type imbue(locale_type l)
{ return l; }
locale_type getloc()const
{ return static_object<locale_type>::get(); }
private:
// this type is not copyable:
regex_traits_architype(const regex_traits_architype&);
regex_traits_architype& operator=(const regex_traits_architype&);
};
//
// alter this to std::tr1, to test a std implementation:
//
namespace global_regex_namespace = ::boost;
template <class Bitmask>
struct BitmaskConcept
{
void constraints()
{
function_requires<CopyConstructibleConcept<Bitmask> >();
function_requires<AssignableConcept<Bitmask> >();
m_mask1 = m_mask2 | m_mask3;
m_mask1 = m_mask2 & m_mask3;
m_mask1 = m_mask2 ^ m_mask3;
m_mask1 = ~m_mask2;
m_mask1 |= m_mask2;
m_mask1 &= m_mask2;
m_mask1 ^= m_mask2;
}
Bitmask m_mask1, m_mask2, m_mask3;
};
template <class traits>
struct RegexTraitsConcept
{
RegexTraitsConcept();
// required typedefs:
typedef typename traits::char_type char_type;
typedef typename traits::size_type size_type;
typedef typename traits::string_type string_type;
typedef typename traits::locale_type locale_type;
typedef typename traits::char_class_type char_class_type;
void constraints()
{
function_requires<UnsignedIntegerConcept<size_type> >();
function_requires<RandomAccessContainerConcept<string_type> >();
function_requires<DefaultConstructibleConcept<locale_type> >();
function_requires<CopyConstructibleConcept<locale_type> >();
function_requires<AssignableConcept<locale_type> >();
function_requires<BitmaskConcept<char_class_type> >();
size_type n = traits::length(m_pointer);
ignore_unused_variable_warning(n);
char_type c = m_ctraits.translate(m_char);
ignore_unused_variable_warning(c);
c = m_ctraits.translate_nocase(m_char);
//string_type::foobar bar;
string_type s1 = m_ctraits.transform(m_pointer, m_pointer);
ignore_unused_variable_warning(s1);
string_type s2 = m_ctraits.transform_primary(m_pointer, m_pointer);
ignore_unused_variable_warning(s2);
char_class_type cc = m_ctraits.lookup_classname(m_pointer, m_pointer);
ignore_unused_variable_warning(cc);
string_type s3 = m_ctraits.lookup_collatename(m_pointer, m_pointer);
ignore_unused_variable_warning(s3);
bool b = m_ctraits.isctype(m_char, cc);
ignore_unused_variable_warning(b);
int v = m_ctraits.value(m_char, 16);
ignore_unused_variable_warning(v);
locale_type l(m_ctraits.getloc());
m_traits.imbue(l);
ignore_unused_variable_warning(l);
}
traits m_traits;
const traits m_ctraits;
const char_type* m_pointer;
char_type m_char;
};
//
// helper class to compute what traits class a regular expression type is using:
//
template <class Regex>
struct regex_traits_computer;
template <class charT, class traits>
struct regex_traits_computer< global_regex_namespace::basic_regex<charT, traits> >
{
typedef traits type;
};
//
// BaseRegexConcept does not test anything dependent on basic_string,
// in case our charT does not have an associated char_traits:
//
template <class Regex>
struct BaseRegexConcept
{
typedef typename Regex::value_type value_type;
typedef typename Regex::size_type size_type;
typedef typename Regex::flag_type flag_type;
typedef typename Regex::locale_type locale_type;
typedef input_iterator_archetype<value_type> input_iterator_type;
// derived test types:
typedef const value_type* pointer_type;
typedef bidirectional_iterator_archetype<value_type> BidiIterator;
typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
typedef global_regex_namespace::match_results<BidiIterator> match_results_type;
typedef output_iterator_archetype<value_type> OutIterator;
typedef typename regex_traits_computer<Regex>::type traits_type;
typedef global_regex_namespace::regex_iterator<BidiIterator, value_type, traits_type> regex_iterator_type;
typedef global_regex_namespace::regex_token_iterator<BidiIterator, value_type, traits_type> regex_token_iterator_type;
void global_constraints()
{
//
// test non-template components:
//
function_requires<BitmaskConcept<global_regex_namespace::regex_constants::syntax_option_type> >();
global_regex_namespace::regex_constants::syntax_option_type opts
= global_regex_namespace::regex_constants::icase
| global_regex_namespace::regex_constants::nosubs
| global_regex_namespace::regex_constants::optimize
| global_regex_namespace::regex_constants::collate
| global_regex_namespace::regex_constants::ECMAScript
| global_regex_namespace::regex_constants::basic
| global_regex_namespace::regex_constants::extended
| global_regex_namespace::regex_constants::awk
| global_regex_namespace::regex_constants::grep
| global_regex_namespace::regex_constants::egrep;
ignore_unused_variable_warning(opts);
function_requires<BitmaskConcept<global_regex_namespace::regex_constants::match_flag_type> >();
global_regex_namespace::regex_constants::match_flag_type mopts
= global_regex_namespace::regex_constants::match_default
| global_regex_namespace::regex_constants::match_not_bol
| global_regex_namespace::regex_constants::match_not_eol
| global_regex_namespace::regex_constants::match_not_bow
| global_regex_namespace::regex_constants::match_not_eow
| global_regex_namespace::regex_constants::match_any
| global_regex_namespace::regex_constants::match_not_null
| global_regex_namespace::regex_constants::match_continuous
| global_regex_namespace::regex_constants::match_partial
| global_regex_namespace::regex_constants::match_prev_avail
| global_regex_namespace::regex_constants::format_default
| global_regex_namespace::regex_constants::format_sed
| global_regex_namespace::regex_constants::format_perl
| global_regex_namespace::regex_constants::format_no_copy
| global_regex_namespace::regex_constants::format_first_only;
ignore_unused_variable_warning(mopts);
BOOST_STATIC_ASSERT((::boost::is_enum<global_regex_namespace::regex_constants::error_type>::value));
global_regex_namespace::regex_constants::error_type e1 = global_regex_namespace::regex_constants::error_collate;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_ctype;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_escape;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_backref;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_brack;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_paren;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_brace;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_badbrace;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_range;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_space;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_badrepeat;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_complexity;
ignore_unused_variable_warning(e1);
e1 = global_regex_namespace::regex_constants::error_stack;
ignore_unused_variable_warning(e1);
BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::runtime_error, global_regex_namespace::regex_error>::value ));
const global_regex_namespace::regex_error except(e1);
e1 = except.code();
typedef typename Regex::value_type value_type;
function_requires< RegexTraitsConcept<global_regex_namespace::regex_traits<char> > >();
function_requires< BaseRegexConcept<global_regex_namespace::basic_regex<char> > >();
}
void constraints()
{
global_constraints();
BOOST_STATIC_ASSERT((::boost::is_same< flag_type, global_regex_namespace::regex_constants::syntax_option_type>::value));
flag_type opts
= Regex::icase
| Regex::nosubs
| Regex::optimize
| Regex::collate
| Regex::ECMAScript
| Regex::basic
| Regex::extended
| Regex::awk
| Regex::grep
| Regex::egrep;
ignore_unused_variable_warning(opts);
function_requires<DefaultConstructibleConcept<Regex> >();
function_requires<CopyConstructibleConcept<Regex> >();
// Regex constructors:
Regex e1(m_pointer);
ignore_unused_variable_warning(e1);
Regex e2(m_pointer, m_flags);
ignore_unused_variable_warning(e2);
Regex e3(m_pointer, m_size, m_flags);
ignore_unused_variable_warning(e3);
Regex e4(in1, in2);
ignore_unused_variable_warning(e4);
Regex e5(in1, in2, m_flags);
ignore_unused_variable_warning(e5);
// assign etc:
Regex e;
e = m_pointer;
e = e1;
e.assign(e1);
e.assign(m_pointer);
e.assign(m_pointer, m_flags);
e.assign(m_pointer, m_size, m_flags);
e.assign(in1, in2);
e.assign(in1, in2, m_flags);
// access:
const Regex ce;
bool b = ce.empty();
ignore_unused_variable_warning(b);
size_type i = ce.mark_count();
ignore_unused_variable_warning(i);
m_flags = ce.flags();
e.imbue(ce.getloc());
e.swap(e1);
global_regex_namespace::swap(e, e1);
// sub_match:
BOOST_STATIC_ASSERT((::boost::is_base_and_derived<std::pair<BidiIterator, BidiIterator>, sub_match_type>::value));
typedef typename sub_match_type::value_type sub_value_type;
typedef typename sub_match_type::difference_type sub_diff_type;
typedef typename sub_match_type::iterator sub_iter_type;
BOOST_STATIC_ASSERT((::boost::is_same<sub_value_type, value_type>::value));
BOOST_STATIC_ASSERT((::boost::is_same<sub_iter_type, BidiIterator>::value));
b = m_sub.matched;
ignore_unused_variable_warning(b);
BidiIterator bi = m_sub.first;
ignore_unused_variable_warning(bi);
bi = m_sub.second;
ignore_unused_variable_warning(bi);
sub_diff_type diff = m_sub.length();
ignore_unused_variable_warning(diff);
// match_results tests:
typedef typename match_results_type::value_type mr_value_type;
typedef typename match_results_type::const_reference mr_const_reference;
typedef typename match_results_type::reference mr_reference;
typedef typename match_results_type::const_iterator mr_const_iterator;
typedef typename match_results_type::iterator mr_iterator;
typedef typename match_results_type::difference_type mr_difference_type;
typedef typename match_results_type::size_type mr_size_type;
typedef typename match_results_type::allocator_type mr_allocator_type;
typedef typename match_results_type::char_type mr_char_type;
typedef typename match_results_type::string_type mr_string_type;
match_results_type m1;
mr_allocator_type at;
match_results_type m2(at);
match_results_type m3(m1);
m1 = m2;
mr_size_type mrs = m_cresults.size();
ignore_unused_variable_warning(mrs);
mrs = m_cresults.max_size();
ignore_unused_variable_warning(mrs);
b = m_cresults.empty();
ignore_unused_variable_warning(b);
mr_difference_type mrd = m_cresults.length();
ignore_unused_variable_warning(mrd);
mrd = m_cresults.length(mrs);
ignore_unused_variable_warning(mrd);
mrd = m_cresults.position();
ignore_unused_variable_warning(mrd);
mrd = m_cresults.position(mrs);
ignore_unused_variable_warning(mrd);
mr_const_reference mrcr = m_cresults[m_size];
ignore_unused_variable_warning(mrcr);
mr_const_reference mrcr2 = m_cresults.prefix();
ignore_unused_variable_warning(mrcr2);
mr_const_reference mrcr3 = m_cresults.suffix();
ignore_unused_variable_warning(mrcr3);
mr_const_iterator mrci = m_cresults.begin();
ignore_unused_variable_warning(mrci);
mrci = m_cresults.end();
ignore_unused_variable_warning(mrci);
mr_allocator_type at2 = m_cresults.get_allocator();
m_results.swap(m_results);
global_regex_namespace::swap(m_results, m_results);
// regex_match:
b = global_regex_namespace::regex_match(m_in, m_in, m_results, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_in, m_in, m_results, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_in, m_in, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_in, m_in, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_pointer, m_pmatch, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_pointer, m_pmatch, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_pointer, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_pointer, e, m_mft);
ignore_unused_variable_warning(b);
// regex_search:
b = global_regex_namespace::regex_search(m_in, m_in, m_results, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_in, m_in, m_results, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_in, m_in, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_in, m_in, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_pointer, m_pmatch, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_pointer, m_pmatch, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_pointer, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_pointer, e, m_mft);
ignore_unused_variable_warning(b);
// regex_iterator:
typedef typename regex_iterator_type::regex_type rit_regex_type;
typedef typename regex_iterator_type::value_type rit_value_type;
typedef typename regex_iterator_type::difference_type rit_difference_type;
typedef typename regex_iterator_type::pointer rit_pointer;
typedef typename regex_iterator_type::reference rit_reference;
typedef typename regex_iterator_type::iterator_category rit_iterator_category;
BOOST_STATIC_ASSERT((::boost::is_same<rit_regex_type, Regex>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rit_value_type, match_results_type>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rit_difference_type, std::ptrdiff_t>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rit_pointer, const match_results_type*>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rit_reference, const match_results_type&>::value));
BOOST_STATIC_ASSERT((::boost::is_convertible<rit_iterator_category*, std::forward_iterator_tag*>::value));
// this takes care of most of the checks needed:
function_requires<ForwardIteratorConcept<regex_iterator_type> >();
regex_iterator_type iter1(m_in, m_in, e);
ignore_unused_variable_warning(iter1);
regex_iterator_type iter2(m_in, m_in, e, m_mft);
ignore_unused_variable_warning(iter2);
// regex_token_iterator:
typedef typename regex_token_iterator_type::regex_type rtit_regex_type;
typedef typename regex_token_iterator_type::value_type rtit_value_type;
typedef typename regex_token_iterator_type::difference_type rtit_difference_type;
typedef typename regex_token_iterator_type::pointer rtit_pointer;
typedef typename regex_token_iterator_type::reference rtit_reference;
typedef typename regex_token_iterator_type::iterator_category rtit_iterator_category;
BOOST_STATIC_ASSERT((::boost::is_same<rtit_regex_type, Regex>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rtit_value_type, sub_match_type>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rtit_difference_type, std::ptrdiff_t>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rtit_pointer, const sub_match_type*>::value));
BOOST_STATIC_ASSERT((::boost::is_same<rtit_reference, const sub_match_type&>::value));
BOOST_STATIC_ASSERT((::boost::is_convertible<rtit_iterator_category*, std::forward_iterator_tag*>::value));
// this takes care of most of the checks needed:
function_requires<ForwardIteratorConcept<regex_token_iterator_type> >();
regex_token_iterator_type ti1(m_in, m_in, e);
ignore_unused_variable_warning(ti1);
regex_token_iterator_type ti2(m_in, m_in, e, 0);
ignore_unused_variable_warning(ti2);
regex_token_iterator_type ti3(m_in, m_in, e, 0, m_mft);
ignore_unused_variable_warning(ti3);
std::vector<int> subs;
regex_token_iterator_type ti4(m_in, m_in, e, subs);
ignore_unused_variable_warning(ti4);
regex_token_iterator_type ti5(m_in, m_in, e, subs, m_mft);
ignore_unused_variable_warning(ti5);
static const int i_array[] = { 1, 2, 3, };
regex_token_iterator_type ti6(m_in, m_in, e, i_array);
ignore_unused_variable_warning(ti6);
regex_token_iterator_type ti7(m_in, m_in, e, i_array, m_mft);
ignore_unused_variable_warning(ti7);
}
pointer_type m_pointer;
flag_type m_flags;
size_type m_size;
input_iterator_type in1, in2;
const sub_match_type m_sub;
const value_type m_char;
match_results_type m_results;
const match_results_type m_cresults;
OutIterator m_out;
BidiIterator m_in;
global_regex_namespace::regex_constants::match_flag_type m_mft;
global_regex_namespace::match_results<pointer_type> m_pmatch;
BaseRegexConcept();
BaseRegexConcept(const BaseRegexConcept&);
BaseRegexConcept& operator=(const BaseRegexConcept&);
};
//
// RegexConcept:
// Test every interface in the std:
//
template <class Regex>
struct RegexConcept
{
typedef typename Regex::value_type value_type;
typedef typename Regex::size_type size_type;
typedef typename Regex::flag_type flag_type;
typedef typename Regex::locale_type locale_type;
// derived test types:
typedef const value_type* pointer_type;
typedef std::basic_string<value_type> string_type;
typedef boost::bidirectional_iterator_archetype<value_type> BidiIterator;
typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
typedef global_regex_namespace::match_results<BidiIterator> match_results_type;
typedef output_iterator_archetype<value_type> OutIterator;
void constraints()
{
function_requires<BaseRegexConcept<Regex> >();
// string based construct:
Regex e1(m_string);
ignore_unused_variable_warning(e1);
Regex e2(m_string, m_flags);
ignore_unused_variable_warning(e2);
// assign etc:
Regex e;
e = m_string;
e.assign(m_string);
e.assign(m_string, m_flags);
// sub_match:
string_type s(m_sub);
ignore_unused_variable_warning(s);
s = m_sub.str();
ignore_unused_variable_warning(s);
int i = m_sub.compare(m_string);
ignore_unused_variable_warning(i);
int i2 = m_sub.compare(m_sub);
ignore_unused_variable_warning(i2);
i2 = m_sub.compare(m_pointer);
ignore_unused_variable_warning(i2);
bool b = m_sub == m_sub;
ignore_unused_variable_warning(b);
b = m_sub != m_sub;
ignore_unused_variable_warning(b);
b = m_sub <= m_sub;
ignore_unused_variable_warning(b);
b = m_sub <= m_sub;
ignore_unused_variable_warning(b);
b = m_sub > m_sub;
ignore_unused_variable_warning(b);
b = m_sub >= m_sub;
ignore_unused_variable_warning(b);
b = m_sub == m_pointer;
ignore_unused_variable_warning(b);
b = m_sub != m_pointer;
ignore_unused_variable_warning(b);
b = m_sub <= m_pointer;
ignore_unused_variable_warning(b);
b = m_sub <= m_pointer;
ignore_unused_variable_warning(b);
b = m_sub > m_pointer;
ignore_unused_variable_warning(b);
b = m_sub >= m_pointer;
ignore_unused_variable_warning(b);
b = m_pointer == m_sub;
ignore_unused_variable_warning(b);
b = m_pointer != m_sub;
ignore_unused_variable_warning(b);
b = m_pointer <= m_sub;
ignore_unused_variable_warning(b);
b = m_pointer <= m_sub;
ignore_unused_variable_warning(b);
b = m_pointer > m_sub;
ignore_unused_variable_warning(b);
b = m_pointer >= m_sub;
ignore_unused_variable_warning(b);
b = m_sub == m_char;
ignore_unused_variable_warning(b);
b = m_sub != m_char;
ignore_unused_variable_warning(b);
b = m_sub <= m_char;
ignore_unused_variable_warning(b);
b = m_sub <= m_char;
ignore_unused_variable_warning(b);
b = m_sub > m_char;
ignore_unused_variable_warning(b);
b = m_sub >= m_char;
ignore_unused_variable_warning(b);
b = m_char == m_sub;
ignore_unused_variable_warning(b);
b = m_char != m_sub;
ignore_unused_variable_warning(b);
b = m_char <= m_sub;
ignore_unused_variable_warning(b);
b = m_char <= m_sub;
ignore_unused_variable_warning(b);
b = m_char > m_sub;
ignore_unused_variable_warning(b);
b = m_char >= m_sub;
ignore_unused_variable_warning(b);
b = m_sub == m_string;
ignore_unused_variable_warning(b);
b = m_sub != m_string;
ignore_unused_variable_warning(b);
b = m_sub <= m_string;
ignore_unused_variable_warning(b);
b = m_sub <= m_string;
ignore_unused_variable_warning(b);
b = m_sub > m_string;
ignore_unused_variable_warning(b);
b = m_sub >= m_string;
ignore_unused_variable_warning(b);
b = m_string == m_sub;
ignore_unused_variable_warning(b);
b = m_string != m_sub;
ignore_unused_variable_warning(b);
b = m_string <= m_sub;
ignore_unused_variable_warning(b);
b = m_string <= m_sub;
ignore_unused_variable_warning(b);
b = m_string > m_sub;
ignore_unused_variable_warning(b);
b = m_string >= m_sub;
ignore_unused_variable_warning(b);
// match results:
m_string = m_results.str();
ignore_unused_variable_warning(m_string);
m_string = m_results.str(0);
ignore_unused_variable_warning(m_string);
m_out = m_cresults.format(m_out, m_string);
m_out = m_cresults.format(m_out, m_string, m_mft);
m_string = m_cresults.format(m_string);
ignore_unused_variable_warning(m_string);
m_string = m_cresults.format(m_string, m_mft);
ignore_unused_variable_warning(m_string);
// regex_match:
b = global_regex_namespace::regex_match(m_string, m_smatch, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_string, m_smatch, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_string, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_match(m_string, e, m_mft);
ignore_unused_variable_warning(b);
// regex_search:
b = global_regex_namespace::regex_search(m_string, m_smatch, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_string, m_smatch, e, m_mft);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_string, e);
ignore_unused_variable_warning(b);
b = global_regex_namespace::regex_search(m_string, e, m_mft);
ignore_unused_variable_warning(b);
// regex_replace:
m_out = global_regex_namespace::regex_replace(m_out, m_in, m_in, e, m_string, m_mft);
m_out = global_regex_namespace::regex_replace(m_out, m_in, m_in, e, m_string);
m_string = global_regex_namespace::regex_replace(m_string, e, m_string, m_mft);
ignore_unused_variable_warning(m_string);
m_string = global_regex_namespace::regex_replace(m_string, e, m_string);
ignore_unused_variable_warning(m_string);
}
flag_type m_flags;
string_type m_string;
const sub_match_type m_sub;
match_results_type m_results;
pointer_type m_pointer;
value_type m_char;
const match_results_type m_cresults;
OutIterator m_out;
BidiIterator m_in;
global_regex_namespace::regex_constants::match_flag_type m_mft;
global_regex_namespace::match_results<typename string_type::const_iterator> m_smatch;
RegexConcept();
RegexConcept(const RegexConcept&);
RegexConcept& operator=(const RegexConcept&);
};
//
// BoostRegexConcept:
// Test every interface in the Boost implementation:
//
template <class Regex>
struct BoostRegexConcept
{
typedef typename Regex::value_type value_type;
typedef typename Regex::size_type size_type;
typedef typename Regex::flag_type flag_type;
typedef typename Regex::locale_type locale_type;
// derived test types:
typedef const value_type* pointer_type;
typedef std::basic_string<value_type> string_type;
typedef typename Regex::const_iterator const_iterator;
typedef bidirectional_iterator_archetype<value_type> BidiIterator;
typedef global_regex_namespace::sub_match<BidiIterator> sub_match_type;
typedef global_regex_namespace::match_results<BidiIterator> match_results_type;
void constraints()
{
function_requires<RegexConcept<Regex> >();
const global_regex_namespace::regex_error except(global_regex_namespace::regex_constants::error_collate);
std::ptrdiff_t pt = except.position();
ignore_unused_variable_warning(pt);
const Regex ce, ce2;
m_stream << ce;
unsigned i = ce.error_code();
ignore_unused_variable_warning(i);
pointer_type p = ce.expression();
ignore_unused_variable_warning(p);
int i2 = ce.compare(ce2);
ignore_unused_variable_warning(i2);
bool b = ce == ce2;
ignore_unused_variable_warning(b);
b = ce != ce2;
ignore_unused_variable_warning(b);
b = ce < ce2;
ignore_unused_variable_warning(b);
b = ce > ce2;
ignore_unused_variable_warning(b);
b = ce <= ce2;
ignore_unused_variable_warning(b);
b = ce >= ce2;
ignore_unused_variable_warning(b);
i = ce.status();
ignore_unused_variable_warning(i);
size_type s = ce.max_size();
ignore_unused_variable_warning(s);
s = ce.size();
ignore_unused_variable_warning(s);
const_iterator pi = ce.begin();
ignore_unused_variable_warning(pi);
pi = ce.end();
ignore_unused_variable_warning(pi);
string_type s2 = ce.str();
ignore_unused_variable_warning(s2);
m_string = m_sub + m_sub;
ignore_unused_variable_warning(m_string);
m_string = m_sub + m_pointer;
ignore_unused_variable_warning(m_string);
m_string = m_pointer + m_sub;
ignore_unused_variable_warning(m_string);
m_string = m_sub + m_string;
ignore_unused_variable_warning(m_string);
m_string = m_string + m_sub;
ignore_unused_variable_warning(m_string);
m_string = m_sub + m_char;
ignore_unused_variable_warning(m_string);
m_string = m_char + m_sub;
ignore_unused_variable_warning(m_string);
m_stream << m_sub;
m_stream << m_cresults;
}
std::basic_ostream<value_type> m_stream;
sub_match_type m_sub;
pointer_type m_pointer;
string_type m_string;
const value_type m_char;
match_results_type m_results;
const match_results_type m_cresults;
BoostRegexConcept();
BoostRegexConcept(const BoostRegexConcept&);
BoostRegexConcept& operator=(const BoostRegexConcept&);
};
}
#endif

View File

@ -18,10 +18,10 @@
#ifndef BOOST_REGEX_CONFIG_HPP
#define BOOST_REGEX_CONFIG_HPP
/*
Borland C++ Fix/error check
this has to go *before* we include any std lib headers:
*/
//
// Borland C++ Fix/error check
// this has to go *before* we include any std lib headers:
//
#if defined(__BORLANDC__)
# include <boost/regex/config/borland.hpp>
#endif
@ -40,31 +40,14 @@
# include BOOST_REGEX_USER_CONFIG
# include <cstdlib>
# include <cstddef>
# include <cstdio>
# include <clocale>
# include <cassert>
# include <string>
# include <stdexcept>
# include <iterator>
# include <iosfwd>
# include <vector>
# include <boost/config.hpp>
# include <boost/cstdint.hpp>
# include <boost/regex/config/allocator.hpp>
# include <boost/regex/config/cstring.hpp>
# include <boost/throw_exception.hpp>
# include <boost/scoped_ptr.hpp>
# ifndef BOOST_NO_STD_LOCALE
# include <locale>
# endif
#else
/*
* C build,
* don't include <boost/config.hpp> because that may
* do C++ specific things in future...
*/
//
// C build,
// don't include <boost/config.hpp> because that may
// do C++ specific things in future...
//
# include <stdlib.h>
# include <stddef.h>
# ifdef _MSC_VER
@ -81,24 +64,34 @@
/* Obsolete macro, use BOOST_VERSION instead: */
#define BOOST_RE_VERSION 320
/* fix: */
// fix:
#if defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
/*
* If there isn't good enough wide character support then there will
* be no wide character regular expressions:
*/
//
// Fix for gcc prior to 3.4: std::ctype<wchar_t> doesn't allow
// masks to be combined, for example:
// std::use_facet<std::ctype<wchar_t> >.is(std::ctype_base::lower|std::ctype_base::upper, L'a');
// returns *false*.
//
#ifdef __GLIBCPP__
# define BOOST_REGEX_BUGGY_CTYPE_FACET
#endif
//
// If there isn't good enough wide character support then there will
// be no wide character regular expressions:
//
#if (defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_CWCTYPE) || defined(BOOST_NO_STD_WSTRING))
# if !defined(BOOST_NO_WREGEX)
# define BOOST_NO_WREGEX
# endif
#else
# if defined(__sgi) && (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION))
/* STLPort on IRIX is misconfigured: <cwctype> does not compile
* as a temporary fix include <wctype.h> instead and prevent inclusion
* of STLPort version of <cwctype> */
// STLPort on IRIX is misconfigured: <cwctype> does not compile
// as a temporary fix include <wctype.h> instead and prevent inclusion
// of STLPort version of <cwctype>
# include <wctype.h>
# define __STLPORT_CWCTYPE
# define _STLP_CWCTYPE
@ -110,78 +103,28 @@
#endif
/*
* If Win32 support has been disabled for boost in general, then
* it is for regex in particular:
*/
//
// If Win32 support has been disabled for boost in general, then
// it is for regex in particular:
//
#if defined(BOOST_DISABLE_WIN32) && !defined(BOOST_REGEX_NO_W32)
# define BOOST_REGEX_NO_W32
#endif
/* some versions of gcc can't merge template instances: */
#if defined(__CYGWIN__)
# define BOOST_REGEX_NO_TEMPLATE_SWITCH_MERGE
#endif
/* fix problems with bool as a macro,
* this probably doesn't affect any current compilers: */
#if defined(bool) || defined(true) || defined(false)
# define BOOST_REGEX_NO_BOOL
#endif
/* We don't make our templates external if the compiler
can't handle it: */
#if (defined(BOOST_NO_MEMBER_FUNCTION_SPECIALIZATIONS) || defined(__HP_aCC) || defined(__MWERKS__) || defined(__COMO__) || defined(BOOST_INTEL))\
&& !defined(BOOST_MSVC) && !defined(__BORLANDC__)
# define BOOST_REGEX_NO_EXTERNAL_TEMPLATES
#endif
/* disable our own file-iterators and mapfiles if we can't
support them: */
// disable our own file-iterators and mapfiles if we can't
// support them:
#if !defined(BOOST_HAS_DIRENT_H) && !(defined(_WIN32) && !defined(BOOST_REGEX_NO_W32))
# define BOOST_REGEX_NO_FILEITER
#endif
#ifdef __cplusplus
#ifndef MB_CUR_MAX
// yuk!
// better make a conservative guess!
#define MB_CUR_MAX 10
#endif
namespace boost{ namespace re_detail{
#ifdef BOOST_NO_STD_DISTANCE
template <class T>
std::ptrdiff_t distance(const T& x, const T& y)
{ return y - x; }
#else
using std::distance;
#endif
}}
#ifdef BOOST_REGEX_NO_BOOL
# define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false)
#else
# ifdef BOOST_MSVC
// warning suppression with VC6:
# pragma warning(disable: 4800)
# endif
# define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x)
#endif
#endif /* __cplusplus */
/* backwards compatibitity: */
// backwards compatibitity:
#if defined(BOOST_RE_NO_LIB)
# define BOOST_REGEX_NO_LIB
#endif
#if defined(__GNUC__) && (defined(_WIN32) || defined(__CYGWIN__))
// gcc on win32 has problems merging switch statements in templates:
# define BOOST_REGEX_NO_TEMPLATE_SWITCH_MERGE
// gcc on win32 has problems if you include <windows.h>
// (sporadically generates bad code).
# define BOOST_REGEX_USE_C_LOCALE
# define BOOST_REGEX_NO_W32
#endif
#if defined(__COMO__) && !defined(BOOST_REGEX_NO_W32) && !defined(_MSC_EXTENSIONS)
@ -194,13 +137,26 @@ using std::distance;
*
****************************************************************************/
#ifdef __cplusplus
#if defined(BOOST_MSVC) && (BOOST_MSVC >= 1300) && !defined(BOOST_REGEX_V3) && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION))
# define BOOST_REGEX_HAS_SHORT_WCHAR_T
namespace boost{ typedef __wchar_t regex_wchar_type; }
#else
namespace boost{ typedef wchar_t regex_wchar_type; }
#endif
//
// define BOOST_REGEX_HAS_OTHER_WCHAR_T when wchar_t is a native type, but the users
// code may be built with wchar_t as unsigned short: basically when we're building
// with MSVC and the /Zc:wchar_t option we place some extra unsigned short versions
// of the non-inline functions in the library, so that users can still link to the lib,
// irrespective of whether their own code is built with /Zc:wchar_t.
//
#if defined(__cplusplus) && (defined(BOOST_MSVC) || defined(__ICL)) && !defined(BOOST_NO_INTRINSIC_WCHAR_T) && defined(BOOST_WINDOWS)
# define BOOST_REGEX_HAS_OTHER_WCHAR_T
# ifdef BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4251 4231 4660)
# endif
# ifdef _DLL
# include <string>
extern template class __declspec(dllimport) std::basic_string<unsigned short>;
# endif
# ifdef BOOST_MSVC
# pragma warning(pop)
# endif
#endif
@ -228,9 +184,9 @@ namespace boost{ typedef wchar_t regex_wchar_type; }
# if defined(BOOST_REGEX_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
# define BOOST_DYN_LINK
# endif
#ifdef BOOST_REGEX_DIAG
# define BOOST_LIB_DIAGNOSTIC
#endif
# ifdef BOOST_REGEX_DIAG
# define BOOST_LIB_DIAGNOSTIC
# endif
# include <boost/config/auto_link.hpp>
#endif
@ -267,7 +223,7 @@ namespace boost{ typedef wchar_t regex_wchar_type; }
*
****************************************************************************/
/* backwards compatibility: */
// backwards compatibility:
#ifdef BOOST_RE_LOCALE_C
# define BOOST_REGEX_USE_C_LOCALE
#endif
@ -276,29 +232,19 @@ namespace boost{ typedef wchar_t regex_wchar_type; }
# define BOOST_REGEX_USE_CPP_LOCALE
#endif
/* Win32 defaults to native Win32 locale: */
// Win32 defaults to native Win32 locale:
#if defined(_WIN32) && !defined(BOOST_REGEX_USE_WIN32_LOCALE) && !defined(BOOST_REGEX_USE_C_LOCALE) && !defined(BOOST_REGEX_USE_CPP_LOCALE) && !defined(BOOST_REGEX_NO_W32)
# define BOOST_REGEX_USE_WIN32_LOCALE
#endif
/* otherwise use C locale: */
// otherwise use C++ locale if supported:
#if !defined(BOOST_REGEX_USE_WIN32_LOCALE) && !defined(BOOST_REGEX_USE_C_LOCALE) && !defined(BOOST_REGEX_USE_CPP_LOCALE) && !defined(BOOST_NO_STD_LOCALE)
# define BOOST_REGEX_USE_CPP_LOCALE
#endif
// otherwise use C+ locale:
#if !defined(BOOST_REGEX_USE_WIN32_LOCALE) && !defined(BOOST_REGEX_USE_C_LOCALE) && !defined(BOOST_REGEX_USE_CPP_LOCALE)
# define BOOST_REGEX_USE_C_LOCALE
#endif
#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
# include <windows.h>
#endif
#ifdef MAXPATH
# define BOOST_REGEX_MAX_PATH MAXPATH
#elif defined(MAX_PATH)
# define BOOST_REGEX_MAX_PATH MAX_PATH
#elif defined(FILENAME_MAX)
# define BOOST_REGEX_MAX_PATH FILENAME_MAX
#else
# define BOOST_REGEX_MAX_PATH 200
#endif
#ifndef BOOST_REGEX_MAX_STATE_COUNT
# define BOOST_REGEX_MAX_STATE_COUNT 100000000
#endif
@ -311,10 +257,14 @@ namespace boost{ typedef wchar_t regex_wchar_type; }
****************************************************************************/
#ifdef BOOST_NO_EXCEPTIONS
/*
* If there are no exceptions then we must report critical-errors
* the only way we know how; by terminating.
*/
//
// If there are no exceptions then we must report critical-errors
// the only way we know how; by terminating.
//
#include <stdexcept>
#include <string>
#include <boost/throw_exception.hpp>
# define BOOST_REGEX_NOEH_ASSERT(x)\
if(0 == (x))\
{\
@ -324,70 +274,13 @@ if(0 == (x))\
boost::throw_exception(e);\
}
#else
/*
* With exceptions then error handling is taken care of and
* there is no need for these checks:
*/
//
// With exceptions then error handling is taken care of and
// there is no need for these checks:
//
# define BOOST_REGEX_NOEH_ASSERT(x)
#endif
/*****************************************************************************
*
* Debugging / tracing support:
*
****************************************************************************/
#if defined(BOOST_REGEX_DEBUG) && defined(__cplusplus)
# include <iostream>
using std::cout;
using std::cin;
using std::cerr;
using std::endl;
using std::hex;
using std::dec;
# ifndef jm_assert
# define jm_assert(x) assert(x)
# endif
# ifndef jm_trace
# define jm_trace(x) cerr << x << endl;
# endif
# ifndef jm_instrument
# define jm_instrument jm_trace(__FILE__<<"#"<<__LINE__)
# endif
namespace boost{
namespace re_detail{
class debug_guard
{
public:
char g1[32];
const char* pc;
char* pnc;
const char* file;
int line;
char g2[32];
debug_guard(const char* f, int l, const char* p1 = 0, char* p2 = 0);
~debug_guard();
};
# define BOOST_RE_GUARD_STACK boost::re_detail::debug_guard sg(__FILE__, __LINE__);
# define BOOST_RE_GUARD_GLOBAL(x) const char g1##x[] = { 0, 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, }; char g2##x[32]; boost::debug_guard g3##x(__FILE__, __LINE__, g1##x, g2##x);
} // namespace re_detail
} // namespace boost
#else
# define jm_assert(x)
# define jm_trace(x)
# define BOOST_RE_GUARD_STACK
# define BOOST_RE_GUARD_GLOBAL(x)
# ifndef jm_instrument
# define jm_instrument
# endif
#endif
/*****************************************************************************
*
@ -419,31 +312,6 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page();
#endif
/*****************************************************************************
*
* Error handling:
*
****************************************************************************/
#if defined(__cplusplus)
namespace boost{
namespace re_detail{
BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_regex_exception(const std::string& s);
template <class traits>
void raise_error(const traits& t, unsigned code)
{
(void)t; // warning suppression
raise_regex_exception(t.error_string(code));
}
}
}
#endif
/*****************************************************************************
*
* Algorithm selection and configuration:
@ -480,93 +348,6 @@ void raise_error(const traits& t, unsigned code)
#endif
/*****************************************************************************
*
* Fix broken compilers that wrongly #define some symbols:
*
****************************************************************************/
#ifdef __cplusplus
// the following may be defined as macros; this is
// incompatable with std::something syntax, we have
// no choice but to undef them?
#ifdef sprintf
#undef sprintf
#endif
#ifdef swprintf
#undef swprintf
#endif
#endif
/*****************************************************************************
*
* Fix broken broken namespace support:
*
****************************************************************************/
#if defined(BOOST_NO_STDC_NAMESPACE) && defined(__cplusplus)
namespace std{
using ::ptrdiff_t;
using ::size_t;
using ::sprintf;
using ::abs;
using ::setlocale;
# ifndef BOOST_NO_WREGEX
# ifndef BOOST_NO_SWPRINTF
using ::swprintf;
# endif
using ::wcstombs;
using ::mbstowcs;
# if !defined(BOOST_NO_STD_LOCALE) && !defined (__STL_NO_NATIVE_MBSTATE_T) && !defined(_STLP_NO_NATIVE_MBSTATE_T)
using ::mbstate_t;
# endif
# endif /* BOOST_NO_WREGEX */
using ::fseek;
using ::fread;
using ::ftell;
using ::fopen;
using ::fclose;
using ::FILE;
#ifdef BOOST_NO_EXCEPTIONS
using ::fprintf;
using ::abort;
#endif
}
#endif
/*****************************************************************************
*
* helper functions pointer_construct/pointer_destroy:
*
****************************************************************************/
#ifdef __cplusplus
namespace boost{ namespace re_detail{
#ifdef BOOST_MSVC
#pragma warning (push)
#pragma warning (disable : 4100)
#endif
template <class T>
inline void pointer_destroy(T* p)
{ p->~T(); (void)p; }
#ifdef BOOST_MSVC
#pragma warning (pop)
#endif
template <class T>
inline void pointer_construct(T* p, const T& t)
{ new (p) T(t); }
}} // namespaces
#endif
/*****************************************************************************
*
* helper memory allocation functions:
@ -593,9 +374,9 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL print_regex_library_info();
#endif
#if defined(BOOST_REGEX_DIAG)
# pragma message ("BOOST_REGEX_DECL set as: " BOOST_STRINGIZE(BOOST_REGEX_DECL))
# pragma message ("BOOST_REGEX_CALL set as: " BOOST_STRINGIZE(BOOST_REGEX_CALL))
# pragma message ("BOOST_REGEX_CCALL set as: " BOOST_STRINGIZE(BOOST_REGEX_CCALL))
# pragma message ("BOOST_REGEX_DECL" BOOST_STRINGIZE(=BOOST_REGEX_DECL))
# pragma message ("BOOST_REGEX_CALL" BOOST_STRINGIZE(=BOOST_REGEX_CALL))
# pragma message ("BOOST_REGEX_CCALL" BOOST_STRINGIZE(=BOOST_REGEX_CCALL))
#ifdef BOOST_REGEX_USE_C_LOCALE
# pragma message ("Using C locale in regex traits class")
#elif BOOST_REGEX_USE_CPP_LOCALE
@ -603,20 +384,15 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL print_regex_library_info();
#else
# pragma message ("Using Win32 locale in regex traits class")
#endif
#ifdef BOOST_REGEX_DYN_LINK
#if defined(BOOST_REGEX_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
# pragma message ("Dynamic linking enabled")
#endif
#ifdef BOOST_REGEX_NO_LIB
#if defined(BOOST_REGEX_NO_LIB) || defined(BOOST_ALL_NO_LIB)
# pragma message ("Auto-linking disabled")
#endif
#ifdef BOOST_REGEX_NO_EXTERNAL_TEMPLATES
# pragma message ("Extern templates disabled")
#endif
#ifdef BOOST_REGEX_V3
# pragma message ("Using Version 3 regex code")
#else
# pragma message ("Using Version 4 regex code")
#endif
#endif

View File

@ -58,6 +58,15 @@
# endif
# endif
#if __BORLANDC__ < 0x600
//
// string workarounds:
//
#include <cstring>
#undef strcmp
#undef strcpy
#endif
#endif

View File

@ -1,303 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE boost/regex/config/cstring.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: regex narrow character string fixes.
*/
#ifndef BOOST_REGEX_CONFIG_CSTRING_HPP
#define BOOST_REGEX_CONFIG_CSTRING_HPP
#include <cstring>
#include <cctype>
#ifndef __sgi
#ifdef __KCC
#include <ios>
#endif
#include <boost/config.hpp>
namespace std{
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
#ifdef BOOST_NO_STDC_NAMESPACE
// Any function that is a macro is converted into an inline function:
#ifdef memcmp
inline int boost_memcmp(const void * p1, const void * p2, size_t s)
{ return memcmp(p1, p2, s); }
#undef memcmp
inline int memcmp(const void * p1, const void * p2, size_t s)
{ return boost_memcmp(p1, p2, s); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::memcmp;
#endif
#ifdef memcpy
inline void *boost_memcpy(void * p1, const void *p2, size_t s)
{ return memcpy(p1, p2, s); }
#undef memcpy
inline void *memcpy(void * p1, const void *p2, size_t s)
{ return boost_memcpy(p1, p2, s); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::memcpy;
#endif
#ifdef memmove
inline void *(memmove)(void *, const void *, size_t)
{ return memmove(p1,p2,s); }
#undef memmove
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::memmove;
#endif
#ifdef memset
inline void *(boost_memset)(void *p, int a, size_t b)
{ return memset(p,a,b); }
#undef memset
inline void *(memset)(void *p, int a, size_t b)
{ return boost_memset(p,a,b); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::memset;
#endif
#ifdef strcat
inline char *(boost_strcat)(char *p1, const char *p2)
{ return strcat(p1,p2); }
#undef strcat
inline char *(strcat)(char *p1, const char *p2)
{ return boost_strcat(p1,p2); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::strcat;
#endif
#ifdef strcmp
inline int (boost_strcmp)(const char *p1, const char *p2)
{ return strcmp(p1,p2); }
#undef strcmp
inline int (strcmp)(const char *p1, const char *p2)
{ return boost_strcmp(p1,p2); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::strcmp;
#endif
#ifdef strcoll
inline int (boost_strcoll) (const char *p1, const char *p2)
{ return strcoll(p1,p2); }
#undef strcoll
inline int (strcoll) (const char *p1, const char *p2)
{ return boost_strcoll(p1,p2); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::strcoll;
#endif
#ifdef strcpy
inline char *(boost_strcpy)(char *p1, const char *p2)
{ return strcpy(p1,p2); }
#undef strcpy
inline char *(strcpy)(char *p1, const char *p2)
{ return boost_strcpy(p1,p2); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::strcpy;
#endif
#ifdef strlen
inline size_t (boost_strlen)(const char *p)
{ return strlen(p); }
#undef strlen
inline size_t (strlen)(const char *p)
{ return boost_strlen(p); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::strlen;
#endif
#ifdef strxfrm
inline size_t (boost_strxfrm)(char *p1, const char *p2, size_t s)
{ return strxfrm(p1,p2,s); }
#undef strxfrm
inline size_t (strxfrm)(char *p1, const char *p2, size_t s)
{ return boost_strxfrm(p1,p2,s); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::strxfrm;
#endif
#ifdef isalnum
inline int (boost_isalnum)(int i)
{ return isalnum(i); }
#undef isalnum
inline int (isalnum)(int i)
{ return boost_isalnum(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isalnum;
#endif
#ifdef isalpha
inline int (boost_isalpha)(int i)
{ return isalpha(i); }
#undef isalpha
inline int (isalpha)(int i)
{ return boost_isalpha(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isalpha;
#endif
#ifdef iscntrl
inline int (boost_iscntrl)(int i)
{ return iscntrl(i); }
#undef iscntrl
inline int (iscntrl)(int i)
{ return boost_iscntrl(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::iscntrl;
#endif
#ifdef isdigit
inline int (boost_isdigit)(int i)
{ return isdigit(i); }
#undef isdigit
inline int (isdigit)(int i)
{ return boost_isdigit(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isdigit;
#endif
#ifdef isgraph
inline int (boost_isgraph)(int i)
{ return isgraph(i); }
#undef isgraph
inline int (isgraph)(int i)
{ return boost_isgraph(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isgraph;
#endif
#ifdef islower
inline int (boost_islower)(int i)
{ return islower(i); }
#undef islower
inline int (islower)(int i)
{ return boost_islower(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::islower;
#endif
#ifdef isprint
inline int (boost_isprint)(int i)
{ return isprint(i); }
#undef isprint
inline int (isprint)(int i)
{ return boost_isprint(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isprint;
#endif
#ifdef ispunct
inline int (boost_ispunct)(int i)
{ return ispunct(i); }
#undef ispunct
inline int (ispunct)(int i)
{ return boost_ispunct(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::ispunct;
#endif
#ifdef isspace
inline int (isspace)(int i)
{ return isspace(i); }
#undef isspace
inline int (boost_isspace)(int i)
{ return boost_isspace(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isspace;
#endif
#ifdef isupper
inline int (isupper)(int i)
{ return isupper(i); }
#undef isupper
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isupper;
#endif
#ifdef isxdigit
inline int (isxdigit)(int i)
{ return isxdigit(i); }
#undef isxdigit
inline int (boost_isxdigit)(int i)
{ return boost_isxdigit(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::isxdigit;
#endif
#ifdef tolower
inline int (boost_tolower)(int i)
{ return tolower(i); }
#undef tolower
inline int (tolower)(int i)
{ return boost_tolower(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::tolower;
#endif
#ifdef toupper
inline int (boost_toupper)(int i)
{ return toupper(i); }
#undef toupper
inline int (toupper)(int i)
{ return boost_toupper(i); }
#elif defined(BOOST_NO_STDC_NAMESPACE)
using ::toupper;
#endif
#else
#undef memcmp
#undef memcpy
#undef memmove
#undef memset
#undef strcat
#undef strcmp
#undef strcoll
#undef strcpy
#undef strlen
#undef strxfrm
#undef isalnum
#undef isalpha
#undef iscntrl
#undef isdigit
#undef isgraph
#undef islower
#undef isprint
#undef ispunct
#undef isspace
#undef isupper
#undef isxdigit
#undef tolower
#undef toupper
#endif
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace std
#endif // __sgi
#endif

897
include/boost/regex/icu.hpp Normal file
View File

@ -0,0 +1,897 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE icu.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Unicode regular expressions on top of the ICU Library.
*/
#ifndef BOOST_REGEX_ICU_HPP
#define BOOST_REGEX_ICU_HPP
#include <unicode/utypes.h>
#include <unicode/uchar.h>
#include <unicode/coll.h>
#include <boost/regex.hpp>
#include <boost/regex/pending/unicode_iterator.hpp>
#include <boost/mpl/int_fwd.hpp>
#include <bitset>
namespace boost{
namespace re_detail{
//
// Implementation details:
//
class BOOST_REGEX_DECL icu_regex_traits_implementation
{
typedef UChar32 char_type;
typedef std::size_t size_type;
typedef std::vector<char_type> string_type;
typedef ::Locale locale_type;
typedef boost::uint_least32_t char_class_type;
public:
icu_regex_traits_implementation(const ::Locale& l)
: m_locale(l)
{
UErrorCode success = U_ZERO_ERROR;
m_collator.reset( ::Collator::createInstance(l, success));
if(U_SUCCESS(success) == 0)
init_error();
m_collator->setStrength(::Collator::IDENTICAL);
success = U_ZERO_ERROR;
m_primary_collator.reset( ::Collator::createInstance(l, success));
if(U_SUCCESS(success) == 0)
init_error();
m_primary_collator->setStrength(::Collator::PRIMARY);
}
::Locale getloc()const
{
return m_locale;
}
string_type do_transform(const char_type* p1, const char_type* p2, const ::Collator* pcoll) const;
string_type transform(const char_type* p1, const char_type* p2) const
{
return do_transform(p1, p2, m_collator.get());
}
string_type transform_primary(const char_type* p1, const char_type* p2) const
{
return do_transform(p1, p2, m_primary_collator.get());
}
private:
void init_error()
{
std::runtime_error e("Could not initialize ICU resources");
boost::throw_exception(e);
}
::Locale m_locale; // The ICU locale that we're using
boost::scoped_ptr< ::Collator> m_collator; // The full collation object
boost::scoped_ptr< ::Collator> m_primary_collator; // The primary collation object
};
inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const ::Locale& loc)
{
return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
}
}
class BOOST_REGEX_DECL icu_regex_traits
{
public:
typedef UChar32 char_type;
typedef std::size_t size_type;
typedef std::vector<char_type> string_type;
typedef ::Locale locale_type;
#ifdef BOOST_NO_INT64_T
typedef std::bitset<64> char_class_type;
#else
typedef boost::uint64_t char_class_type;
#endif
struct boost_extensions_tag{};
icu_regex_traits()
: m_pimpl(re_detail::get_icu_regex_traits_implementation(::Locale()))
{
}
static size_type length(const char_type* p);
::boost::regex_constants::syntax_type syntax_type(char_type c)const
{
return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
}
::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c) const
{
return ((c < 0x7f) && (c > 0)) ? re_detail::get_default_escape_syntax_type(static_cast<char>(c)) : regex_constants::syntax_char;
}
char_type translate(char_type c) const
{
return c;
}
char_type translate_nocase(char_type c) const
{
return ::u_tolower(c);
}
char_type translate(char_type c, bool icase) const
{
return icase ? translate_nocase(c) : translate(c);
}
char_type tolower(char_type c) const
{
return ::u_tolower(c);
}
char_type toupper(char_type c) const
{
return ::u_toupper(c);
}
string_type transform(const char_type* p1, const char_type* p2) const
{
return m_pimpl->transform(p1, p2);
}
string_type transform_primary(const char_type* p1, const char_type* p2) const
{
return m_pimpl->transform_primary(p1, p2);
}
char_class_type lookup_classname(const char_type* p1, const char_type* p2) const;
string_type lookup_collatename(const char_type* p1, const char_type* p2) const;
bool isctype(char_type c, char_class_type f) const;
int toi(const char_type*& p1, const char_type* p2, int radix)const
{
return re_detail::global_toi(p1, p2, radix, *this);
}
int value(char_type c, int radix)const
{
return u_digit(c, static_cast< ::int8_t>(radix));
}
locale_type imbue(locale_type l)
{
locale_type result(m_pimpl->getloc());
m_pimpl = re_detail::get_icu_regex_traits_implementation(l);
return result;
}
locale_type getloc()const
{
return locale_type();
}
std::string error_string(::boost::regex_constants::error_type n) const
{
return re_detail::get_default_error_string(n);
}
private:
icu_regex_traits(const icu_regex_traits&);
icu_regex_traits& operator=(const icu_regex_traits&);
//
// define the bitmasks offsets we need for additional character properties:
//
enum{
offset_blank = U_CHAR_CATEGORY_COUNT,
offset_space = U_CHAR_CATEGORY_COUNT+1,
offset_xdigit = U_CHAR_CATEGORY_COUNT+2,
offset_underscore = U_CHAR_CATEGORY_COUNT+3,
offset_unicode = U_CHAR_CATEGORY_COUNT+4,
offset_any = U_CHAR_CATEGORY_COUNT+5,
offset_ascii = U_CHAR_CATEGORY_COUNT+6
};
//
// and now the masks:
//
static const char_class_type mask_blank;
static const char_class_type mask_space;
static const char_class_type mask_xdigit;
static const char_class_type mask_underscore;
static const char_class_type mask_unicode;
static const char_class_type mask_any;
static const char_class_type mask_ascii;
static char_class_type lookup_icu_mask(const ::UChar32* p1, const ::UChar32* p2);
boost::shared_ptr< ::boost::re_detail::icu_regex_traits_implementation> m_pimpl;
};
// types:
typedef basic_regex< ::UChar32, icu_regex_traits> u32regex;
typedef match_results<const ::UChar32*> u32match;
typedef match_results<const ::UChar*> u16match;
//
// Construction of 32-bit regex types from UTF-8 and UTF-16 primitives:
//
namespace re_detail{
template <class InputIterator>
inline u32regex do_make_u32regex(InputIterator i,
InputIterator j,
boost::regex_constants::syntax_option_type opt,
const boost::mpl::int_<1>*)
{
typedef boost::u8_to_u32_iterator<InputIterator, UChar32> conv_type;
return u32regex(conv_type(i), conv_type(j), opt);
}
template <class InputIterator>
inline u32regex do_make_u32regex(InputIterator i,
InputIterator j,
boost::regex_constants::syntax_option_type opt,
const boost::mpl::int_<2>*)
{
typedef boost::u16_to_u32_iterator<InputIterator, UChar32> conv_type;
return u32regex(conv_type(i), conv_type(j), opt);
}
template <class InputIterator>
inline u32regex do_make_u32regex(InputIterator i,
InputIterator j,
boost::regex_constants::syntax_option_type opt,
const boost::mpl::int_<4>*)
{
return u32regex(i, j, opt);
}
}
//
// Construction from an iterator pair:
//
template <class InputIterator>
inline u32regex make_u32regex(InputIterator i,
InputIterator j,
boost::regex_constants::syntax_option_type opt)
{
return re_detail::do_make_u32regex(i, j, opt, static_cast<boost::mpl::int_<sizeof(*i)> const*>(0));
}
//
// construction from UTF-8 nul-terminated strings:
//
inline u32regex make_u32regex(const char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
{
return re_detail::do_make_u32regex(p, p + std::strlen(p), opt, static_cast<boost::mpl::int_<1> const*>(0));
}
inline u32regex make_u32regex(const unsigned char* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
{
return re_detail::do_make_u32regex(p, p + std::strlen(reinterpret_cast<const char*>(p)), opt, static_cast<boost::mpl::int_<1> const*>(0));
}
//
// construction from UTF-16 nul-terminated strings:
//
#ifndef BOOST_NO_WREGEX
inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
{
return re_detail::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
#ifndef U_WCHAR_IS_UTF16
inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
{
return re_detail::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
}
#endif
//
// construction from basic_string class-template:
//
template<class C, class T, class A>
inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
{
return re_detail::do_make_u32regex(s.begin(), s.end(), opt, static_cast<boost::mpl::int_<sizeof(C)> const*>(0));
}
//
// Construction from ICU string type:
//
inline u32regex make_u32regex(const UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
{
return re_detail::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
}
//
// regex_match overloads that widen the character type as appropriate:
//
namespace re_detail{
template<class MR1, class MR2>
void copy_results(MR1& out, MR2 const& in)
{
// copy results from an adapted MR2 match_results:
out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
out.set_base(in.base().base());
for(int i = 0; i < (int)in.size(); ++i)
{
if(in[i].matched)
{
out.set_first(in[i].first.base(), i);
out.set_second(in[i].second.base(), i);
}
}
}
template <class BidiIterator, class Allocator>
inline bool do_regex_match(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags,
boost::mpl::int_<4> const*)
{
return ::boost::regex_match(first, last, m, e, flags);
}
template <class BidiIterator, class Allocator>
bool do_regex_match(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags,
boost::mpl::int_<2> const*)
{
typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
typedef match_results<conv_type> match_type;
typedef typename match_type::allocator_type alloc_type;
match_type what;
bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
// copy results across to m:
if(result) copy_results(m, what);
return result;
}
template <class BidiIterator, class Allocator>
bool do_regex_match(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags,
boost::mpl::int_<1> const*)
{
typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
typedef match_results<conv_type> match_type;
typedef typename match_type::allocator_type alloc_type;
match_type what;
bool result = ::boost::regex_match(conv_type(first), conv_type(last), what, e, flags);
// copy results across to m:
if(result) copy_results(m, what);
return result;
}
} // namespace re_detail
template <class BidiIterator, class Allocator>
inline bool u32regex_match(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
}
inline bool u32regex_match(const UChar* p,
match_results<const UChar*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
inline bool u32regex_match(const wchar_t* p,
match_results<const wchar_t*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_match(const char* p,
match_results<const char*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_match(const unsigned char* p,
match_results<const unsigned char*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_match(const std::string& s,
match_results<std::string::const_iterator>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
#ifndef BOOST_NO_STD_WSTRING
inline bool u32regex_match(const std::wstring& s,
match_results<std::wstring::const_iterator>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_match(const UnicodeString& s,
match_results<const UChar*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
//
// regex_match overloads that do not return what matched:
//
template <class BidiIterator>
inline bool u32regex_match(BidiIterator first, BidiIterator last,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<BidiIterator> m;
return re_detail::do_regex_match(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
}
inline bool u32regex_match(const UChar* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const UChar*> m;
return re_detail::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
inline bool u32regex_match(const wchar_t* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const wchar_t*> m;
return re_detail::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_match(const char* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const char*> m;
return re_detail::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_match(const unsigned char* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const unsigned char*> m;
return re_detail::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_match(const std::string& s,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<std::string::const_iterator> m;
return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
#ifndef BOOST_NO_STD_WSTRING
inline bool u32regex_match(const std::wstring& s,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<std::wstring::const_iterator> m;
return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_match(const UnicodeString& s,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const UChar*> m;
return re_detail::do_regex_match(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
//
// regex_search overloads that widen the character type as appropriate:
//
namespace re_detail{
template <class BidiIterator, class Allocator>
inline bool do_regex_search(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags,
boost::mpl::int_<4> const*)
{
return ::boost::regex_search(first, last, m, e, flags);
}
template <class BidiIterator, class Allocator>
bool do_regex_search(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags,
boost::mpl::int_<2> const*)
{
typedef u16_to_u32_iterator<BidiIterator, UChar32> conv_type;
typedef match_results<conv_type> match_type;
typedef typename match_type::allocator_type alloc_type;
match_type what;
bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags);
// copy results across to m:
if(result) copy_results(m, what);
return result;
}
template <class BidiIterator, class Allocator>
bool do_regex_search(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags,
boost::mpl::int_<1> const*)
{
typedef u8_to_u32_iterator<BidiIterator, UChar32> conv_type;
typedef match_results<conv_type> match_type;
typedef typename match_type::allocator_type alloc_type;
match_type what;
bool result = ::boost::regex_search(conv_type(first), conv_type(last), what, e, flags);
// copy results across to m:
if(result) copy_results(m, what);
return result;
}
}
template <class BidiIterator, class Allocator>
inline bool u32regex_search(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
}
inline bool u32regex_search(const UChar* p,
match_results<const UChar*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
inline bool u32regex_search(const wchar_t* p,
match_results<const wchar_t*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_search(const char* p,
match_results<const char*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_search(const unsigned char* p,
match_results<const unsigned char*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_search(const std::string& s,
match_results<std::string::const_iterator>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
#ifndef BOOST_NO_STD_WSTRING
inline bool u32regex_search(const std::wstring& s,
match_results<std::wstring::const_iterator>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_search(const UnicodeString& s,
match_results<const UChar*>& m,
const u32regex& e,
match_flag_type flags = match_default)
{
return re_detail::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
template <class BidiIterator>
inline bool u32regex_search(BidiIterator first, BidiIterator last,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<BidiIterator> m;
return re_detail::do_regex_search(first, last, m, e, flags, static_cast<mpl::int_<sizeof(*first)> const*>(0));
}
inline bool u32regex_search(const UChar* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const UChar*> m;
return re_detail::do_regex_search(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && !defined(BOOST_NO_WREGEX)
inline bool u32regex_search(const wchar_t* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const wchar_t*> m;
return re_detail::do_regex_search(p, p+std::wcslen(p), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_search(const char* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const char*> m;
return re_detail::do_regex_search(p, p+std::strlen(p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_search(const unsigned char* p,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const unsigned char*> m;
return re_detail::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
inline bool u32regex_search(const std::string& s,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<std::string::const_iterator> m;
return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<1> const*>(0));
}
#ifndef BOOST_NO_STD_WSTRING
inline bool u32regex_search(const std::wstring& s,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<std::wstring::const_iterator> m;
return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
inline bool u32regex_search(const UnicodeString& s,
const u32regex& e,
match_flag_type flags = match_default)
{
match_results<const UChar*> m;
return re_detail::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
}
//
// overloads for regex_replace with utf-8 and utf-16 data types:
//
namespace re_detail{
template <class I>
inline std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >
make_utf32_seq(I i, I j, mpl::int_<1> const*)
{
return std::pair< boost::u8_to_u32_iterator<I>, boost::u8_to_u32_iterator<I> >(boost::u8_to_u32_iterator<I>(i), boost::u8_to_u32_iterator<I>(j));
}
template <class I>
inline std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >
make_utf32_seq(I i, I j, mpl::int_<2> const*)
{
return std::pair< boost::u16_to_u32_iterator<I>, boost::u16_to_u32_iterator<I> >(boost::u16_to_u32_iterator<I>(i), boost::u16_to_u32_iterator<I>(j));
}
template <class I>
inline std::pair< I, I >
make_utf32_seq(I i, I j, mpl::int_<4> const*)
{
return std::pair< I, I >(i, j);
}
template <class charT>
inline std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >
make_utf32_seq(const charT* p, mpl::int_<1> const*)
{
return std::pair< boost::u8_to_u32_iterator<const charT*>, boost::u8_to_u32_iterator<const charT*> >(boost::u8_to_u32_iterator<const charT*>(p), boost::u8_to_u32_iterator<const charT*>(p+std::strlen((const char*)p)));
}
template <class charT>
inline std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >
make_utf32_seq(const charT* p, mpl::int_<2> const*)
{
return std::pair< boost::u16_to_u32_iterator<const charT*>, boost::u16_to_u32_iterator<const charT*> >(boost::u16_to_u32_iterator<const charT*>(p), boost::u16_to_u32_iterator<const charT*>(p+u_strlen((const UChar*)p)));
}
template <class charT>
inline std::pair< const charT*, const charT* >
make_utf32_seq(const charT* p, mpl::int_<4> const*)
{
return std::pair< const charT*, const charT* >(p, p+icu_regex_traits::length((UChar32 const*)p));
}
template <class OutputIterator>
inline OutputIterator make_utf32_out(OutputIterator o, mpl::int_<4> const*)
{
return o;
}
template <class OutputIterator>
inline utf16_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<2> const*)
{
return o;
}
template <class OutputIterator>
inline utf8_output_iterator<OutputIterator> make_utf32_out(OutputIterator o, mpl::int_<1> const*)
{
return o;
}
template <class OutputIterator, class I1, class I2>
OutputIterator do_regex_replace(OutputIterator out,
std::pair<I1, I1> const& in,
const u32regex& e,
const std::pair<I2, I2>& fmt,
match_flag_type flags
)
{
// unfortunately we have to copy the format string in order to pass in onward:
std::vector<UChar32> f;
f.assign(fmt.first, fmt.second);
regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
regex_iterator<I1, UChar32, icu_regex_traits> j;
if(i == j)
{
if(!(flags & regex_constants::format_no_copy))
out = std::copy(in.first, in.second, out);
}
else
{
I1 last_m = in.first;
while(i != j)
{
if(!(flags & regex_constants::format_no_copy))
out = std::copy(i->prefix().first, i->prefix().second, out);
out = ::boost::re_detail::regex_format_imp(out, *i, &*f.begin(), &*f.end(), flags, e.get_traits());
last_m = (*i)[0].second;
if(flags & regex_constants::format_first_only)
break;
++i;
}
if(!(flags & regex_constants::format_no_copy))
out = std::copy(last_m, in.second, out);
}
return out;
}
template <class BaseIterator>
inline const BaseIterator& extract_output_base(const BaseIterator& b)
{
return b;
}
template <class BaseIterator>
inline BaseIterator extract_output_base(const utf8_output_iterator<BaseIterator>& b)
{
return b.base();
}
template <class BaseIterator>
inline BaseIterator extract_output_base(const utf16_output_iterator<BaseIterator>& b)
{
return b.base();
}
} // re_detail
template <class OutputIterator, class BidirectionalIterator, class charT>
inline OutputIterator u32regex_replace(OutputIterator out,
BidirectionalIterator first,
BidirectionalIterator last,
const u32regex& e,
const charT* fmt,
match_flag_type flags = match_default)
{
return re_detail::extract_output_base(
re_detail::do_regex_replace(
re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
e,
re_detail::make_utf32_seq(fmt, static_cast<mpl::int_<sizeof(*fmt)> const*>(0)),
flags)
);
}
template <class OutputIterator, class Iterator, class charT>
inline OutputIterator u32regex_replace(OutputIterator out,
Iterator first,
Iterator last,
const u32regex& e,
const std::basic_string<charT>& fmt,
match_flag_type flags = match_default)
{
return re_detail::extract_output_base(
re_detail::do_regex_replace(
re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
e,
re_detail::make_utf32_seq(fmt.begin(), fmt.end(), static_cast<mpl::int_<sizeof(charT)> const*>(0)),
flags)
);
}
template <class OutputIterator, class Iterator>
inline OutputIterator u32regex_replace(OutputIterator out,
Iterator first,
Iterator last,
const u32regex& e,
const UnicodeString& fmt,
match_flag_type flags = match_default)
{
return re_detail::extract_output_base(
re_detail::do_regex_replace(
re_detail::make_utf32_out(out, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
re_detail::make_utf32_seq(first, last, static_cast<mpl::int_<sizeof(*first)> const*>(0)),
e,
re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
flags)
);
}
template <class charT>
std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
const u32regex& e,
const charT* fmt,
match_flag_type flags = match_default)
{
std::basic_string<charT> result;
re_detail::string_out_iterator<std::basic_string<charT> > i(result);
u32regex_replace(i, s.begin(), s.end(), e, fmt, flags);
return result;
}
template <class charT>
std::basic_string<charT> u32regex_replace(const std::basic_string<charT>& s,
const u32regex& e,
const std::basic_string<charT>& fmt,
match_flag_type flags = match_default)
{
std::basic_string<charT> result;
re_detail::string_out_iterator<std::basic_string<charT> > i(result);
u32regex_replace(i, s.begin(), s.end(), e, fmt.c_str(), flags);
return result;
}
namespace re_detail{
class unicode_string_out_iterator
{
UnicodeString* out;
public:
unicode_string_out_iterator(UnicodeString& s) : out(&s) {}
unicode_string_out_iterator& operator++() { return *this; }
unicode_string_out_iterator& operator++(int) { return *this; }
unicode_string_out_iterator& operator*() { return *this; }
unicode_string_out_iterator& operator=(UChar v)
{
*out += v;
return *this;
}
};
}
inline UnicodeString u32regex_replace(const UnicodeString& s,
const u32regex& e,
const UChar* fmt,
match_flag_type flags = match_default)
{
UnicodeString result;
re_detail::unicode_string_out_iterator i(result);
u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
return result;
}
inline UnicodeString u32regex_replace(const UnicodeString& s,
const u32regex& e,
const UnicodeString& fmt,
match_flag_type flags = match_default)
{
UnicodeString result;
re_detail::unicode_string_out_iterator i(result);
re_detail::do_regex_replace(
re_detail::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),
re_detail::make_utf32_seq(s.getBuffer(), s.getBuffer()+s.length(), static_cast<mpl::int_<2> const*>(0)),
e,
re_detail::make_utf32_seq(fmt.getBuffer(), fmt.getBuffer() + fmt.length(), static_cast<mpl::int_<2> const*>(0)),
flags);
return result;
}
} // namespace boost.
#include <boost/regex/v4/u32regex_iterator.hpp>
#include <boost/regex/v4/u32regex_token_iterator.hpp>
#endif

185
include/boost/regex/mfc.hpp Normal file
View File

@ -0,0 +1,185 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE mfc.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Overloads and helpers for using MFC/ATL string types with Boost.Regex.
*/
#ifndef BOOST_REGEX_MFC_HPP
#define BOOST_REGEX_MFC_HPP
#include <atlsimpstr.h>
#include <boost/regex.hpp>
namespace boost{
//
// define the types used for TCHAR's:
typedef basic_regex<TCHAR> tregex;
typedef match_results<TCHAR const*> tmatch;
typedef regex_iterator<TCHAR const*> tregex_iterator;
typedef regex_token_iterator<TCHAR const*> tregex_token_iterator;
#if _MSC_VER >= 1310
#define SIMPLE_STRING_PARAM class B, bool b
#define SIMPLE_STRING_ARG_LIST B, b
#else
#define SIMPLE_STRING_PARAM class B
#define SIMPLE_STRING_ARG_LIST B
#endif
//
// define regex creation functions:
//
template <SIMPLE_STRING_PARAM>
inline basic_regex<B>
make_regex(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, ::boost::regex_constants::syntax_option_type f = boost::regex_constants::normal)
{
basic_regex<B> result(s.GetString(), s.GetString() + s.GetLength(), f);
return result;
}
//
// regex_match overloads:
//
template <SIMPLE_STRING_PARAM, class A, class T>
inline bool regex_match(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
match_results<const B*, A>& what,
const basic_regex<B, T>& e,
boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
return ::boost::regex_match(s.GetString(),
s.GetString() + s.GetLength(),
what,
e,
f);
}
template <SIMPLE_STRING_PARAM, class T>
inline bool regex_match(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
const basic_regex<B, T>& e,
boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
return ::boost::regex_match(s.GetString(),
s.GetString() + s.GetLength(),
e,
f);
}
//
// regex_search overloads:
//
template <SIMPLE_STRING_PARAM, class A, class T>
inline bool regex_search(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
match_results<const B*, A>& what,
const basic_regex<B, T>& e,
boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
return ::boost::regex_search(s.GetString(),
s.GetString() + s.GetLength(),
what,
e,
f);
}
template <SIMPLE_STRING_PARAM, class T>
inline bool regex_search(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
const basic_regex<B, T>& e,
boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
return ::boost::regex_search(s.GetString(),
s.GetString() + s.GetLength(),
e,
f);
}
//
// regex_iterator creation:
//
template <SIMPLE_STRING_PARAM>
inline regex_iterator<B const*>
make_regex_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
regex_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, f);
return result;
}
template <SIMPLE_STRING_PARAM>
inline regex_token_iterator<B const*>
make_regex_token_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, int sub = 0, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, sub, f);
return result;
}
template <SIMPLE_STRING_PARAM>
inline regex_token_iterator<B const*>
make_regex_token_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, const std::vector<int>& subs, ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, subs, f);
return result;
}
template <SIMPLE_STRING_PARAM, std::size_t N>
inline regex_token_iterator<B const*>
make_regex_token_iterator(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s, const basic_regex<B>& e, const int (& subs)[N], ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default)
{
regex_token_iterator<B const*> result(s.GetString(), s.GetString() + s.GetLength(), e, subs, f);
return result;
}
template <class OutputIterator, class BidirectionalIterator, class traits,
SIMPLE_STRING_PARAM>
OutputIterator regex_replace(OutputIterator out,
BidirectionalIterator first,
BidirectionalIterator last,
const basic_regex<B, traits>& e,
const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& fmt,
match_flag_type flags = match_default)
{
return ::boost::regex_replace(out, first, last, e, fmt.GetString(), flags);
}
namespace re_detail{
template <SIMPLE_STRING_PARAM>
class mfc_string_out_iterator
{
ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>* out;
public:
mfc_string_out_iterator(ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s) : out(&s) {}
mfc_string_out_iterator& operator++() { return *this; }
mfc_string_out_iterator& operator++(int) { return *this; }
mfc_string_out_iterator& operator*() { return *this; }
mfc_string_out_iterator& operator=(B v)
{
out->AppendChar(v);
return *this;
}
};
}
template <class traits, SIMPLE_STRING_PARAM>
ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST> regex_replace(const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& s,
const basic_regex<B, traits>& e,
const ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST>& fmt,
match_flag_type flags = match_default)
{
ATL::CSimpleStringT<SIMPLE_STRING_ARG_LIST> result(s.GetManager());
re_detail::mfc_string_out_iterator<SIMPLE_STRING_ARG_LIST> i(result);
regex_replace(i, s.GetString(), s.GetString() + s.GetLength(), e, fmt.GetString(), flags);
return result;
}
} // namespace boost.
#endif

View File

@ -23,6 +23,10 @@
#include <boost/regex/config.hpp>
#endif
#include <stdexcept>
#include <cstddef>
#include <boost/regex/v4/error_type.hpp>
namespace boost{
#ifdef BOOST_HAS_ABI_HEADERS
@ -33,22 +37,39 @@ namespace boost{
#pragma warning(push)
#pragma warning(disable : 4275)
#endif
class BOOST_REGEX_DECL bad_pattern : public std::runtime_error
class BOOST_REGEX_DECL regex_error : public std::runtime_error
{
public:
explicit bad_pattern(const std::string& s) : std::runtime_error(s){};
~bad_pattern() throw();
explicit regex_error(const std::string& s, regex_constants::error_type err, std::ptrdiff_t pos);
explicit regex_error(regex_constants::error_type err);
~regex_error() throw();
regex_constants::error_type code()const
{ return m_error_code; }
std::ptrdiff_t position()const
{ return m_position; }
void raise()const;
private:
regex_constants::error_type m_error_code;
std::ptrdiff_t m_position;
};
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
class BOOST_REGEX_DECL bad_expression : public bad_pattern
typedef regex_error bad_pattern;
typedef regex_error bad_expression;
namespace re_detail{
BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex);
template <class traits>
void raise_error(const traits& t, regex_constants::error_type code)
{
public:
explicit bad_expression(const std::string& s) : bad_pattern(s) {}
~bad_expression() throw();
};
(void)t; // warning suppression
std::runtime_error e(t.error_string(code));
::boost::re_detail::raise_runtime_error(e);
}
}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX

View File

@ -0,0 +1,159 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE object_cache.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Implements a generic object cache.
*/
#ifndef BOOST_REGEX_OBJECT_CACHE_HPP
#define BOOST_REGEX_OBJECT_CACHE_HPP
#include <map>
#include <list>
#include <stdexcept>
#include <string>
#include <boost/config.hpp>
#include <boost/shared_ptr.hpp>
#ifdef BOOST_HAS_THREADS
#include <boost/regex/pending/static_mutex.hpp>
#endif
namespace boost{
template <class Key, class Object>
class object_cache
{
typedef std::pair< ::boost::shared_ptr<Object>, Key const*> value_type;
typedef std::list<value_type> list_type;
typedef typename list_type::iterator list_iterator;
typedef std::map<Key, list_iterator> map_type;
typedef typename map_type::iterator map_iterator;
typedef typename list_type::size_type size_type;
public:
static boost::shared_ptr<Object> get(const Key& k, size_type max_cache_size);
private:
static boost::shared_ptr<Object> do_get(const Key& k, size_type max_cache_size);
struct data
{
list_type cont;
map_type index;
};
};
template <class Key, class Object>
boost::shared_ptr<Object> object_cache<Key, Object>::get(const Key& k, size_type max_cache_size)
{
#ifdef BOOST_HAS_THREADS
static boost::static_mutex mut = BOOST_STATIC_MUTEX_INIT;
boost::static_mutex::scoped_lock l(mut);
if(l)
{
return do_get(k, max_cache_size);
}
//
// what do we do if the lock fails?
// for now just throw, but we should never really get here...
//
::boost::throw_exception(std::runtime_error("Error in thread safety code: could not acquire a lock"));
return boost::shared_ptr<Object>();
#else
return do_get(k, max_cache_size);
#endif
}
template <class Key, class Object>
boost::shared_ptr<Object> object_cache<Key, Object>::do_get(const Key& k, size_type max_cache_size)
{
typedef typename object_cache<Key, Object>::data object_data;
typedef typename list_type::size_type list_size_type;
static object_data s_data;
//
// see if the object is already in the cache:
//
map_iterator mpos = s_data.index.find(k);
if(mpos != s_data.index.end())
{
//
// Eureka!
// We have a cached item, bump it up the list and return it:
//
if(--(s_data.cont.end()) != mpos->second)
{
// splice out the item we want to move:
list_type temp;
temp.splice(temp.end(), s_data.cont, mpos->second);
// and now place it at the end of the list:
s_data.cont.splice(s_data.cont.end(), temp, temp.begin());
BOOST_ASSERT(*(s_data.cont.back().second) == k);
// update index with new position:
mpos->second = --(s_data.cont.end());
BOOST_ASSERT(&(mpos->first) == mpos->second->second);
BOOST_ASSERT(&(mpos->first) == s_data.cont.back().second);
}
return s_data.cont.back().first;
}
//
// if we get here then the item is not in the cache,
// so create it:
//
boost::shared_ptr<Object> result(new Object(k));
//
// Add it to the list, and index it:
//
s_data.cont.push_back(value_type(result, 0));
s_data.index[k] = --(s_data.cont.end());
s_data.cont.back().second = &(s_data.index.find(k)->first);
list_size_type s = s_data.cont.size();
BOOST_ASSERT(s_data.index[k]->first.get() == result.get());
BOOST_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second);
BOOST_ASSERT(s_data.index.find(k)->first == k);
if(s > max_cache_size)
{
//
// We have too many items in the list, so we need to start
// popping them off the back of the list, but only if they're
// being held uniquely by us:
//
list_iterator pos = s_data.cont.begin();
list_iterator last = s_data.cont.end();
while((pos != last) && (s > max_cache_size))
{
if(pos->first.unique())
{
list_iterator condemmed(pos);
++pos;
// now remove the items from our containers,
// then order has to be as follows:
BOOST_ASSERT(s_data.index.find(*(condemmed->second)) != s_data.index.end());
s_data.index.erase(*(condemmed->second));
s_data.cont.erase(condemmed);
--s;
}
else
--pos;
}
BOOST_ASSERT(s_data.index[k]->first.get() == result.get());
BOOST_ASSERT(&(s_data.index.find(k)->first) == s_data.cont.back().second);
BOOST_ASSERT(s_data.index.find(k)->first == k);
}
return result;
}
}
#endif

View File

@ -0,0 +1,180 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE static_mutex.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares static_mutex lock type, there are three different
* implementations: POSIX pthreads, WIN32 threads, and portable,
* these are described in more detail below.
*/
#ifndef BOOST_REGEX_STATIC_MUTEX_HPP
#define BOOST_REGEX_STATIC_MUTEX_HPP
#include <boost/config.hpp>
#include <boost/regex/config.hpp> // dll import/export options.
#ifdef BOOST_HAS_PTHREADS
#include <pthread.h>
#endif
#if defined(BOOST_HAS_PTHREADS) && defined(PTHREAD_MUTEX_INITIALIZER)
//
// pthreads version:
// simple wrap around a pthread_mutex_t initialized with
// PTHREAD_MUTEX_INITIALIZER.
//
namespace boost{
class BOOST_REGEX_DECL scoped_static_mutex_lock;
class static_mutex
{
public:
typedef scoped_static_mutex_lock scoped_lock;
pthread_mutex_t m_mutex;
};
#define BOOST_STATIC_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER, }
class BOOST_REGEX_DECL scoped_static_mutex_lock
{
public:
scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
~scoped_static_mutex_lock();
operator void const*()const;
bool locked()const;
void lock();
void unlock();
private:
static_mutex& m_mutex;
bool m_have_lock;
};
inline scoped_static_mutex_lock::operator void const*()const
{
return locked() ? this : 0;
}
inline bool scoped_static_mutex_lock::locked()const
{
return m_have_lock;
}
} // namespace boost
#elif defined(BOOST_HAS_WINTHREADS)
//
// Win32 version:
// Use a 32-bit int as a lock, along with a test-and-set
// implementation using InterlockedCompareExchange.
//
#include <boost/cstdint.hpp>
namespace boost{
class BOOST_REGEX_DECL scoped_static_mutex_lock;
class static_mutex
{
public:
typedef scoped_static_mutex_lock scoped_lock;
boost::int32_t m_mutex;
};
#define BOOST_STATIC_MUTEX_INIT { 0, }
class BOOST_REGEX_DECL scoped_static_mutex_lock
{
public:
scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
~scoped_static_mutex_lock();
operator void const*()const;
bool locked()const;
void lock();
void unlock();
private:
static_mutex& m_mutex;
bool m_have_lock;
scoped_static_mutex_lock(const scoped_static_mutex_lock&);
scoped_static_mutex_lock& operator=(const scoped_static_mutex_lock&);
};
inline scoped_static_mutex_lock::operator void const*()const
{
return locked() ? this : 0;
}
inline bool scoped_static_mutex_lock::locked()const
{
return m_have_lock;
}
} // namespace
#else
//
// Portable version of a static mutex based on Boost.Thread library:
// This has to use a single mutex shared by all instances of static_mutex
// because boost::call_once doesn't alow us to pass instance information
// down to the initialisation proceedure. In fact the initialisation routine
// may need to be called more than once - but only once per instance.
//
#include <boost/thread/once.hpp>
#include <boost/thread/recursive_mutex.hpp>
namespace boost{
class BOOST_REGEX_DECL scoped_static_mutex_lock;
extern "C" BOOST_REGEX_DECL void free_static_mutex();
class BOOST_REGEX_DECL static_mutex
{
public:
typedef scoped_static_mutex_lock scoped_lock;
static void init();
static boost::recursive_mutex* m_pmutex;
static boost::once_flag m_once;
};
#define BOOST_STATIC_MUTEX_INIT { }
class BOOST_REGEX_DECL scoped_static_mutex_lock
{
public:
scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
~scoped_static_mutex_lock();
operator void const*()const;
bool locked()const;
void lock();
void unlock();
private:
boost::recursive_mutex::scoped_lock* m_plock;
bool m_have_lock;
};
inline scoped_static_mutex_lock::operator void const*()const
{
return locked() ? this : 0;
}
inline bool scoped_static_mutex_lock::locked()const
{
return m_have_lock;
}
} // namespace
#endif
#endif

View File

@ -0,0 +1,676 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE unicode_iterator.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Iterator adapters for converting between different Unicode encodings.
*/
/****************************************************************************
Contents:
~~~~~~~~~
1) Read Only, Input Adapters:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class BaseIterator, class U8Type = ::boost::uint8_t>
class u32_to_u8_iterator;
Adapts sequence of UTF-32 code points to "look like" a sequence of UTF-8.
template <class BaseIterator, class U32Type = ::boost::uint32_t>
class u8_to_u32_iterator;
Adapts sequence of UTF-8 code points to "look like" a sequence of UTF-32.
template <class BaseIterator, class U16Type = ::boost::uint16_t>
class u32_to_u16_iterator;
Adapts sequence of UTF-32 code points to "look like" a sequence of UTF-16.
template <class BaseIterator, class U32Type = ::boost::uint32_t>
class u16_to_u32_iterator;
Adapts sequence of UTF-16 code points to "look like" a sequence of UTF-32.
2) Single pass output iterator adapters:
template <class BaseIterator>
class utf8_output_iterator;
Accepts UTF-32 code points and forwards them on as UTF-8 code points.
template <class BaseIterator>
class utf16_output_iterator;
Accepts UTF-32 code points and forwards them on as UTF-16 code points.
****************************************************************************/
#ifndef BOOST_REGEX_UNICODE_ITERATOR_HPP
#define BOOST_REGEX_UNICODE_ITERATOR_HPP
#include <boost/cstdint.hpp>
#include <boost/assert.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
#include <stdexcept>
#ifndef BOOST_NO_STD_LOCALE
#include <sstream>
#endif
namespace boost{
namespace detail{
static const ::boost::uint16_t high_surrogate_base = 0xD7C0u;
static const ::boost::uint16_t low_surrogate_base = 0xDC00u;
static const ::boost::uint32_t ten_bit_mask = 0x3FFu;
inline bool is_high_surrogate(::boost::uint16_t v)
{
return (v & 0xFC00u) == 0xd800u;
}
inline bool is_low_surrogate(::boost::uint16_t v)
{
return (v & 0xFC00u) == 0xdc00u;
}
template <class T>
inline bool is_surrogate(T v)
{
return (v & 0xF800u) == 0xd800;
}
inline unsigned utf8_byte_count(boost::uint8_t c)
{
// if the most significant bit with a zero in it is in position
// 8-N then there are N bytes in this UTF-8 sequence:
boost::uint8_t mask = 0x80u;
unsigned result = 0;
while(c & mask)
{
++result;
mask >>= 1;
}
return (result == 0) ? 1 : ((result > 4) ? 4 : result);
}
inline unsigned utf8_trailing_byte_count(boost::uint8_t c)
{
return utf8_byte_count(c) - 1;
}
inline void invalid_utf32_code_point(::boost::uint32_t val)
{
#ifndef BOOST_NO_STD_LOCALE
std::stringstream ss;
ss << "Invalid UTF-32 code point U+" << std::showbase << std::hex << val << " encountered while trying to encode UTF-16 sequence";
std::out_of_range e(ss.str());
#else
std::out_of_range e("Invalid UTF-32 code point encountered while trying to encode UTF-16 sequence");
#endif
boost::throw_exception(e);
}
} // namespace detail
template <class BaseIterator, class U16Type = ::boost::uint16_t>
class u32_to_u16_iterator
: public boost::iterator_facade<u32_to_u16_iterator<BaseIterator, U16Type>, U16Type, std::bidirectional_iterator_tag, const U16Type>
{
typedef boost::iterator_facade<u32_to_u16_iterator<BaseIterator, U16Type>, U16Type, std::bidirectional_iterator_tag, const U16Type> base_type;
#if !defined(BOOST_NO_STD_ITERATOR_TRAITS) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef typename std::iterator_traits<BaseIterator>::value_type base_value_type;
BOOST_STATIC_ASSERT(sizeof(base_value_type)*CHAR_BIT == 32);
BOOST_STATIC_ASSERT(sizeof(U16Type)*CHAR_BIT == 16);
#endif
public:
typename base_type::reference
dereference()const
{
if(m_current == 2)
extract_current();
return m_values[m_current];
}
bool equal(const u32_to_u16_iterator& that)const
{
if(m_position == that.m_position)
{
// Both m_currents must be equal, or both even
// this is the same as saying their sum must be even:
return (m_current + that.m_current) & 1u ? false : true;
}
return false;
}
void increment()
{
// if we have a pending read then read now, so that we know whether
// to skip a position, or move to a low-surrogate:
if(m_current == 2)
{
// pending read:
extract_current();
}
// move to the next surrogate position:
++m_current;
// if we've reached the end skip a position:
if(m_values[m_current] == 0)
{
m_current = 2;
++m_position;
}
}
void decrement()
{
if(m_current != 1)
{
// decrementing an iterator always leads to a valid position:
--m_position;
extract_current();
m_current = m_values[1] ? 1 : 0;
}
else
{
m_current = 0;
}
}
BaseIterator base()const
{
return m_position;
}
// construct:
u32_to_u16_iterator() : m_position(), m_current(0)
{
m_values[2] = 0;
}
u32_to_u16_iterator(BaseIterator b) : m_position(b), m_current(2)
{
m_values[2] = 0;
}
private:
void extract_current()const
{
// begin by checking for a code point out of range:
::boost::uint32_t v = *m_position;
if(v >= 0x10000u)
{
if(v > 0x10FFFFu)
detail::invalid_utf32_code_point(*m_position);
// split into two surrogates:
m_values[0] = static_cast<U16Type>(v >> 10) + detail::high_surrogate_base;
m_values[1] = static_cast<U16Type>(v & detail::ten_bit_mask) + detail::low_surrogate_base;
m_current = 0;
BOOST_ASSERT(detail::is_high_surrogate(m_values[0]));
BOOST_ASSERT(detail::is_low_surrogate(m_values[1]));
}
else
{
// 16-bit code point:
m_values[0] = static_cast<U16Type>(*m_position);
m_values[1] = 0;
m_current = 0;
// value must not be a surrogate:
if(detail::is_surrogate(m_values[0]))
detail::invalid_utf32_code_point(*m_position);
}
}
BaseIterator m_position;
mutable U16Type m_values[3];
mutable unsigned m_current;
};
template <class BaseIterator, class U32Type = ::boost::uint32_t>
class u16_to_u32_iterator
: public boost::iterator_facade<u16_to_u32_iterator<BaseIterator, U32Type>, U32Type, std::bidirectional_iterator_tag, const U32Type>
{
typedef boost::iterator_facade<u16_to_u32_iterator<BaseIterator, U32Type>, U32Type, std::bidirectional_iterator_tag, const U32Type> base_type;
// special values for pending iterator reads:
BOOST_STATIC_CONSTANT(U32Type, pending_read = 0xffffffffu);
#if !defined(BOOST_NO_STD_ITERATOR_TRAITS) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef typename std::iterator_traits<BaseIterator>::value_type base_value_type;
BOOST_STATIC_ASSERT(sizeof(base_value_type)*CHAR_BIT == 16);
BOOST_STATIC_ASSERT(sizeof(U32Type)*CHAR_BIT == 32);
#endif
public:
typename base_type::reference
dereference()const
{
if(m_value == pending_read)
extract_current();
return m_value;
}
bool equal(const u16_to_u32_iterator& that)const
{
return m_position == that.m_position;
}
void increment()
{
// skip high surrogate first if there is one:
if(detail::is_high_surrogate(*m_position)) ++m_position;
++m_position;
m_value = pending_read;
}
void decrement()
{
--m_position;
// if we have a low surrogate then go back one more:
if(detail::is_low_surrogate(*m_position))
--m_position;
m_value = pending_read;
}
BaseIterator base()const
{
return m_position;
}
// construct:
u16_to_u32_iterator() : m_position()
{
}
u16_to_u32_iterator(BaseIterator b) : m_position(b)
{
m_value = pending_read;
}
private:
static void invalid_code_point(::boost::uint16_t val)
{
#ifndef BOOST_NO_STD_LOCALE
std::stringstream ss;
ss << "Misplaced UTF-16 surrogate U+" << std::showbase << std::hex << val << " encountered while trying to encode UTF-32 sequence";
std::out_of_range e(ss.str());
#else
std::out_of_range e("Misplaced UTF-16 surrogate encountered while trying to encode UTF-32 sequence");
#endif
boost::throw_exception(e);
}
void extract_current()const
{
m_value = static_cast<U32Type>(static_cast< ::boost::uint16_t>(*m_position));
// if the last value is a high surrogate then adjust m_position and m_value as needed:
if(detail::is_high_surrogate(*m_position))
{
// precondition; next value must have be a low-surrogate:
BaseIterator next(m_position);
::boost::uint16_t t = *++next;
if((t & 0xFC00u) != 0xDC00u)
invalid_code_point(t);
m_value = (m_value - detail::high_surrogate_base) << 10;
m_value |= (static_cast<U32Type>(static_cast< ::boost::uint16_t>(t)) & detail::ten_bit_mask);
}
// postcondition; result must not be a surrogate:
if(detail::is_surrogate(m_value))
invalid_code_point(static_cast< ::boost::uint16_t>(m_value));
}
BaseIterator m_position;
mutable U32Type m_value;
};
template <class BaseIterator, class U8Type = ::boost::uint8_t>
class u32_to_u8_iterator
: public boost::iterator_facade<u32_to_u8_iterator<BaseIterator, U8Type>, U8Type, std::bidirectional_iterator_tag, const U8Type>
{
typedef boost::iterator_facade<u32_to_u8_iterator<BaseIterator, U8Type>, U8Type, std::bidirectional_iterator_tag, const U8Type> base_type;
#if !defined(BOOST_NO_STD_ITERATOR_TRAITS) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef typename std::iterator_traits<BaseIterator>::value_type base_value_type;
BOOST_STATIC_ASSERT(sizeof(base_value_type)*CHAR_BIT == 32);
BOOST_STATIC_ASSERT(sizeof(U8Type)*CHAR_BIT == 8);
#endif
public:
typename base_type::reference
dereference()const
{
if(m_current == 4)
extract_current();
return m_values[m_current];
}
bool equal(const u32_to_u8_iterator& that)const
{
if(m_position == that.m_position)
{
// either the m_current's must be equal, or one must be 0 and
// the other 4: which means neither must have bits 1 or 2 set:
return (m_current == that.m_current)
|| (((m_current | that.m_current) & 3) == 0);
}
return false;
}
void increment()
{
// if we have a pending read then read now, so that we know whether
// to skip a position, or move to a low-surrogate:
if(m_current == 4)
{
// pending read:
extract_current();
}
// move to the next surrogate position:
++m_current;
// if we've reached the end skip a position:
if(m_values[m_current] == 0)
{
m_current = 4;
++m_position;
}
}
void decrement()
{
if((m_current & 3) == 0)
{
--m_position;
extract_current();
m_current = 3;
while(m_current && (m_values[m_current] == 0))
--m_current;
}
else
--m_current;
}
BaseIterator base()const
{
return m_position;
}
// construct:
u32_to_u8_iterator() : m_position(), m_current(0)
{
m_values[4] = 0;
}
u32_to_u8_iterator(BaseIterator b) : m_position(b), m_current(4)
{
m_values[4] = 0;
}
private:
void extract_current()const
{
boost::uint32_t c = *m_position;
if(c > 0x10FFFFu)
detail::invalid_utf32_code_point(c);
if(c < 0x80u)
{
m_values[0] = static_cast<unsigned char>(c);
m_values[1] = static_cast<unsigned char>(0u);
m_values[2] = static_cast<unsigned char>(0u);
m_values[3] = static_cast<unsigned char>(0u);
}
else if(c < 0x800u)
{
m_values[0] = static_cast<unsigned char>(0xC0u + (c >> 6));
m_values[1] = static_cast<unsigned char>(0x80u + (c & 0x3Fu));
m_values[2] = static_cast<unsigned char>(0u);
m_values[3] = static_cast<unsigned char>(0u);
}
else if(c < 0x10000u)
{
m_values[0] = static_cast<unsigned char>(0xE0u + (c >> 12));
m_values[1] = static_cast<unsigned char>(0x80u + ((c >> 6) & 0x3Fu));
m_values[2] = static_cast<unsigned char>(0x80u + (c & 0x3Fu));
m_values[3] = static_cast<unsigned char>(0u);
}
else
{
m_values[0] = static_cast<unsigned char>(0xF0u + (c >> 18));
m_values[1] = static_cast<unsigned char>(0x80u + ((c >> 12) & 0x3Fu));
m_values[2] = static_cast<unsigned char>(0x80u + ((c >> 6) & 0x3Fu));
m_values[3] = static_cast<unsigned char>(0x80u + (c & 0x3Fu));
}
m_current= 0;
}
BaseIterator m_position;
mutable U8Type m_values[5];
mutable unsigned m_current;
};
template <class BaseIterator, class U32Type = ::boost::uint32_t>
class u8_to_u32_iterator
: public boost::iterator_facade<u8_to_u32_iterator<BaseIterator, U32Type>, U32Type, std::bidirectional_iterator_tag, const U32Type>
{
typedef boost::iterator_facade<u8_to_u32_iterator<BaseIterator, U32Type>, U32Type, std::bidirectional_iterator_tag, const U32Type> base_type;
// special values for pending iterator reads:
BOOST_STATIC_CONSTANT(U32Type, pending_read = 0xffffffffu);
#if !defined(BOOST_NO_STD_ITERATOR_TRAITS) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef typename std::iterator_traits<BaseIterator>::value_type base_value_type;
BOOST_STATIC_ASSERT(sizeof(base_value_type)*CHAR_BIT == 8);
BOOST_STATIC_ASSERT(sizeof(U32Type)*CHAR_BIT == 32);
#endif
public:
typename base_type::reference
dereference()const
{
if(m_value == pending_read)
extract_current();
return m_value;
}
bool equal(const u8_to_u32_iterator& that)const
{
return m_position == that.m_position;
}
void increment()
{
// skip high surrogate first if there is one:
unsigned c = detail::utf8_byte_count(*m_position);
std::advance(m_position, c);
m_value = pending_read;
}
void decrement()
{
// Keep backtracking until we don't have a trailing character:
unsigned count = 0;
while((*--m_position & 0xC0u) == 0x80u) ++count;
// now check that the sequence was valid:
if(count != detail::utf8_trailing_byte_count(*m_position))
invalid_sequnce();
m_value = pending_read;
}
BaseIterator base()const
{
return m_position;
}
// construct:
u8_to_u32_iterator() : m_position()
{
m_value = pending_read;
}
u8_to_u32_iterator(BaseIterator b) : m_position(b)
{
m_value = pending_read;
}
private:
static void invalid_sequnce()
{
std::out_of_range e("Invalid UTF-8 sequence encountered while trying to encode UTF-32 character");
boost::throw_exception(e);
}
void extract_current()const
{
m_value = static_cast<U32Type>(static_cast< ::boost::uint8_t>(*m_position));
// we must not have a continuation character:
if((m_value & 0xC0u) == 0x80u)
invalid_sequnce();
// see how many extra byts we have:
unsigned extra = detail::utf8_trailing_byte_count(*m_position);
// extract the extra bits, 6 from each extra byte:
BaseIterator next(m_position);
for(unsigned c = 0; c < extra; ++c)
{
++next;
m_value <<= 6;
m_value += static_cast<boost::uint8_t>(*next) & 0x3Fu;
}
// we now need to remove a few of the leftmost bits, but how many depends
// upon how many extra bytes we've extracted:
static const boost::uint32_t masks[] =
{
0x7Fu,
0x7FFu,
0xFFFFu,
0x1FFFFFu,
};
m_value &= masks[extra];
// check the result:
if(m_value > static_cast<U32Type>(0x10FFFFu))
invalid_sequnce();
}
BaseIterator m_position;
mutable U32Type m_value;
};
template <class BaseIterator>
class utf16_output_iterator
{
public:
typedef void difference_type;
typedef void value_type;
typedef boost::uint32_t* pointer;
typedef boost::uint32_t& reference;
typedef std::output_iterator_tag iterator_category;
utf16_output_iterator(const BaseIterator& b)
: m_position(b){}
utf16_output_iterator(const utf16_output_iterator& that)
: m_position(that.m_position){}
utf16_output_iterator& operator=(const utf16_output_iterator& that)
{
m_position = that.m_position;
return *this;
}
const utf16_output_iterator& operator*()const
{
return *this;
}
void operator=(boost::uint32_t val)const
{
push(val);
}
utf16_output_iterator& operator++()
{
return *this;
}
utf16_output_iterator& operator++(int)
{
return *this;
}
BaseIterator base()const
{
return m_position;
}
private:
void push(boost::uint32_t v)const
{
if(v >= 0x10000u)
{
// begin by checking for a code point out of range:
if(v > 0x10FFFFu)
detail::invalid_utf32_code_point(v);
// split into two surrogates:
*m_position++ = static_cast<boost::uint16_t>(v >> 10) + detail::high_surrogate_base;
*m_position++ = static_cast<boost::uint16_t>(v & detail::ten_bit_mask) + detail::low_surrogate_base;
}
else
{
// 16-bit code point:
// value must not be a surrogate:
if(detail::is_surrogate(v))
detail::invalid_utf32_code_point(v);
*m_position++ = static_cast<boost::uint16_t>(v);
}
}
mutable BaseIterator m_position;
};
template <class BaseIterator>
class utf8_output_iterator
{
public:
typedef void difference_type;
typedef void value_type;
typedef boost::uint32_t* pointer;
typedef boost::uint32_t& reference;
typedef std::output_iterator_tag iterator_category;
utf8_output_iterator(const BaseIterator& b)
: m_position(b){}
utf8_output_iterator(const utf8_output_iterator& that)
: m_position(that.m_position){}
utf8_output_iterator& operator=(const utf8_output_iterator& that)
{
m_position = that.m_position;
return *this;
}
const utf8_output_iterator& operator*()const
{
return *this;
}
void operator=(boost::uint32_t val)const
{
push(val);
}
utf8_output_iterator& operator++()
{
return *this;
}
utf8_output_iterator& operator++(int)
{
return *this;
}
BaseIterator base()const
{
return m_position;
}
private:
void push(boost::uint32_t c)const
{
if(c > 0x10FFFFu)
detail::invalid_utf32_code_point(c);
if(c < 0x80u)
{
*m_position++ = static_cast<unsigned char>(c);
}
else if(c < 0x800u)
{
*m_position++ = static_cast<unsigned char>(0xC0u + (c >> 6));
*m_position++ = static_cast<unsigned char>(0x80u + (c & 0x3Fu));
}
else if(c < 0x10000u)
{
*m_position++ = static_cast<unsigned char>(0xE0u + (c >> 12));
*m_position++ = static_cast<unsigned char>(0x80u + ((c >> 6) & 0x3Fu));
*m_position++ = static_cast<unsigned char>(0x80u + (c & 0x3Fu));
}
else
{
*m_position++ = static_cast<unsigned char>(0xF0u + (c >> 18));
*m_position++ = static_cast<unsigned char>(0x80u + ((c >> 12) & 0x3Fu));
*m_position++ = static_cast<unsigned char>(0x80u + ((c >> 6) & 0x3Fu));
*m_position++ = static_cast<unsigned char>(0x80u + (c & 0x3Fu));
}
}
mutable BaseIterator m_position;
};
} // namespace boost
#endif // BOOST_REGEX_UNICODE_ITERATOR_HPP

View File

@ -0,0 +1,180 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE static_mutex.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares static_mutex lock type, there are three different
* implementations: POSIX pthreads, WIN32 threads, and portable,
* these are described in more detail below.
*/
#ifndef BOOST_REGEX_STATIC_MUTEX_HPP
#define BOOST_REGEX_STATIC_MUTEX_HPP
#include <boost/config.hpp>
#include <boost/regex/config.hpp> // dll import/export options.
#ifdef BOOST_HAS_PTHREADS
#include <pthread.h>
#endif
#if defined(BOOST_HAS_PTHREADS) && defined(PTHREAD_MUTEX_INITIALIZER)
//
// pthreads version:
// simple wrap around a pthread_mutex_t initialized with
// PTHREAD_MUTEX_INITIALIZER.
//
namespace boost{
class BOOST_REGEX_DECL scoped_static_mutex_lock;
class static_mutex
{
public:
typedef scoped_static_mutex_lock scoped_lock;
pthread_mutex_t m_mutex;
};
#define BOOST_STATIC_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER, }
class BOOST_REGEX_DECL scoped_static_mutex_lock
{
public:
scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
~scoped_static_mutex_lock();
operator void const*()const;
bool locked()const;
void lock();
void unlock();
private:
static_mutex& m_mutex;
bool m_have_lock;
};
inline scoped_static_mutex_lock::operator void const*()const
{
return locked() ? this : 0;
}
inline bool scoped_static_mutex_lock::locked()const
{
return m_have_lock;
}
} // namespace boost
#elif defined(BOOST_HAS_WINTHREADS)
//
// Win32 version:
// Use a 32-bit int as a lock, along with a test-and-set
// implementation using InterlockedCompareExchange.
//
#include <boost/cstdint.hpp>
namespace boost{
class BOOST_REGEX_DECL scoped_static_mutex_lock;
class static_mutex
{
public:
typedef scoped_static_mutex_lock scoped_lock;
boost::int32_t m_mutex;
};
#define BOOST_STATIC_MUTEX_INIT { 0, }
class BOOST_REGEX_DECL scoped_static_mutex_lock
{
public:
scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
~scoped_static_mutex_lock();
operator void const*()const;
bool locked()const;
void lock();
void unlock();
private:
static_mutex& m_mutex;
bool m_have_lock;
scoped_static_mutex_lock(const scoped_static_mutex_lock&);
scoped_static_mutex_lock& operator=(const scoped_static_mutex_lock&);
};
inline scoped_static_mutex_lock::operator void const*()const
{
return locked() ? this : 0;
}
inline bool scoped_static_mutex_lock::locked()const
{
return m_have_lock;
}
} // namespace
#else
//
// Portable version of a static mutex based on Boost.Thread library:
// This has to use a single mutex shared by all instances of static_mutex
// because boost::call_once doesn't alow us to pass instance information
// down to the initialisation proceedure. In fact the initialisation routine
// may need to be called more than once - but only once per instance.
//
#include <boost/thread/once.hpp>
#include <boost/thread/recursive_mutex.hpp>
namespace boost{
class BOOST_REGEX_DECL scoped_static_mutex_lock;
extern "C" BOOST_REGEX_DECL void free_static_mutex();
class BOOST_REGEX_DECL static_mutex
{
public:
typedef scoped_static_mutex_lock scoped_lock;
static void init();
static boost::recursive_mutex* m_pmutex;
static boost::once_flag m_once;
};
#define BOOST_STATIC_MUTEX_INIT { }
class BOOST_REGEX_DECL scoped_static_mutex_lock
{
public:
scoped_static_mutex_lock(static_mutex& mut, bool lk = true);
~scoped_static_mutex_lock();
operator void const*()const;
bool locked()const;
void lock();
void unlock();
private:
boost::recursive_mutex::scoped_lock* m_plock;
bool m_have_lock;
};
inline scoped_static_mutex_lock::operator void const*()const
{
return locked() ? this : 0;
}
inline bool scoped_static_mutex_lock::locked()const
{
return m_have_lock;
}
} // namespace
#endif
#endif

View File

@ -1,314 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE cregex.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares POSIX API functions
* + boost::RegEx high level wrapper.
*/
#ifndef BOOST_RE_CREGEX_HPP_INCLUDED
#define BOOST_RE_CREGEX_HPP_INCLUDED
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
/* include these defs only for POSIX compatablity */
#ifdef __cplusplus
namespace boost{
extern "C" {
#endif
#if defined(__cplusplus) && !defined(BOOST_NO_STDC_NAMESPACE)
typedef std::ptrdiff_t regoff_t;
typedef std::size_t regsize_t;
#else
typedef ptrdiff_t regoff_t;
typedef size_t regsize_t;
#endif
typedef struct
{
unsigned int re_magic;
unsigned int re_nsub; /* number of parenthesized subexpressions */
const char* re_endp; /* end pointer for REG_PEND */
void* guts; /* none of your business :-) */
unsigned int eflags; /* none of your business :-) */
} regex_tA;
#ifndef BOOST_NO_WREGEX
typedef struct
{
unsigned int re_magic;
unsigned int re_nsub; /* number of parenthesized subexpressions */
const wchar_t* re_endp; /* end pointer for REG_PEND */
void* guts; /* none of your business :-) */
unsigned int eflags; /* none of your business :-) */
} regex_tW;
#endif
typedef struct
{
regoff_t rm_so; /* start of match */
regoff_t rm_eo; /* end of match */
} regmatch_t;
/* regcomp() flags */
typedef enum{
REG_BASIC = 0000,
REG_EXTENDED = 0001,
REG_ICASE = 0002,
REG_NOSUB = 0004,
REG_NEWLINE = 0010,
REG_NOSPEC = 0020,
REG_PEND = 0040,
REG_DUMP = 0200,
REG_NOCOLLATE = 0400,
REG_ESCAPE_IN_LISTS = 01000,
REG_NEWLINE_ALT = 02000,
REG_PERL = REG_EXTENDED | REG_NOCOLLATE | REG_ESCAPE_IN_LISTS,
REG_AWK = REG_EXTENDED | REG_ESCAPE_IN_LISTS,
REG_GREP = REG_BASIC | REG_NEWLINE_ALT,
REG_EGREP = REG_EXTENDED | REG_NEWLINE_ALT,
REG_ASSERT = 15,
REG_INVARG = 16,
REG_ATOI = 255, /* convert name to number (!) */
REG_ITOA = 0400 /* convert number to name (!) */
} reg_comp_flags;
/* regexec() flags */
typedef enum{
REG_NOTBOL = 00001,
REG_NOTEOL = 00002,
REG_STARTEND = 00004
} reg_exec_flags;
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int);
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t);
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int);
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeA(regex_tA*);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW*, const wchar_t*, int);
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorW(int, const regex_tW*, wchar_t*, regsize_t);
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecW(const regex_tW*, const wchar_t*, regsize_t, regmatch_t*, int);
BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*);
#endif
#ifdef UNICODE
#define regcomp regcompW
#define regerror regerrorW
#define regexec regexecW
#define regfree regfreeW
#define regex_t regex_tW
#else
#define regcomp regcompA
#define regerror regerrorA
#define regexec regexecA
#define regfree regfreeA
#define regex_t regex_tA
#endif
/* regerror() flags */
typedef enum
{
REG_NOERROR = 0, /* Success. */
REG_NOMATCH = 1, /* Didn't find a match (for regexec). */
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
REG_BADPAT = 2, /* Invalid pattern. */
REG_ECOLLATE = 3, /* Undefined collating element. */
REG_ECTYPE = 4, /* Invalid character class name. */
REG_EESCAPE = 5, /* Trailing backslash. */
REG_ESUBREG = 6, /* Invalid back reference. */
REG_EBRACK = 7, /* Unmatched left bracket. */
REG_EPAREN = 8, /* Parenthesis imbalance. */
REG_EBRACE = 9, /* Unmatched \{. */
REG_BADBR = 10, /* Invalid contents of \{\}. */
REG_ERANGE = 11, /* Invalid range end. */
REG_ESPACE = 12, /* Ran out of memory. */
REG_BADRPT = 13, /* No preceding re for repetition op. */
REG_EEND = 14, /* unexpected end of expression */
REG_ESIZE = 15, /* expression too big */
REG_ERPAREN = 16, /* unmatched right parenthesis */
REG_EMPTY = 17, /* empty expression */
REG_E_MEMORY = REG_ESIZE, /* out of memory */
REG_E_UNKNOWN = 18 /* unknown error */
} reg_errcode_t;
enum match_flags
{
match_default = 0,
match_not_bol = 1, // first is not start of line
match_not_eol = match_not_bol << 1, // last is not end of line
match_not_bob = match_not_eol << 1, // first is not start of buffer
match_not_eob = match_not_bob << 1, // last is not end of buffer
match_not_bow = match_not_eob << 1, // first is not start of word
match_not_eow = match_not_bow << 1, // last is not end of word
match_not_dot_newline = match_not_eow << 1, // \n is not matched by '.'
match_not_dot_null = match_not_dot_newline << 1, // '\0' is not matched by '.'
match_prev_avail = match_not_dot_null << 1, // *--first is a valid expression
match_init = match_prev_avail << 1, // internal use
match_any = match_init << 1, // don't care what we match
match_not_null = match_any << 1, // string can't be null
match_continuous = match_not_null << 1, // each grep match must continue from
// uninterupted from the previous one
match_partial = match_continuous << 1, // find partial matches
match_stop = match_partial << 1, // stop after first match (grep)
match_all = match_stop << 1, // must find the whole of input even if match_any is set
match_max = match_all
};
typedef unsigned long match_flag_type;
#ifdef __cplusplus
} // extern "C"
} // namespace
#endif
#ifdef __BORLANDC__
#if __BORLANDC__ > 0x520
#pragma option pop
#endif
#endif
//
// C++ high level wrapper goes here:
//
#if defined(__cplusplus)
#include <string>
#include <vector>
namespace boost{
#ifdef __BORLANDC__
#if __BORLANDC__ == 0x530
#pragma option push -a4 -b
#elif __BORLANDC__ > 0x530
#pragma option push -a8 -b
#endif
#endif
class RegEx;
namespace re_detail{
class RegExData;
struct pred1;
struct pred2;
struct pred3;
struct pred4;
} // namespace re_detail
#if defined(BOOST_MSVC) || defined(__BORLANDC__)
typedef bool (__cdecl *GrepCallback)(const RegEx& expression);
typedef bool (__cdecl *GrepFileCallback)(const char* file, const RegEx& expression);
typedef bool (__cdecl *FindFilesCallback)(const char* file);
#else
typedef bool (*GrepCallback)(const RegEx& expression);
typedef bool (*GrepFileCallback)(const char* file, const RegEx& expression);
typedef bool (*FindFilesCallback)(const char* file);
#endif
class BOOST_REGEX_DECL RegEx
{
private:
re_detail::RegExData* pdata;
public:
RegEx();
RegEx(const RegEx& o);
~RegEx();
explicit RegEx(const char* c, bool icase = false);
explicit RegEx(const std::string& s, bool icase = false);
RegEx& operator=(const RegEx& o);
RegEx& operator=(const char* p);
RegEx& operator=(const std::string& s){ return this->operator=(s.c_str()); }
unsigned int SetExpression(const char* p, bool icase = false);
unsigned int SetExpression(const std::string& s, bool icase = false){ return SetExpression(s.c_str(), icase); }
std::string Expression()const;
unsigned int error_code()const;
//
// now matching operators:
//
bool Match(const char* p, match_flag_type flags = match_default);
bool Match(const std::string& s, match_flag_type flags = match_default) { return Match(s.c_str(), flags); }
bool Search(const char* p, match_flag_type flags = match_default);
bool Search(const std::string& s, match_flag_type flags = match_default) { return Search(s.c_str(), flags); }
unsigned int Grep(GrepCallback cb, const char* p, match_flag_type flags = match_default);
unsigned int Grep(GrepCallback cb, const std::string& s, match_flag_type flags = match_default) { return Grep(cb, s.c_str(), flags); }
unsigned int Grep(std::vector<std::string>& v, const char* p, match_flag_type flags = match_default);
unsigned int Grep(std::vector<std::string>& v, const std::string& s, match_flag_type flags = match_default) { return Grep(v, s.c_str(), flags); }
unsigned int Grep(std::vector<std::size_t>& v, const char* p, match_flag_type flags = match_default);
unsigned int Grep(std::vector<std::size_t>& v, const std::string& s, match_flag_type flags = match_default) { return Grep(v, s.c_str(), flags); }
#ifndef BOOST_REGEX_NO_FILEITER
unsigned int GrepFiles(GrepFileCallback cb, const char* files, bool recurse = false, match_flag_type flags = match_default);
unsigned int GrepFiles(GrepFileCallback cb, const std::string& files, bool recurse = false, match_flag_type flags = match_default) { return GrepFiles(cb, files.c_str(), recurse, flags); }
unsigned int FindFiles(FindFilesCallback cb, const char* files, bool recurse = false, match_flag_type flags = match_default);
unsigned int FindFiles(FindFilesCallback cb, const std::string& files, bool recurse = false, match_flag_type flags = match_default) { return FindFiles(cb, files.c_str(), recurse, flags); }
#endif
std::string Merge(const std::string& in, const std::string& fmt,
bool copy = true, match_flag_type flags = match_default);
std::string Merge(const char* in, const char* fmt,
bool copy = true, match_flag_type flags = match_default);
std::size_t Split(std::vector<std::string>& v, std::string& s, match_flag_type flags = match_default, unsigned max_count = ~0);
//
// now operators for returning what matched in more detail:
//
std::size_t Position(int i = 0)const;
std::size_t Length(int i = 0)const;
bool Matched(int i = 0)const;
unsigned int Line()const;
unsigned int Marks()const;
std::string What(int i = 0)const;
std::string operator[](int i)const { return What(i); }
static const unsigned int npos;
friend struct re_detail::pred1;
friend struct re_detail::pred2;
friend struct re_detail::pred3;
friend struct re_detail::pred4;
};
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace boost
#endif
#endif // include guard

View File

@ -1,453 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE fileiter.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares various platform independent file and
* directory iterators, plus binary file input in
* the form of class map_file.
*/
#ifndef BOOST_RE_FILEITER_HPP_INCLUDED
#define BOOST_RE_FILEITER_HPP_INCLUDED
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#ifndef BOOST_REGEX_NO_FILEITER
#if (defined(__CYGWIN__) || defined(__CYGWIN32__)) && !defined(BOOST_REGEX_NO_W32)
#error "Sorry, can't mix <windows.h> with STL code and gcc compiler: if you ran configure, try again with configure --disable-ms-windows"
#define BOOST_REGEX_FI_WIN32_MAP
#define BOOST_REGEX_FI_POSIX_DIR
#elif (defined(__WIN32__) || defined(_WIN32) || defined(WIN32)) && !defined(BOOST_REGEX_NO_W32)
#define BOOST_REGEX_FI_WIN32_MAP
#define BOOST_REGEX_FI_WIN32_DIR
#else
#define BOOST_REGEX_FI_POSIX_MAP
#define BOOST_REGEX_FI_POSIX_DIR
#endif
#if defined(BOOST_REGEX_FI_WIN32_MAP)||defined(BOOST_REGEX_FI_WIN32_DIR)
#include <windows.h>
#endif
#if defined(BOOST_REGEX_FI_WIN32_DIR)
namespace boost{
namespace re_detail{
typedef WIN32_FIND_DATAA _fi_find_data;
typedef HANDLE _fi_find_handle;
} // namespace re_detail
} // namespace boost
#define _fi_invalid_handle INVALID_HANDLE_VALUE
#define _fi_dir FILE_ATTRIBUTE_DIRECTORY
#elif defined(BOOST_REGEX_FI_POSIX_DIR)
#include <cstdio>
#include <cctype>
#include <iterator>
#include <list>
#include <cassert>
#include <dirent.h>
#if defined(__SUNPRO_CC)
using std::list;
#endif
#ifndef MAX_PATH
#define MAX_PATH 256
#endif
namespace boost{
namespace re_detail{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
struct _fi_find_data
{
unsigned dwFileAttributes;
char cFileName[MAX_PATH];
};
struct _fi_priv_data;
typedef _fi_priv_data* _fi_find_handle;
#define _fi_invalid_handle 0
#define _fi_dir 1
_fi_find_handle _fi_FindFirstFile(const char* lpFileName, _fi_find_data* lpFindFileData);
bool _fi_FindNextFile(_fi_find_handle hFindFile, _fi_find_data* lpFindFileData);
bool _fi_FindClose(_fi_find_handle hFindFile);
#ifdef __BORLANDC__
#if __BORLANDC__ > 0x520
#pragma option pop
#endif
#endif
} // namespace re_detail
} // namespace boost
#ifdef FindFirstFile
#undef FindFirstFile
#endif
#ifdef FindNextFile
#undef FindNextFile
#endif
#ifdef FindClose
#undef FindClose
#endif
#define FindFirstFileA _fi_FindFirstFile
#define FindNextFileA _fi_FindNextFile
#define FindClose _fi_FindClose
#endif
namespace boost{
namespace re_detail{
#ifdef __BORLANDC__
#if __BORLANDC__ == 0x530
#pragma option push -a4 -b
#elif __BORLANDC__ > 0x530
#pragma option push -a8 -b
#endif
#endif
#ifdef BOOST_REGEX_FI_WIN32_MAP // win32 mapfile
class BOOST_REGEX_DECL mapfile
{
HANDLE hfile;
HANDLE hmap;
const char* _first;
const char* _last;
public:
typedef const char* iterator;
mapfile(){ hfile = hmap = 0; _first = _last = 0; }
mapfile(const char* file){ hfile = hmap = 0; _first = _last = 0; open(file); }
~mapfile(){ close(); }
void open(const char* file);
void close();
const char* begin(){ return _first; }
const char* end(){ return _last; }
size_t size(){ return _last - _first; }
bool valid(){ return (hfile != 0) && (hfile != INVALID_HANDLE_VALUE); }
};
#else
class BOOST_REGEX_DECL mapfile_iterator;
class BOOST_REGEX_DECL mapfile
{
typedef char* pointer;
std::FILE* hfile;
long int _size;
pointer* _first;
pointer* _last;
mutable std::list<pointer*> condemed;
enum sizes
{
buf_size = 4096
};
void lock(pointer* node)const;
void unlock(pointer* node)const;
public:
typedef mapfile_iterator iterator;
mapfile(){ hfile = 0; _size = 0; _first = _last = 0; }
mapfile(const char* file){ hfile = 0; _size = 0; _first = _last = 0; open(file); }
~mapfile(){ close(); }
void open(const char* file);
void close();
iterator begin()const;
iterator end()const;
unsigned long size()const{ return _size; }
bool valid()const{ return hfile != 0; }
friend class mapfile_iterator;
};
class BOOST_REGEX_DECL mapfile_iterator
#if !defined(BOOST_NO_STD_ITERATOR) || defined(BOOST_MSVC_STD_ITERATOR)
: public std::iterator<std::random_access_iterator_tag, char>
#endif
{
typedef mapfile::pointer internal_pointer;
internal_pointer* node;
const mapfile* file;
unsigned long offset;
long position()const
{
return file ? ((node - file->_first) * mapfile::buf_size + offset) : 0;
}
void position(long pos)
{
if(file)
{
node = file->_first + (pos / mapfile::buf_size);
offset = pos % mapfile::buf_size;
}
}
public:
typedef std::ptrdiff_t difference_type;
typedef char value_type;
typedef const char* pointer;
typedef const char& reference;
typedef std::random_access_iterator_tag iterator_category;
mapfile_iterator() { node = 0; file = 0; offset = 0; }
mapfile_iterator(const mapfile* f, long position)
{
file = f;
node = f->_first + position / mapfile::buf_size;
offset = position % mapfile::buf_size;
if(file)
file->lock(node);
}
mapfile_iterator(const mapfile_iterator& i)
{
file = i.file;
node = i.node;
offset = i.offset;
if(file)
file->lock(node);
}
~mapfile_iterator()
{
if(file && node)
file->unlock(node);
}
mapfile_iterator& operator = (const mapfile_iterator& i);
char operator* ()const
{
assert(node >= file->_first);
assert(node < file->_last);
return file ? *(*node + sizeof(int) + offset) : char(0);
}
char operator[] (long off)const
{
mapfile_iterator tmp(*this);
tmp += off;
return *tmp;
}
mapfile_iterator& operator++ ();
mapfile_iterator operator++ (int);
mapfile_iterator& operator-- ();
mapfile_iterator operator-- (int);
mapfile_iterator& operator += (long off)
{
position(position() + off);
return *this;
}
mapfile_iterator& operator -= (long off)
{
position(position() - off);
return *this;
}
friend inline bool operator==(const mapfile_iterator& i, const mapfile_iterator& j)
{
return (i.file == j.file) && (i.node == j.node) && (i.offset == j.offset);
}
friend inline bool operator!=(const mapfile_iterator& i, const mapfile_iterator& j)
{
return !(i == j);
}
friend inline bool operator<(const mapfile_iterator& i, const mapfile_iterator& j)
{
return i.position() < j.position();
}
friend inline bool operator>(const mapfile_iterator& i, const mapfile_iterator& j)
{
return i.position() > j.position();
}
friend inline bool operator<=(const mapfile_iterator& i, const mapfile_iterator& j)
{
return i.position() <= j.position();
}
friend inline bool operator>=(const mapfile_iterator& i, const mapfile_iterator& j)
{
return i.position() >= j.position();
}
friend mapfile_iterator operator + (const mapfile_iterator& i, long off);
friend mapfile_iterator operator + (long off, const mapfile_iterator& i)
{
mapfile_iterator tmp(i);
return tmp += off;
}
friend mapfile_iterator operator - (const mapfile_iterator& i, long off);
friend inline long operator - (const mapfile_iterator& i, const mapfile_iterator& j)
{
return i.position() - j.position();
}
};
#endif
// _fi_sep determines the directory separator, either '\\' or '/'
BOOST_REGEX_DECL extern const char* _fi_sep;
struct file_iterator_ref
{
_fi_find_handle hf;
_fi_find_data _data;
long count;
};
class BOOST_REGEX_DECL file_iterator
{
char* _root;
char* _path;
char* ptr;
file_iterator_ref* ref;
public:
typedef std::ptrdiff_t difference_type;
typedef const char* value_type;
typedef const char** pointer;
typedef const char*& reference;
typedef std::input_iterator_tag iterator_category;
file_iterator();
file_iterator(const char* wild);
~file_iterator();
file_iterator(const file_iterator&);
file_iterator& operator=(const file_iterator&);
const char* root()const { return _root; }
const char* path()const { return _path; }
const char* name()const { return ptr; }
_fi_find_data* data() { return &(ref->_data); }
void next();
file_iterator& operator++() { next(); return *this; }
file_iterator operator++(int);
const char* operator*() { return path(); }
friend inline bool operator == (const file_iterator& f1, const file_iterator& f2)
{
return ((f1.ref->hf == _fi_invalid_handle) && (f2.ref->hf == _fi_invalid_handle));
}
friend inline bool operator != (const file_iterator& f1, const file_iterator& f2)
{
return !(f1 == f2);
}
};
// dwa 9/13/00 - suppress unused parameter warning
inline bool operator < (const file_iterator&, const file_iterator&)
{
return false;
}
class BOOST_REGEX_DECL directory_iterator
{
char* _root;
char* _path;
char* ptr;
file_iterator_ref* ref;
public:
typedef std::ptrdiff_t difference_type;
typedef const char* value_type;
typedef const char** pointer;
typedef const char*& reference;
typedef std::input_iterator_tag iterator_category;
directory_iterator();
directory_iterator(const char* wild);
~directory_iterator();
directory_iterator(const directory_iterator& other);
directory_iterator& operator=(const directory_iterator& other);
const char* root()const { return _root; }
const char* path()const { return _path; }
const char* name()const { return ptr; }
_fi_find_data* data() { return &(ref->_data); }
void next();
directory_iterator& operator++() { next(); return *this; }
directory_iterator operator++(int);
const char* operator*() { return path(); }
static const char* separator() { return _fi_sep; }
friend inline bool operator == (const directory_iterator& f1, const directory_iterator& f2)
{
return ((f1.ref->hf == _fi_invalid_handle) && (f2.ref->hf == _fi_invalid_handle));
}
friend inline bool operator != (const directory_iterator& f1, const directory_iterator& f2)
{
return !(f1 == f2);
}
};
inline bool operator < (const directory_iterator&, const directory_iterator&)
{
return false;
}
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace re_detail
using boost::re_detail::directory_iterator;
using boost::re_detail::file_iterator;
using boost::re_detail::mapfile;
} // namespace boost
#endif // BOOST_REGEX_NO_FILEITER
#endif // BOOST_RE_FILEITER_HPP

View File

@ -1,165 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE instances.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Defines those template instances that are placed in the
* library rather than in the users object files.
*/
//
// note no include guard, we may include this multiple times:
//
#ifndef BOOST_REGEX_NO_EXTERNAL_TEMPLATES
namespace boost{
//
// this header can be included multiple times, each time with
// a different character type, BOOST_REGEX_CHAR_T must be defined
// first:
//
#ifndef BOOST_REGEX_CHAR_T
# error "BOOST_REGEX_CHAR_T not defined"
#endif
//
// what follows is compiler specific:
//
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
# ifndef BOOST_REGEX_INSTANTIATE
# pragma option push -Jgx
# endif
template class BOOST_REGEX_DECL reg_expression< BOOST_REGEX_CHAR_T >;
template class BOOST_REGEX_DECL re_detail::match_results_base<BOOST_REGEX_CHAR_T const*>;
template class BOOST_REGEX_DECL re_detail::match_results_base<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator>;
template class BOOST_REGEX_DECL match_results<BOOST_REGEX_CHAR_T const*>;
template class BOOST_REGEX_DECL match_results<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator>;
# ifndef BOOST_REGEX_INSTANTIATE
# pragma option pop
# endif
#pragma option pop
#elif defined(BOOST_MSVC)
# ifndef BOOST_REGEX_INSTANTIATE
# define template extern template
# endif
#pragma warning(push)
#pragma warning(disable : 4251 4231 4660)
//template class BOOST_REGEX_DECL regex_traits< BOOST_REGEX_CHAR_T >;
template class BOOST_REGEX_DECL reg_expression< BOOST_REGEX_CHAR_T >;
template class BOOST_REGEX_DECL re_detail::match_results_base<BOOST_REGEX_CHAR_T const*, BOOST_DEFAULT_ALLOCATOR(re_detail::def_alloc_param_traits<BOOST_REGEX_CHAR_T const*>::type) >;
template class BOOST_REGEX_DECL re_detail::match_results_base<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator, BOOST_DEFAULT_ALLOCATOR(re_detail::def_alloc_param_traits<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator>::type) >;
template class BOOST_REGEX_DECL match_results<BOOST_REGEX_CHAR_T const*, BOOST_DEFAULT_ALLOCATOR(re_detail::def_alloc_param_traits<BOOST_REGEX_CHAR_T const*>::type) >;
template class BOOST_REGEX_DECL match_results<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator, BOOST_DEFAULT_ALLOCATOR(re_detail::def_alloc_param_traits<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator>::type) >;
#pragma warning(pop)
# ifdef template
# undef template
# endif
#elif !defined(BOOST_REGEX_HAS_DLL_RUNTIME)
//
// for each [member] function declare a full specialisation of that
// [member] function, then instantiate it in one translation unit.
// This is not guarenteed to work according to the standard, but in
// practice it should work for all compilers (unless they use a realy
// perverse name mangling convention). Unfortunately this approach
// does *not* work for Win32 style import/export, because that can
// alter the class layout.
//
# ifndef BOOST_REGEX_INSTANTIATE
# define template template<>
# endif
template reg_expression<BOOST_REGEX_CHAR_T>::reg_expression(const BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T)&);
template reg_expression<BOOST_REGEX_CHAR_T>::reg_expression(const BOOST_REGEX_CHAR_T* p, reg_expression<BOOST_REGEX_CHAR_T>::flag_type f, const BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T)& a);
template reg_expression<BOOST_REGEX_CHAR_T>::reg_expression(const BOOST_REGEX_CHAR_T* p, size_type len, reg_expression<BOOST_REGEX_CHAR_T>::flag_type f, const BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T)&);
template reg_expression<BOOST_REGEX_CHAR_T>::reg_expression(const reg_expression<BOOST_REGEX_CHAR_T>&);
template reg_expression<BOOST_REGEX_CHAR_T>::~reg_expression();
template reg_expression<BOOST_REGEX_CHAR_T>& BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::operator=(const reg_expression&);
template BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::get_allocator()const;
template bool BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::operator==(const reg_expression<BOOST_REGEX_CHAR_T>&)const;
template bool BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::operator<(const reg_expression<BOOST_REGEX_CHAR_T>&)const;
template BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::allocator()const;
template unsigned int BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::set_expression(const BOOST_REGEX_CHAR_T* p, const BOOST_REGEX_CHAR_T* end, reg_expression<BOOST_REGEX_CHAR_T>::flag_type f);
template void BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::compile_maps();
template void BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::compile_map(re_detail::re_syntax_base* node, unsigned char* _map, unsigned int* pnull, unsigned char mask, re_detail::re_syntax_base* terminal)const;
template bool BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::probe_start(re_detail::re_syntax_base* node, BOOST_REGEX_CHAR_T c, re_detail::re_syntax_base* terminal)const;
template bool BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::probe_start_null(re_detail::re_syntax_base* node, re_detail::re_syntax_base* terminal)const;
template void BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::fixup_apply(re_detail::re_syntax_base* b, unsigned cbraces);
template void BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::move_offsets(re_detail::re_syntax_base* j, unsigned size);
template re_detail::re_syntax_base* BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::compile_set(const BOOST_REGEX_CHAR_T*& first, const BOOST_REGEX_CHAR_T* last);
template re_detail::re_syntax_base* BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::compile_set_aux(re_detail::jstack<reg_expression<BOOST_REGEX_CHAR_T>::traits_string_type, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) >& singles, re_detail::jstack<reg_expression<BOOST_REGEX_CHAR_T>::traits_string_type, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T)>& ranges, re_detail::jstack<boost::uint_fast32_t, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) >& classes, re_detail::jstack<reg_expression<BOOST_REGEX_CHAR_T>::traits_string_type, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) >& equivalents, bool isnot, const re_detail::_narrow_type&);
template re_detail::re_syntax_base* BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::compile_set_aux(re_detail::jstack<reg_expression<BOOST_REGEX_CHAR_T>::traits_string_type, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) >& singles, re_detail::jstack<reg_expression<BOOST_REGEX_CHAR_T>::traits_string_type, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T)>& ranges, re_detail::jstack<boost::uint_fast32_t, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) >& classes, re_detail::jstack<reg_expression<BOOST_REGEX_CHAR_T>::traits_string_type, BOOST_DEFAULT_ALLOCATOR(BOOST_REGEX_CHAR_T) >& equivalents, bool isnot, const re_detail::_wide_type&);
template re_detail::re_syntax_base* BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::compile_set_simple(re_detail::re_syntax_base* dat, unsigned long cls, bool isnot);
template unsigned int BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::parse_inner_set(const BOOST_REGEX_CHAR_T*& first, const BOOST_REGEX_CHAR_T* last);
template re_detail::re_syntax_base* BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::add_simple(re_detail::re_syntax_base* dat, re_detail::syntax_element_type type, unsigned int size);
template re_detail::re_syntax_base* BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::add_literal(re_detail::re_syntax_base* dat, BOOST_REGEX_CHAR_T c);
template BOOST_REGEX_CHAR_T BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::parse_escape(const BOOST_REGEX_CHAR_T*& first, const BOOST_REGEX_CHAR_T* last);
template void BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::parse_range(const BOOST_REGEX_CHAR_T*& first, const BOOST_REGEX_CHAR_T* last, unsigned& min, unsigned& max);
template bool BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::skip_space(const BOOST_REGEX_CHAR_T*& first, const BOOST_REGEX_CHAR_T* last);
template unsigned int BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::probe_restart(re_detail::re_syntax_base* dat);
template unsigned int BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::fixup_leading_rep(re_detail::re_syntax_base* dat, re_detail::re_syntax_base* end);
template void BOOST_REGEX_CALL reg_expression<BOOST_REGEX_CHAR_T>::fail(unsigned int err);
namespace re_detail{
#define iterator const BOOST_REGEX_CHAR_T*
#define Allocator match_results_base<iterator>::alloc_type
#define size_type match_results_base<iterator>::size_type
template void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_first(iterator i);
template void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_first(iterator i, std::size_t pos);
template match_results_base<iterator, Allocator>::match_results_base(const Allocator& a);
template Allocator BOOST_REGEX_CALL match_results_base<iterator, Allocator>::allocator()const;
template void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::m_free();
template bool match_results_base<iterator, Allocator>::operator==(const match_results_base<iterator, Allocator>& that)const;
template void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_type n);
template void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::set_size(size_type n, iterator i, iterator j);
template void BOOST_REGEX_CALL match_results_base<iterator, Allocator>::cow();
#undef iterator
#undef Allocator
#undef size_type
} // namespace re_detail
# ifdef template
# undef template
# endif
#endif
} // namespace boost
#endif // BOOST_REGEX_NO_EXTERNAL_TEMPLATES

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,131 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_cstring.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: This is an internal header file, do not include directly.
* String support and helper functions, for regular
* expression library.
*/
#ifndef BOOST_REGEX_CSTRING_HPP
#define BOOST_REGEX_CSTRING_HPP
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#include <cstring>
namespace boost{
namespace re_detail{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
//
// start by defining some template function aliases for C API functions:
//
template <class charT>
std::size_t BOOST_REGEX_CALL re_strlen(const charT *s)
{
std::size_t len = 0;
while(*s)
{
++s;
++len;
}
return len;
}
inline std::size_t BOOST_REGEX_CALL re_strlen(const char *s)
{
return std::strlen(s);
}
#ifndef BOOST_NO_WREGEX
inline std::size_t BOOST_REGEX_CALL re_strlen(const wchar_t *s)
{
return std::wcslen(s);
}
#endif
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL void BOOST_REGEX_CALL re_transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
#endif
BOOST_REGEX_DECL void BOOST_REGEX_CALL re_transform(std::string& out, const std::string& in);
template <class charT>
void BOOST_REGEX_CALL re_trunc_primary(std::basic_string<charT>& s)
{
for(unsigned int i = 0; i < s.size(); ++i)
{
if(s[i] <= 1)
{
s.erase(i);
break;
}
}
}
inline char* BOOST_REGEX_CALL re_strcpy(char *s1, const char *s2)
{
#if defined(__BORLANDC__) && defined(strcpy)
return ::strcpy(s1, s2);
#else
return std::strcpy(s1, s2);
#endif
}
#ifndef BOOST_NO_WREGEX
inline wchar_t* BOOST_REGEX_CALL re_strcpy(wchar_t *s1, const wchar_t *s2)
{
return std::wcscpy(s1, s2);
}
#endif
template <class charT>
charT* BOOST_REGEX_CALL re_strdup(const charT* p)
{
charT* buf = new charT[re_strlen(p) + 1];
re_strcpy(buf, p);
return buf;
}
template <class charT>
inline void BOOST_REGEX_CALL re_strfree(charT* p)
{
delete[] p;
}
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace re_detail
} // namespace boost
#endif // BOOST_REGEX_CSTRING_HPP

View File

@ -1,576 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_format.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Provides formatting output routines for search and replace
* operations. Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
#ifndef BOOST_REGEX_FORMAT_HPP
#define BOOST_REGEX_FORMAT_HPP
namespace boost{
enum format_flags_t{
format_all = 0, // enable all extentions to sytax
format_sed = match_max << 1, // sed style replacement.
format_perl = format_sed << 1, // perl style replacement.
format_no_copy = format_perl << 1, // don't copy non-matching segments.
format_first_only = format_no_copy << 1, // Only replace first occurance.
format_is_if = format_first_only << 1 // internal use only.
};
namespace re_detail{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc -w-8037
#endif
template <class O, class I>
O BOOST_REGEX_CALL re_copy_out(O out, I first, I last)
{
while(first != last)
{
*out = *first;
++out;
++first;
}
return out;
}
template <class charT, class traits_type>
void BOOST_REGEX_CALL re_skip_format(const charT*& fmt, const traits_type& traits_inst)
{
// dwa 9/13/00 - suppress incorrect unused parameter warning for MSVC
(void)traits_inst;
typedef typename traits_type::size_type traits_size_type;
typedef typename traits_type::uchar_type traits_uchar_type;
typedef typename traits_type::string_type traits_string_type;
unsigned int parens = 0;
unsigned int c;
while(*fmt)
{
c = traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*fmt));
if((c == traits_type::syntax_colon) && (parens == 0))
{
++fmt;
return;
}
else if(c == traits_type::syntax_close_bracket)
{
if(parens == 0)
{
++fmt;
return;
}
--parens;
}
else if(c == traits_type::syntax_open_bracket)
++parens;
else if(c == traits_type::syntax_slash)
{
++fmt;
if(*fmt == 0)
return;
}
++fmt;
}
}
#ifdef BOOST_NO_STD_OUTPUT_ITERATOR_ASSIGN
//
// ugly hack for buggy output iterators
template <class T>
inline void oi_assign(T* p, T v)
{
::boost::re_detail::pointer_destroy(p);
pointer_construct(p, v);
}
#else
template <class T>
inline void oi_assign(T* p, T v)
{
//
// if you get a compile time error in here then you either
// need to rewrite your output iterator to make it assignable
// (as is required by the standard), or define
// BOOST_NO_STD_OUTPUT_ITERATOR_ASSIGN to use the ugly hack above
*p = v;
}
#endif
#if defined(BOOST_REGEX_NO_TEMPLATE_SWITCH_MERGE)
//
// Ugly ugly hack,
// template don't merge if they contain switch statements so declare these
// templates in unnamed namespace (ie with internal linkage), each translation
// unit then gets its own local copy, it works seemlessly but bloats the app.
namespace{
#endif
//
// algorithm reg_format:
// takes the result of a match and a format string
// and merges them to produce a new string which
// is sent to an OutputIterator,
// _reg_format_aux does the actual work:
//
template <class OutputIterator, class Iterator, class Allocator, class charT, class traits_type>
OutputIterator BOOST_REGEX_CALL _reg_format_aux(OutputIterator out,
const match_results<Iterator, Allocator>& m,
const charT*& fmt,
unsigned flags, const traits_type& traits_inst)
{
const charT* fmt_end = fmt;
while(*fmt_end) ++ fmt_end;
typedef typename traits_type::size_type traits_size_type;
typedef typename traits_type::uchar_type traits_uchar_type;
typedef typename traits_type::string_type traits_string_type;
while(*fmt)
{
switch(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*fmt)))
{
case traits_type::syntax_dollar:
if(flags & format_sed)
{
// no perl style replacement,
// $ is an ordinary character:
goto default_opt;
}
++fmt;
if(*fmt == 0) // oops trailing $
{
--fmt;
*out = *fmt;
++out;
return out;
}
switch(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*fmt)))
{
case traits_type::syntax_start_buffer:
oi_assign(&out, re_copy_out(out, Iterator(m[-1].first), Iterator(m[-1].second)));
++fmt;
continue;
case traits_type::syntax_end_buffer:
oi_assign(&out, re_copy_out(out, Iterator(m[-2].first), Iterator(m[-2].second)));
++fmt;
continue;
case traits_type::syntax_digit:
{
expand_sub:
unsigned int index = traits_inst.toi(fmt, fmt_end, 10);
oi_assign(&out, re_copy_out(out, Iterator(m[index].first), Iterator(m[index].second)));
continue;
}
}
// anything else:
if(*fmt == '&')
{
oi_assign(&out, re_copy_out(out, Iterator(m[0].first), Iterator(m[0].second)));
++fmt;
}
else
{
// probably an error, treat as a literal '$'
--fmt;
*out = *fmt;
++out;
++fmt;
}
continue;
case traits_type::syntax_slash:
{
// escape sequence:
++fmt;
charT c(*fmt);
if(*fmt == 0)
{
--fmt;
*out = *fmt;
++out;
++fmt;
return out;
}
switch(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*fmt)))
{
case traits_type::syntax_a:
c = '\a';
++fmt;
break;
case traits_type::syntax_f:
c = '\f';
++fmt;
break;
case traits_type::syntax_n:
c = '\n';
++fmt;
break;
case traits_type::syntax_r:
c = '\r';
++fmt;
break;
case traits_type::syntax_t:
c = '\t';
++fmt;
break;
case traits_type::syntax_v:
c = '\v';
++fmt;
break;
case traits_type::syntax_x:
++fmt;
if(fmt == fmt_end)
{
*out = *--fmt;
++out;
return out;
}
// maybe have \x{ddd}
if(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*fmt)) == traits_type::syntax_open_brace)
{
++fmt;
if(fmt == fmt_end)
{
fmt -= 2;
*out = *fmt;
++out;
++fmt;
continue;
}
if(traits_inst.is_class(*fmt, traits_type::char_class_xdigit) == false)
{
fmt -= 2;
*out = *fmt;
++out;
++fmt;
continue;
}
c = (charT)traits_inst.toi(fmt, fmt_end, -16);
if(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*fmt)) != traits_type::syntax_close_brace)
{
while(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*fmt)) != traits_type::syntax_slash)
--fmt;
++fmt;
*out = *fmt;
++out;
++fmt;
continue;
}
++fmt;
break;
}
else
{
if(traits_inst.is_class(*fmt, traits_type::char_class_xdigit) == false)
{
--fmt;
*out = *fmt;
++out;
++fmt;
continue;
}
c = (charT)traits_inst.toi(fmt, fmt_end, -16);
}
break;
case traits_type::syntax_c:
++fmt;
if(fmt == fmt_end)
{
--fmt;
*out = *fmt;
++out;
return out;
}
if(((typename traits_type::uchar_type)(*fmt) < (typename traits_type::uchar_type)'@')
|| ((typename traits_type::uchar_type)(*fmt) > (typename traits_type::uchar_type)127) )
{
--fmt;
*out = *fmt;
++out;
++fmt;
break;
}
c = (charT)((typename traits_type::uchar_type)(*fmt) - (typename traits_type::uchar_type)'@');
++fmt;
break;
case traits_type::syntax_e:
c = (charT)27;
++fmt;
break;
case traits_type::syntax_digit:
if(flags & format_sed)
goto expand_sub;
else
c = (charT)traits_inst.toi(fmt, fmt_end, -8);
break;
default:
//c = *fmt;
++fmt;
}
*out = c;
++out;
continue;
}
case traits_type::syntax_open_bracket:
if(flags & (format_sed|format_perl))
{
*out = *fmt;
++out;
++fmt;
continue;
}
else
{
++fmt; // recurse
oi_assign(&out, _reg_format_aux(out, m, fmt, flags, traits_inst));
continue;
}
case traits_type::syntax_close_bracket:
if(flags & (format_sed|format_perl))
{
*out = *fmt;
++out;
++fmt;
continue;
}
else
{
++fmt; // return from recursion
return out;
}
case traits_type::syntax_colon:
if(flags & format_is_if)
{
++fmt;
return out;
}
*out = *fmt;
++out;
++fmt;
continue;
case traits_type::syntax_question:
{
if(flags & (format_sed|format_perl))
{
*out = *fmt;
++out;
++fmt;
continue;
}
else
{
++fmt;
if(*fmt == 0)
{
--fmt;
*out = *fmt;
++out;
++fmt;
return out;
}
unsigned int id = traits_inst.toi(fmt, fmt_end, 10);
if(m[id].matched)
{
oi_assign(&out, _reg_format_aux(out, m, fmt, flags | format_is_if, traits_inst));
if(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*(fmt-1))) == traits_type::syntax_colon)
re_skip_format(fmt, traits_inst);
}
else
{
re_skip_format(fmt, traits_inst);
if(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*(fmt-1))) == traits_type::syntax_colon)
oi_assign(&out, _reg_format_aux(out, m, fmt, flags | format_is_if, traits_inst));
}
return out;
}
}
default:
default_opt:
if((flags & format_sed) && (*fmt == '&'))
{
oi_assign(&out, re_copy_out(out, Iterator(m[0].first), Iterator(m[0].second)));
++fmt;
continue;
}
*out = *fmt;
++out;
++fmt;
}
}
return out;
}
#if defined(BOOST_REGEX_NO_TEMPLATE_SWITCH_MERGE)
} // namespace
#endif
template <class S>
class string_out_iterator
{
S* out;
public:
string_out_iterator(S& s) : out(&s) {}
string_out_iterator& operator++() { return *this; }
string_out_iterator& operator++(int) { return *this; }
string_out_iterator& operator*() { return *this; }
string_out_iterator& operator=(typename S::value_type v)
{
out->append(1, v);
return *this;
}
};
template <class OutputIterator, class Iterator, class charT, class Allocator, class traits_type>
class merge_out_predicate
{
OutputIterator* out;
Iterator* last;
const charT* fmt;
unsigned flags;
const traits_type* pt;
public:
merge_out_predicate(OutputIterator& o, Iterator& pi, const charT* f, unsigned format_flags, const traits_type& p)
: out(&o), last(&pi), fmt(f), flags(format_flags), pt(&p){}
~merge_out_predicate() {}
bool BOOST_REGEX_CALL operator()(const boost::match_results<Iterator, Allocator>& m)
{
const charT* f = fmt;
if(0 == (flags & format_no_copy))
oi_assign(out, re_copy_out(*out, Iterator(m[-1].first), Iterator(m[-1].second)));
oi_assign(out, _reg_format_aux(*out, m, f, flags, *pt));
*last = m[-2].first;
return flags & format_first_only ? false : true;
}
};
} // namespace re_detail
template <class OutputIterator, class Iterator, class Allocator, class charT>
OutputIterator regex_format(OutputIterator out,
const match_results<Iterator, Allocator>& m,
const charT* fmt,
unsigned flags = 0
)
{
regex_traits<charT> t;
return re_detail::_reg_format_aux(out, m, fmt, flags, t);
}
template <class OutputIterator, class Iterator, class Allocator, class charT>
OutputIterator regex_format(OutputIterator out,
const match_results<Iterator, Allocator>& m,
const std::basic_string<charT>& fmt,
unsigned flags = 0
)
{
regex_traits<charT> t;
const charT* start = fmt.c_str();
return re_detail::_reg_format_aux(out, m, start, flags, t);
}
template <class Iterator, class Allocator, class charT>
std::basic_string<charT> regex_format(const match_results<Iterator, Allocator>& m, const charT* fmt, unsigned flags = 0)
{
std::basic_string<charT> result;
re_detail::string_out_iterator<std::basic_string<charT> > i(result);
regex_format(i, m, fmt, flags);
return result;
}
template <class Iterator, class Allocator, class charT>
std::basic_string<charT> regex_format(const match_results<Iterator, Allocator>& m, const std::basic_string<charT>& fmt, unsigned flags = 0)
{
std::basic_string<charT> result;
re_detail::string_out_iterator<std::basic_string<charT> > i(result);
regex_format(i, m, fmt.c_str(), flags);
return result;
}
template <class OutputIterator, class Iterator, class traits, class Allocator, class charT>
OutputIterator regex_merge(OutputIterator out,
Iterator first,
Iterator last,
const reg_expression<charT, traits, Allocator>& e,
const charT* fmt,
unsigned int flags = match_default)
{
Iterator l = first;
re_detail::merge_out_predicate<OutputIterator, Iterator, charT, Allocator, traits> oi(out, l, fmt, flags, e.get_traits());
regex_grep(oi, first, last, e, flags);
return (flags & format_no_copy) ? out : re_detail::re_copy_out(out, l, last);
}
template <class OutputIterator, class Iterator, class traits, class Allocator, class charT>
inline OutputIterator regex_merge(OutputIterator out,
Iterator first,
Iterator last,
const reg_expression<charT, traits, Allocator>& e,
const std::basic_string<charT>& fmt,
unsigned int flags = match_default)
{
return regex_merge(out, first, last, e, fmt.c_str(), flags);
}
template <class traits, class Allocator, class charT>
std::basic_string<charT> regex_merge(const std::basic_string<charT>& s,
const reg_expression<charT, traits, Allocator>& e,
const charT* fmt,
unsigned int flags = match_default)
{
std::basic_string<charT> result;
re_detail::string_out_iterator<std::basic_string<charT> > i(result);
regex_merge(i, s.begin(), s.end(), e, fmt, flags);
return result;
}
template <class traits, class Allocator, class charT>
std::basic_string<charT> regex_merge(const std::basic_string<charT>& s,
const reg_expression<charT, traits, Allocator>& e,
const std::basic_string<charT>& fmt,
unsigned int flags = match_default)
{
std::basic_string<charT> result;
re_detail::string_out_iterator<std::basic_string<charT> > i(result);
regex_merge(i, s.begin(), s.end(), e, fmt.c_str(), flags);
return result;
}
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace boost
#endif // BOOST_REGEX_FORMAT_HPP

View File

@ -1,67 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_fwd.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Forward declares boost::reg_expression<> and
* associated typedefs.
*/
#ifndef BOOST_REGEX_FWD_HPP_INCLUDED
#define BOOST_REGEX_FWD_HPP_INCLUDED
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/config.hpp>
#endif
#include <boost/regex/config/allocator.hpp>
//
// define BOOST_REGEX_NO_FWD if this
// header doesn't work!
//
#ifdef BOOST_REGEX_NO_FWD
# ifndef BOOST_RE_REGEX_HPP
# include <boost/regex.hpp>
# endif
#else
//
// If there isn't good enough wide character support then there will
// be no wide character regular expressions:
//
#if (defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_CWCTYPE) || defined(BOOST_NO_STD_WSTRING)) && !defined(BOOST_NO_WREGEX)
# define BOOST_NO_WREGEX
#endif
namespace boost{
template <class charT>
class regex_traits;
template <class charT, class traits = regex_traits<charT>, class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
class reg_expression;
typedef reg_expression<char, regex_traits<char>, BOOST_DEFAULT_ALLOCATOR(char) > regex;
#ifndef BOOST_NO_WREGEX
typedef reg_expression<wchar_t, regex_traits<wchar_t>, BOOST_DEFAULT_ALLOCATOR(wchar_t) > wregex;
#endif
} // namespace boost
#endif // BOOST_REGEX_NO_FWD
#endif

View File

@ -1,108 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_kmp.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Provides Knuth Morris Pratt search operations.
* Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
#ifndef BOOST_REGEX_KMP_HPP
#define BOOST_REGEX_KMP_HPP
#ifdef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
namespace boost{
namespace re_detail{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
template <class charT>
struct kmp_info
{
unsigned int size;
unsigned int len;
const charT* pstr;
int kmp_next[1];
};
template <class charT, class Allocator>
void kmp_free(kmp_info<charT>* pinfo, const Allocator& a)
{
typedef typename boost::detail::rebind_allocator<char, Allocator>::type atype;
atype(a).deallocate(reinterpret_cast<char*>(pinfo), pinfo->size);
}
template <class iterator, class charT, class Trans, class Allocator>
kmp_info<charT>* kmp_compile(iterator first, iterator last, charT, Trans translate, const Allocator& a)
{
typedef typename boost::detail::rebind_allocator<char, Allocator>::type atype;
int i, j, m;
i = 0;
m = static_cast<int>(boost::re_detail::distance(first, last));
++m;
unsigned int size = sizeof(kmp_info<charT>) + sizeof(int)*m + sizeof(charT)*m;
--m;
//
// allocate struct and fill it in:
//
kmp_info<charT>* pinfo = reinterpret_cast<kmp_info<charT>*>(atype(a).allocate(size));
BOOST_REGEX_NOEH_ASSERT(pinfo)
pinfo->size = size;
pinfo->len = m;
charT* p = reinterpret_cast<charT*>(reinterpret_cast<char*>(pinfo) + sizeof(kmp_info<charT>) + sizeof(int)*(m+1));
pinfo->pstr = p;
while(first != last)
{
*p = translate(*first);
++first;
++p;
}
*p = 0;
//
// finally do regular kmp compile:
//
j = pinfo->kmp_next[0] = -1;
while (i < m)
{
while ((j > -1) && (pinfo->pstr[i] != pinfo->pstr[j]))
j = pinfo->kmp_next[j];
++i;
++j;
if (pinfo->pstr[i] == pinfo->pstr[j])
pinfo->kmp_next[i] = pinfo->kmp_next[j];
else
pinfo->kmp_next[i] = j;
}
return pinfo;
}
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namepsace re_detail
} // namespace boost
#endif // BOOST_REGEX_KMP_HPP

View File

@ -1,181 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_libary_include.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Automatic library inclusion for Borland/Microsoft compilers.
* Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
/*************************************************************************
Libraries for Borland and Microsoft compilers are automatically
selected here, the name of the lib is selected according to the following
formula:
BOOST_LIB_NAME
+ "_"
+ BOOST_LIB_TOOLSET
+ "_"
+ BOOST_LIB_THREAD_OPT
+ BOOST_LIB_RT_OPT
+ BOOST_LIB_LINK_OPT
+ BOOST_LIB_DEBUG_OPT
These are defined as:
BOOST_LIB_NAME: The base name of the lib (boost_regex).
BOOST_LIB_TOOLSET: The compiler toolset name (vc6, vc7, bcb5 etc).
BOOST_LIB_THREAD_OPT: "s" for single thread builds,
"m" for multithread builds.
BOOST_LIB_RT_OPT: "s" for static runtime,
"d" for dynamic runtime.
BOOST_LIB_LINK_OPT: "s" for static link,
"i" for dynamic link.
BOOST_LIB_DEBUG_OPT: nothing for release builds,
"d" for debug builds,
"dd" for debug-diagnostic builds (_STLP_DEBUG).
***************************************************************************/
#if !defined(BOOST_REGEX_LIBRARY_INCLUDE_HPP) && !defined(BOOST_REGEX_NO_LIB)
#define BOOST_REGEX_LIBRARY_INCLUDE_HPP
#define BOOST_LIB_NAME "boost_regex"
//
// select toolset:
//
#if defined(BOOST_MSVC) && (BOOST_MSVC == 1200) && (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION))
// vc6-stlport:
# define BOOST_LIB_TOOLSET "vc6-stlport"
#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1200)
// vc6:
# define BOOST_LIB_TOOLSET "vc6"
#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1300)
// vc7:
# define BOOST_LIB_TOOLSET "vc7"
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x560)
// CBuilder 6:
# define BOOST_LIB_TOOLSET "bcb6"
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
// CBuilder 6:
# define BOOST_LIB_TOOLSET "bcb5"
#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x540)
// CBuilder 6:
# define BOOST_LIB_TOOLSET "bcb4"
#endif
//
// select thread opt:
//
#if defined(_MT) || defined(__MT__)
# define BOOST_LIB_THREAD_OPT "m"
#else
# define BOOST_LIB_THREAD_OPT "s"
#endif
//
// select runtime opt:
//
#if defined(_DLL) || defined(_RTLDLL)
# define BOOST_LIB_RT_OPT "d"
#else
# define BOOST_LIB_RT_OPT "s"
#endif
//
// select linkage opt:
//
#if (defined(_DLL) || defined(_RTLDLL)) && !defined(BOOST_REGEX_STATIC_LINK)
# define BOOST_LIB_LINK_OPT "i"
#else
# define BOOST_LIB_LINK_OPT "s"
#endif
//
// select debug opt:
//
#if defined(BOOST_MSVC) && defined(_DEBUG) && (defined(_STLP_DEBUG) || defined(__STL_DEBUG))
# define BOOST_LIB_DEBUG_OPT "dd"
#elif defined(BOOST_MSVC) && defined(_DEBUG)
# define BOOST_LIB_DEBUG_OPT "d"
#elif defined(__BORLANDC__) && (__BORLANDC__ == 0x560) && (defined(_STLP_DEBUG) || defined(__STL_DEBUG))
# define BOOST_LIB_DEBUG_OPT "dd"
#else
# define BOOST_LIB_DEBUG_OPT
#endif
//
// now include the lib:
//
#if defined(BOOST_LIB_NAME) \
&& defined(BOOST_LIB_TOOLSET) \
&& defined(BOOST_LIB_THREAD_OPT) \
&& defined(BOOST_LIB_RT_OPT) \
&& defined(BOOST_LIB_LINK_OPT) \
&& defined(BOOST_LIB_DEBUG_OPT)
# pragma comment(lib, BOOST_LIB_NAME "_" BOOST_LIB_TOOLSET "_" BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT BOOST_LIB_LINK_OPT BOOST_LIB_DEBUG_OPT ".lib")
#endif
//
// finally undef any macros we may have set:
//
#if defined(BOOST_LIB_NAME)
# undef BOOST_LIB_NAME
#endif
#if defined(BOOST_LIB_TOOLSET)
# undef BOOST_LIB_TOOLSET
#endif
#if defined(BOOST_LIB_THREAD_OPT)
# undef BOOST_LIB_THREAD_OPT
#endif
#if defined(BOOST_LIB_RT_OPT)
# undef BOOST_LIB_RT_OPT
#endif
#if defined(BOOST_LIB_LINK_OPT)
# undef BOOST_LIB_LINK_OPT
#endif
#if defined(BOOST_LIB_DEBUG_OPT)
# undef BOOST_LIB_DEBUG_OPT
#endif
#endif // BOOST_REGEX_LIBRARY_INCLUDE_HPP

File diff suppressed because it is too large Load Diff

View File

@ -1,246 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_raw_buffer.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Raw character buffer for regex code.
* Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
#define BOOST_REGEX_RAW_BUFFER_HPP
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
namespace boost{
namespace re_detail{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
struct empty_padding{};
union padding
{
void* p;
unsigned int i;
};
template <int N>
struct padding3
{
enum{
padding_size = 8,
padding_mask = 7
};
};
template<>
struct padding3<2>
{
enum{
padding_size = 2,
padding_mask = 1
};
};
template<>
struct padding3<4>
{
enum{
padding_size = 4,
padding_mask = 3
};
};
template<>
struct padding3<8>
{
enum{
padding_size = 8,
padding_mask = 7
};
};
template<>
struct padding3<16>
{
enum{
padding_size = 16,
padding_mask = 15
};
};
enum{
padding_size = padding3<sizeof(padding)>::padding_size,
padding_mask = padding3<sizeof(padding)>::padding_mask
};
//
// class raw_storage
// basically this is a simplified vector<unsigned char>
// this is used by reg_expression for expression storage
//
template <class Allocator>
class raw_storage
{
public:
typedef Allocator allocator_type;
typedef typename boost::detail::rebind_allocator<unsigned char, allocator_type>::type alloc_inst_type;
typedef typename alloc_inst_type::size_type size_type;
typedef typename alloc_inst_type::pointer pointer;
private:
//
// empty member optimisation:
struct alloc_data : public alloc_inst_type
{
typename alloc_inst_type::pointer last;
alloc_data(const Allocator& a) : alloc_inst_type(a){}
} alloc_inst;
pointer start, end;
public:
raw_storage(const Allocator& a = Allocator());
raw_storage(size_type n, const Allocator& a = Allocator());
~raw_storage()
{
alloc_inst.deallocate(start, (alloc_inst.last - start));
}
void BOOST_REGEX_CALL resize(size_type n);
void* BOOST_REGEX_CALL extend(size_type n)
{
if(size_type(alloc_inst.last - end) < n)
resize(n + (end - start));
register void* result = end;
end += n;
return result;
}
void* BOOST_REGEX_CALL insert(size_type pos, size_type n);
size_type BOOST_REGEX_CALL size()
{
return end - start;
}
size_type BOOST_REGEX_CALL capacity()
{
return alloc_inst.last - start;
}
void* BOOST_REGEX_CALL data()const
{
return start;
}
size_type BOOST_REGEX_CALL index(void* ptr)
{
return reinterpret_cast<unsigned char*>(ptr) - reinterpret_cast<unsigned char*>(data());
}
void BOOST_REGEX_CALL clear()
{
end = start;
}
void BOOST_REGEX_CALL align()
{
// move end up to a boundary:
end = reinterpret_cast<unsigned char*>(start) + (((reinterpret_cast<unsigned char*>(end) - reinterpret_cast<unsigned char*>(start)) + padding_mask) & ~padding_mask);
}
Allocator BOOST_REGEX_CALL allocator()const;
};
template <class Allocator>
raw_storage<Allocator>::raw_storage(const Allocator& a)
: alloc_inst(a)
{
start = end = alloc_inst.allocate(1024);
BOOST_REGEX_NOEH_ASSERT(start)
alloc_inst.last = start + 1024;
}
template <class Allocator>
raw_storage<Allocator>::raw_storage(size_type n, const Allocator& a)
: alloc_inst(a)
{
start = end = alloc_inst.allocate(n);
BOOST_REGEX_NOEH_ASSERT(start)
alloc_inst.last = start + n;
}
template <class Allocator>
Allocator BOOST_REGEX_CALL raw_storage<Allocator>::allocator()const
{
return alloc_inst;
}
template <class Allocator>
void BOOST_REGEX_CALL raw_storage<Allocator>::resize(size_type n)
{
register size_type newsize = (alloc_inst.last - start) * 2;
register size_type datasize = end - start;
if(newsize < n)
newsize = n;
// extend newsize to WORD/DWORD boundary:
newsize = (newsize + padding_mask) & ~(padding_mask);
// allocate and copy data:
register unsigned char* ptr = alloc_inst.allocate(newsize);
BOOST_REGEX_NOEH_ASSERT(ptr)
std::memcpy(ptr, start, datasize);
// get rid of old buffer:
alloc_inst.deallocate(start, (alloc_inst.last - start));
// and set up pointers:
start = ptr;
end = ptr + datasize;
alloc_inst.last = ptr + newsize;
}
template <class Allocator>
void* BOOST_REGEX_CALL raw_storage<Allocator>::insert(size_type pos, size_type n)
{
jm_assert(pos <= size_type(end - start));
if(size_type(alloc_inst.last - end) < n)
resize(n + (end - start));
register void* result = start + pos;
std::memmove(start + pos + n, start + pos, (end - start) - pos);
end += n;
return result;
}
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace re_detail
} // namespace boost
#endif

View File

@ -1,149 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_split.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Implements regex_split and associated functions.
* Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
#ifndef BOOST_REGEX_SPLIT_HPP
#define BOOST_REGEX_SPLIT_HPP
namespace boost{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
namespace re_detail{
template <class charT>
const reg_expression<charT>& get_default_expression(charT)
{
static const charT expression_text[4] = { '\\', 's', '+', '\00', };
static const reg_expression<charT> e(expression_text);
return e;
}
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Alloc2>
class split_pred
{
typedef std::basic_string<charT, Traits1, Alloc1> string_type;
typedef typename string_type::const_iterator iterator_type;
iterator_type* p_last;
OutputIterator* p_out;
std::size_t* p_max;
std::size_t initial_max;
public:
split_pred(iterator_type* a, OutputIterator* b, std::size_t* c)
: p_last(a), p_out(b), p_max(c), initial_max(*c) {}
bool operator()(const match_results<iterator_type, Alloc2>& what);
};
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Alloc2>
bool split_pred<OutputIterator, charT, Traits1, Alloc1, Alloc2>::operator()
(const match_results<iterator_type, Alloc2>& what)
{
*p_last = what[0].second;
if(what.size() > 1)
{
// output sub-expressions only:
for(unsigned i = 1; i < what.size(); ++i)
{
*(*p_out) = static_cast<string_type>(what[i]);
++(*p_out);
if(0 == --*p_max) return false;
}
return *p_max != 0;
}
else
{
// output $` only if it's not-null or not at the start of the input:
const sub_match<iterator_type>& sub = what[-1];
if((sub.first != sub.second) || (*p_max != initial_max))
{
*(*p_out) = static_cast<string_type>(sub);
++(*p_out);
return --*p_max;
}
}
//
// initial null, do nothing:
return true;
}
} // namespace re_detail
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2, class Alloc2>
std::size_t regex_split(OutputIterator out,
std::basic_string<charT, Traits1, Alloc1>& s,
const reg_expression<charT, Traits2, Alloc2>& e,
unsigned flags,
std::size_t max_split)
{
typedef typename std::basic_string<charT, Traits1, Alloc1>::const_iterator ci_t;
ci_t last = s.begin();
std::size_t init_size = max_split;
re_detail::split_pred<OutputIterator, charT, Traits1, Alloc1, Alloc2> pred(&last, &out, &max_split);
ci_t i, j;
i = s.begin();
j = s.end();
regex_grep(pred, i, j, e, flags);
//
// if there is still input left, do a final push as long as max_split
// is not exhausted, and we're not splitting sub-expressions rather
// than whitespace:
if(max_split && (last != s.end()) && (e.mark_count() == 1))
{
*out = std::basic_string<charT, Traits1, Alloc1>((ci_t)last, (ci_t)s.end());
++out;
last = s.end();
--max_split;
}
//
// delete from the string everything that has been processed so far:
s.erase(0, last - s.begin());
//
// return the number of new records pushed:
return init_size - max_split;
}
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2, class Alloc2>
inline std::size_t regex_split(OutputIterator out,
std::basic_string<charT, Traits1, Alloc1>& s,
const reg_expression<charT, Traits2, Alloc2>& e,
unsigned flags = match_default)
{
return regex_split(out, s, e, flags, UINT_MAX);
}
template <class OutputIterator, class charT, class Traits1, class Alloc1>
inline std::size_t regex_split(OutputIterator out,
std::basic_string<charT, Traits1, Alloc1>& s)
{
return regex_split(out, s, re_detail::get_default_expression(charT(0)), match_default, UINT_MAX);
}
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace boost
#endif

View File

@ -1,224 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_stack.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Implements customised internal regex stacks.
* Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
#ifndef BOOST_REGEX_STACK_HPP
#define BOOST_REGEX_STACK_HPP
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
#include <boost/regex/v3/regex_raw_buffer.hpp>
#endif
namespace boost{
namespace re_detail{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
//
// class jstack
// simplified stack optimised for push/peek/pop
// operations, we could use std::stack<std::vector<T>> instead...
//
template <class T, class Allocator = BOOST_DEFAULT_ALLOCATOR(T) >
class jstack
{
private:
typedef typename boost::detail::rebind_allocator<unsigned char, Allocator>::type allocator_type;
typedef typename boost::detail::rebind_allocator<T, Allocator>::type T_alloc_type;
typedef typename T_alloc_type::size_type size_type;
typedef T value_type;
struct node
{
node* next;
T* start; // first item
T* end; // last item
T* last; // end of storage
};
//
// empty base member optimisation:
struct data : public allocator_type
{
padding buf[(sizeof(T) * 16 + sizeof(padding) - 1) / sizeof(padding)];
data(const Allocator& a) : allocator_type(a){}
};
data alloc_inst;
mutable node* m_stack;
mutable node* unused;
node base;
size_type block_size;
void BOOST_REGEX_CALL pop_aux()const;
void BOOST_REGEX_CALL push_aux();
public:
jstack(size_type n = 64, const Allocator& a = Allocator());
~jstack();
node* BOOST_REGEX_CALL get_node()
{
node* new_stack = reinterpret_cast<node*>(alloc_inst.allocate(sizeof(node) + sizeof(T) * block_size));
BOOST_REGEX_NOEH_ASSERT(new_stack)
new_stack->last = reinterpret_cast<T*>(new_stack+1);
new_stack->start = new_stack->end = new_stack->last + block_size;
new_stack->next = 0;
return new_stack;
}
bool BOOST_REGEX_CALL empty()
{
return (m_stack->start == m_stack->end) && (m_stack->next == 0);
}
bool BOOST_REGEX_CALL good()
{
return (m_stack->start != m_stack->end) || (m_stack->next != 0);
}
T& BOOST_REGEX_CALL peek()
{
if(m_stack->start == m_stack->end)
pop_aux();
return *m_stack->end;
}
const T& BOOST_REGEX_CALL peek()const
{
if(m_stack->start == m_stack->end)
pop_aux();
return *m_stack->end;
}
void BOOST_REGEX_CALL pop()
{
if(m_stack->start == m_stack->end)
pop_aux();
::boost::re_detail::pointer_destroy(m_stack->end);
++(m_stack->end);
}
void BOOST_REGEX_CALL pop(T& t)
{
if(m_stack->start == m_stack->end)
pop_aux();
t = *m_stack->end;
::boost::re_detail::pointer_destroy(m_stack->end);
++(m_stack->end);
}
void BOOST_REGEX_CALL push(const T& t)
{
if(m_stack->end == m_stack->last)
push_aux();
--(m_stack->end);
pointer_construct(m_stack->end, t);
}
};
template <class T, class Allocator>
jstack<T, Allocator>::jstack(size_type n, const Allocator& a)
: alloc_inst(a)
{
unused = 0;
block_size = n;
m_stack = &base;
base.last = reinterpret_cast<T*>(alloc_inst.buf);
base.end = base.start = base.last + 16;
base.next = 0;
}
template <class T, class Allocator>
void BOOST_REGEX_CALL jstack<T, Allocator>::push_aux()
{
// make sure we have spare space on TOS:
register node* new_node;
if(unused)
{
new_node = unused;
unused = new_node->next;
new_node->next = m_stack;
m_stack = new_node;
}
else
{
new_node = get_node();
new_node->next = m_stack;
m_stack = new_node;
}
}
template <class T, class Allocator>
void BOOST_REGEX_CALL jstack<T, Allocator>::pop_aux()const
{
// make sure that we have a valid item
// on TOS:
jm_assert(m_stack->next);
register node* p = m_stack;
m_stack = p->next;
p->next = unused;
unused = p;
}
template <class T, class Allocator>
jstack<T, Allocator>::~jstack()
{
node* condemned;
while(good())
pop();
while(unused)
{
condemned = unused;
unused = unused->next;
alloc_inst.deallocate(reinterpret_cast<unsigned char*>(condemned), sizeof(node) + sizeof(T) * block_size);
}
while(m_stack != &base)
{
condemned = m_stack;
m_stack = m_stack->next;
alloc_inst.deallocate(reinterpret_cast<unsigned char*>(condemned), sizeof(node) + sizeof(T) * block_size);
}
}
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace re_detail
} // namespace boost
#endif

View File

@ -1,210 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_synch.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Thread synchronisation for regex code.
* Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
#ifndef BOOST_REGEX_SYNCH_HPP
#define BOOST_REGEX_SYNCH_HPP
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#if defined(BOOST_HAS_THREADS)
# if defined(BOOST_HAS_WINTHREADS)
# include <windows.h>
# elif defined(BOOST_HAS_BETHREADS)
# include <OS.h>
# include <cassert>
# elif defined(BOOST_HAS_PTHREADS)
# include <pthread.h>
# else
# error "Unknown threading API"
# endif
#endif
namespace boost{
namespace re_detail{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
void BOOST_REGEX_CALL re_init_threads();
void BOOST_REGEX_CALL re_free_threads();
#ifdef BOOST_HAS_THREADS
# ifdef BOOST_HAS_BETHREADS
typedef sem_id CRITICAL_SECTION;
inline void BOOST_REGEX_CALL InitializeCriticalSection(CRITICAL_SECTION* ps)
{
*ps = create_sem(1, "regex++");
assert(*ps > 0);
}
inline void BOOST_REGEX_CALL DeleteCriticalSection(CRITICAL_SECTION* ps)
{
int t = delete_sem(*ps);
assert(t == B_NO_ERROR);
}
inline void BOOST_REGEX_CALL EnterCriticalSection(CRITICAL_SECTION* ps)
{
status_t t = acquire_sem(*ps);
assert(t == B_NO_ERROR);
}
inline void BOOST_REGEX_CALL LeaveCriticalSection(CRITICAL_SECTION* ps)
{
status_t t = release_sem(*ps);
assert(t == B_NO_ERROR);
}
# elif defined(BOOST_HAS_PTHREADS)
typedef pthread_mutex_t CRITICAL_SECTION;
inline void BOOST_REGEX_CALL InitializeCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_init(ps, 0);
}
inline void BOOST_REGEX_CALL DeleteCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_destroy(ps);
}
inline void BOOST_REGEX_CALL EnterCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_lock(ps);
}
inline void BOOST_REGEX_CALL LeaveCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_unlock(ps);
}
# elif !defined(BOOST_HAS_WINTHREADS)
# error "Unknown threading API"
# endif
template <class Lock>
class lock_guard
{
typedef Lock lock_type;
public:
lock_guard(lock_type& m, bool aq = true)
: mut(m), owned(false){ acquire(aq); }
~lock_guard()
{ acquire(false); }
void BOOST_REGEX_CALL acquire(bool aq = true)
{
if(aq && !owned)
{
mut.acquire(true);
owned = true;
}
else if(!aq && owned)
{
mut.acquire(false);
owned = false;
}
}
private:
lock_type& mut;
bool owned;
// VC6 warning suppression:
lock_guard& operator=(const lock_guard&);
};
class critical_section
{
public:
critical_section()
{ InitializeCriticalSection(&hmutex);}
critical_section(const critical_section&)
{ InitializeCriticalSection(&hmutex);}
const critical_section& BOOST_REGEX_CALL operator=(const critical_section&)
{return *this;}
~critical_section()
{DeleteCriticalSection(&hmutex);}
private:
void BOOST_REGEX_CALL acquire(bool aq)
{ if(aq) EnterCriticalSection(&hmutex);
else LeaveCriticalSection(&hmutex);
}
CRITICAL_SECTION hmutex;
public:
typedef lock_guard<critical_section> ro_guard;
typedef lock_guard<critical_section> rw_guard;
friend class lock_guard<critical_section>;
};
inline bool BOOST_REGEX_CALL operator==(const critical_section&, const critical_section&)
{
return false;
}
inline bool BOOST_REGEX_CALL operator<(const critical_section&, const critical_section&)
{
return true;
}
typedef lock_guard<critical_section> cs_guard;
BOOST_REGEX_DECL extern critical_section* p_re_lock;
BOOST_REGEX_DECL extern unsigned int re_lock_count;
#define BOOST_REGEX_GUARD(inst) boost::re_detail::critical_section::rw_guard g(inst);
#else // BOOST_HAS_THREADS
#define BOOST_REGEX_GUARD(inst)
#endif // BOOST_HAS_THREADS
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace re_detail
} // namespace boost
#endif // sentry

View File

@ -1,815 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_traits.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares regular expression traits classes.
*/
#ifndef BOOST_REGEX_TRAITS_HPP_INCLUDED
#define BOOST_REGEX_TRAITS_HPP_INCLUDED
#ifndef BOOST_RE_CREGEX_HPP
#include <boost/cregex.hpp>
#endif
#ifndef BOOST_REGEX_CSTRING_HPP
#include <boost/regex/v3/regex_cstring.hpp>
#endif
namespace boost{
#ifdef __BORLANDC__
#pragma option push -a8 -b -Vx -Ve -pc
#endif
template <class charT>
class c_regex_traits;
namespace re_detail{
struct mss
{
unsigned int id;
const char* what;
};
BOOST_REGEX_DECL bool BOOST_REGEX_CALL re_lookup_def_collate_name(std::string& buf, const char* name);
BOOST_REGEX_DECL std::size_t BOOST_REGEX_CALL re_get_default_message(char* buf, std::size_t len, std::size_t id);
extern BOOST_REGEX_DECL const char *re_default_error_messages[];
#ifndef BOOST_NO_WREGEX
extern BOOST_REGEX_DECL wchar_t wide_lower_case_map[];
extern BOOST_REGEX_DECL unsigned short wide_unicode_classes[];
BOOST_REGEX_DECL bool BOOST_REGEX_CALL is_combining(wchar_t c);
#endif
struct BOOST_REGEX_DECL regex_traits_base
{
enum char_syntax_type
{
syntax_char = 0,
syntax_open_bracket = 1, // (
syntax_close_bracket = 2, // )
syntax_dollar = 3, // $
syntax_caret = 4, // ^
syntax_dot = 5, // .
syntax_star = 6, // *
syntax_plus = 7, // +
syntax_question = 8, // ?
syntax_open_set = 9, // [
syntax_close_set = 10, // ]
syntax_or = 11, // |
syntax_slash = 12, //
syntax_hash = 13, // #
syntax_dash = 14, // -
syntax_open_brace = 15, // {
syntax_close_brace = 16, // }
syntax_digit = 17, // 0-9
syntax_b = 18, // for \b
syntax_B = 19, // for \B
syntax_left_word = 20, // for \<
syntax_right_word = 21, // for \>
syntax_w = 22, // for \w
syntax_W = 23, // for \W
syntax_start_buffer = 24, // for \`
syntax_end_buffer = 25, // for \'
syntax_newline = 26, // for newline alt
syntax_comma = 27, // for {x,y}
syntax_a = 28, // for \a
syntax_f = 29, // for \f
syntax_n = 30, // for \n
syntax_r = 31, // for \r
syntax_t = 32, // for \t
syntax_v = 33, // for \v
syntax_x = 34, // for \xdd
syntax_c = 35, // for \cx
syntax_colon = 36, // for [:...:]
syntax_equal = 37, // for [=...=]
// perl ops:
syntax_e = 38, // for \e
syntax_l = 39, // for \l
syntax_L = 40, // for \L
syntax_u = 41, // for \u
syntax_U = 42, // for \U
syntax_s = 43, // for \s
syntax_S = 44, // for \S
syntax_d = 45, // for \d
syntax_D = 46, // for \D
syntax_E = 47, // for \Q\E
syntax_Q = 48, // for \Q\E
syntax_X = 49, // for \X
syntax_C = 50, // for \C
syntax_Z = 51, // for \Z
syntax_G = 52, // for \G
// new extentions:
syntax_not = 53, // for (?!...)
syntax_max = 54
};
#ifdef __BORLANDC__
private:
char dummy_member;
#endif
};
struct BOOST_REGEX_DECL c_traits_base : public regex_traits_base
{
public:
enum{
char_class_none = 0,
char_class_alpha = 0x0001,
char_class_cntrl = 0x0002,
char_class_digit = 0x0004,
char_class_lower = 0x0008,
char_class_punct = 0x0010,
char_class_space = 0x0020,
char_class_upper = 0x0040,
char_class_xdigit = 0x0080,
char_class_blank = 0x0100,
char_class_underscore = 0x4000,
char_class_unicode = 0x8000,
char_class_alnum = char_class_alpha | char_class_digit,
char_class_graph = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore,
char_class_print = char_class_alpha | char_class_digit | char_class_punct | char_class_underscore | char_class_blank,
char_class_word = char_class_alpha | char_class_digit | char_class_underscore
};
static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s);
protected:
#if defined(__MWERKS__) && __MWERKS__ <= 0x6000
friend class c_regex_traits<char>;
friend class c_regex_traits<wchar_t>;
#endif
static char regex_message_catalogue[BOOST_REGEX_MAX_PATH];
enum syntax_map_size
{
map_size = UCHAR_MAX + 1
};
static unsigned char syntax_map[map_size];
static unsigned short class_map[map_size];
static char lower_case_map[map_size];
static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p);
static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p);
static void BOOST_REGEX_CALL do_update_ctype();
static void BOOST_REGEX_CALL do_update_collate();
public:
static std::string BOOST_REGEX_CALL error_string(unsigned id);
static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; }
};
} // namespace re_detail
template<>
class BOOST_REGEX_DECL c_regex_traits<char> : public re_detail::c_traits_base
{
typedef re_detail::c_traits_base base_type;
public:
typedef char char_type;
typedef unsigned char uchar_type;
typedef unsigned int size_type;
typedef std::string string_type;
typedef int locale_type;
static std::size_t BOOST_REGEX_CALL length(const char_type* p)
{
return std::strlen(p);
}
static unsigned int BOOST_REGEX_CALL syntax_type(size_type c)
{
return syntax_map[c];
}
static char BOOST_REGEX_CALL translate(char c, bool icase)
{
return icase ? lower_case_map[(size_type)(uchar_type)c] : c;
}
static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in);
static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in);
static bool BOOST_REGEX_CALL is_separator(char c)
{
return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r'));
}
static bool BOOST_REGEX_CALL is_combining(char)
{
return false;
}
static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)
{
return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f);
}
static int BOOST_REGEX_CALL toi(char c);
static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix);
static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)
{
std::string s(first, last);
return do_lookup_class(s.c_str());
}
static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last)
{
std::string s(first, last);
return do_lookup_collate(buf, s.c_str());
}
static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
c_regex_traits()
{
init();
}
~c_regex_traits()
{
m_free();
}
struct sentry
{
sentry(const c_regex_traits<char>&)
{ c_regex_traits<char>::update(); }
operator void*() { return this; }
};
static void BOOST_REGEX_CALL update();
private:
static void BOOST_REGEX_CALL init();
static void BOOST_REGEX_CALL m_free();
static c_regex_traits<char> i;
static unsigned sort_type;
static char sort_delim;
};
#ifndef BOOST_NO_WREGEX
template<>
class BOOST_REGEX_DECL c_regex_traits<wchar_t> : public re_detail::c_traits_base
{
typedef re_detail::c_traits_base base_type;
public:
typedef wchar_t char_type;
typedef unsigned short uchar_type;
typedef unsigned int size_type;
typedef std::basic_string<wchar_t> string_type;
typedef int locale_type;
static std::size_t BOOST_REGEX_CALL length(const char_type* p)
{
return std::wcslen(p);
}
static unsigned int BOOST_REGEX_CALL syntax_type(size_type c);
static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)
{
return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : std::towlower(c)) : c;
}
static void BOOST_REGEX_CALL transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
static void BOOST_REGEX_CALL transform_primary(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
static bool BOOST_REGEX_CALL is_separator(wchar_t c)
{
return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029));
}
static bool BOOST_REGEX_CALL is_combining(wchar_t c)
{ return re_detail::is_combining(c); }
static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)
{
return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (re_detail::wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f));
}
static int BOOST_REGEX_CALL toi(wchar_t c);
static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix);
static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last);
static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<wchar_t>& s, const wchar_t* first, const wchar_t* last);
static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
c_regex_traits<wchar_t>()
{ init(); }
~c_regex_traits<wchar_t>()
{ m_free(); }
struct sentry
{
sentry(const c_regex_traits<wchar_t>&)
{ c_regex_traits<wchar_t>::update(); }
operator void*() { return this; }
};
static void BOOST_REGEX_CALL update();
static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2);
static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2);
private:
static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f);
static void BOOST_REGEX_CALL m_free();
static void BOOST_REGEX_CALL init();
static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string<wchar_t>& out, const wchar_t* first, const wchar_t* last);
static c_regex_traits<wchar_t> init_;
static unsigned sort_type;
static wchar_t sort_delim;
};
#endif
#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
namespace re_detail{
struct BOOST_REGEX_DECL w32_traits_base : public regex_traits_base
{
enum{
char_class_none = 0,
char_class_alnum = C1_ALPHA | C1_DIGIT,
char_class_alpha = C1_ALPHA,
char_class_cntrl = C1_CNTRL,
char_class_digit = C1_DIGIT,
char_class_graph = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_ALPHA,
char_class_lower = C1_LOWER,
char_class_print = C1_UPPER | C1_LOWER | C1_DIGIT | C1_PUNCT | C1_BLANK | C1_ALPHA,
char_class_punct = C1_PUNCT,
char_class_space = C1_SPACE,
char_class_upper = C1_UPPER,
char_class_xdigit = C1_XDIGIT,
char_class_blank = C1_BLANK,
char_class_underscore = 0x4000,
char_class_word = C1_ALPHA | C1_DIGIT | char_class_underscore,
char_class_unicode = 0x8000,
char_class_win = 0x01FF
};
public:
static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s);
protected:
static char regex_message_catalogue[BOOST_REGEX_MAX_PATH];
enum syntax_map_size
{
map_size = UCHAR_MAX + 1
};
static unsigned char syntax_map[map_size];
static unsigned short class_map[map_size];
static char lower_case_map[map_size];
static boost::uint_fast32_t BOOST_REGEX_CALL do_lookup_class(const char* p);
static bool BOOST_REGEX_CALL do_lookup_collate(std::string& buf, const char* p);
static void BOOST_REGEX_CALL do_free();
static void BOOST_REGEX_CALL do_init();
public:
static std::string BOOST_REGEX_CALL error_string(unsigned id);
static char* BOOST_REGEX_CALL get_catalogue() { return regex_message_catalogue; }
};
} // namespace re_detail
template<class charT>
class w32_regex_traits;
template<>
class BOOST_REGEX_DECL w32_regex_traits<char> : public re_detail::w32_traits_base
{
typedef re_detail::w32_traits_base base_type;
public:
typedef char char_type;
typedef unsigned char uchar_type;
typedef unsigned int size_type;
typedef std::string string_type;
typedef int locale_type;
static std::size_t BOOST_REGEX_CALL length(const char_type* p)
{
return std::strlen(p);
}
static unsigned int BOOST_REGEX_CALL syntax_type(size_type c)
{
return syntax_map[c];
}
static char BOOST_REGEX_CALL translate(char c, bool icase)
{
return icase ? lower_case_map[(size_type)(uchar_type)c] : c;
}
static void BOOST_REGEX_CALL transform(std::string& out, const std::string& in);
static void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in);
static bool BOOST_REGEX_CALL is_separator(char c)
{
return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r'));
}
static bool BOOST_REGEX_CALL is_combining(char)
{
return false;
}
static bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)
{
return BOOST_REGEX_MAKE_BOOL(class_map[(size_type)(uchar_type)c] & f);
}
static int BOOST_REGEX_CALL toi(char c);
static int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix);
static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)
{
std::string s(first, last);
return do_lookup_class(s.c_str());
}
static bool BOOST_REGEX_CALL lookup_collatename(std::string& buf, const char* first, const char* last)
{
std::string s(first, last);
return do_lookup_collate(buf, s.c_str());
}
static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
struct sentry
{
sentry(const w32_regex_traits<char>&)
{ w32_regex_traits<char>::update(); }
~sentry(){}
operator void*() { return this; }
};
static void BOOST_REGEX_CALL update();
w32_regex_traits();
~w32_regex_traits();
private:
static w32_regex_traits<char> i;
};
#ifndef BOOST_NO_WREGEX
template<>
class BOOST_REGEX_DECL w32_regex_traits<wchar_t> : public re_detail::w32_traits_base
{
typedef re_detail::w32_traits_base base_type;
public:
typedef wchar_t char_type;
typedef unsigned short uchar_type;
typedef unsigned int size_type;
typedef std::basic_string<wchar_t> string_type;
typedef int locale_type;
static std::size_t BOOST_REGEX_CALL length(const char_type* p)
{
return std::wcslen(p);
}
static unsigned int BOOST_REGEX_CALL syntax_type(size_type c);
static wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)
{
return icase ? ((c < 256) ? re_detail::wide_lower_case_map[(uchar_type)c] : wtolower(c)) : c;
}
static void BOOST_REGEX_CALL transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
static void BOOST_REGEX_CALL transform_primary(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in);
static bool BOOST_REGEX_CALL is_separator(wchar_t c)
{
return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029));
}
static bool BOOST_REGEX_CALL is_combining(wchar_t c)
{ return re_detail::is_combining(c); }
static bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)
{
return BOOST_REGEX_MAKE_BOOL(((uchar_type)c < 256) ? (wide_unicode_classes[(size_type)(uchar_type)c] & f) : do_iswclass(c, f));
}
static int BOOST_REGEX_CALL toi(wchar_t c);
static int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix);
static boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last);
static bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<wchar_t>& s, const wchar_t* first, const wchar_t* last);
static locale_type BOOST_REGEX_CALL imbue(locale_type l){ return l; }
locale_type BOOST_REGEX_CALL getloc()const{ return locale_type(); }
struct sentry
{
sentry(const w32_regex_traits<wchar_t>&)
{ w32_regex_traits<wchar_t>::update(); }
~sentry(){}
operator void*() { return this; }
};
static void BOOST_REGEX_CALL update();
w32_regex_traits();
~w32_regex_traits();
static std::size_t BOOST_REGEX_CALL strnarrow(char *s1, std::size_t len, const wchar_t *s2);
static std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2);
private:
static bool BOOST_REGEX_CALL do_iswclass(wchar_t c, boost::uint_fast32_t f);
static bool BOOST_REGEX_CALL do_lookup_collate(std::basic_string<wchar_t>& out, const wchar_t* first, const wchar_t* last);
static w32_regex_traits<wchar_t> init_;
static wchar_t BOOST_REGEX_CALL wtolower(wchar_t c);
static unsigned short wide_unicode_classes[];
};
#endif // Wide strings
#endif // Win32
#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_STD_WSTREAMBUF)
} // namspace boost
#ifdef __BORLANDC__
#pragma option pop
#endif
#include <locale>
#ifdef __BORLANDC__
#pragma option push -a4 -b -Ve -pc
#endif
namespace boost{
namespace re_detail
{
template <class charT>
struct message_data;
template <>
struct message_data<char>;
template <>
struct message_data<wchar_t>;
struct BOOST_REGEX_DECL cpp_regex_traits_base : public regex_traits_base
{
enum char_class_type
{
char_class_none = 0,
char_class_alnum = std::ctype_base::alnum,
char_class_alpha = std::ctype_base::alpha,
char_class_cntrl = std::ctype_base::cntrl,
char_class_digit = std::ctype_base::digit,
char_class_graph = std::ctype_base::graph,
char_class_lower = std::ctype_base::lower,
char_class_print = std::ctype_base::print,
char_class_punct = std::ctype_base::punct,
char_class_space = std::ctype_base::space,
char_class_upper = std::ctype_base::upper,
char_class_xdigit = std::ctype_base::xdigit,
char_class_blank = 1<<12,
char_class_underscore = 1<<13,
char_class_word = std::ctype_base::alnum | char_class_underscore,
char_class_unicode = 1<<14,
char_class_all_base = char_class_alnum | char_class_alpha | char_class_cntrl
| char_class_digit | char_class_graph | char_class_lower
| char_class_print | char_class_punct | char_class_space
| char_class_upper | char_class_xdigit
};
static std::string BOOST_REGEX_CALL set_message_catalogue(const std::string& s);
protected:
static char regex_message_cat[BOOST_REGEX_MAX_PATH];
};
} // namespace re_detail
template <class charT>
class cpp_regex_traits;
template<>
class BOOST_REGEX_DECL cpp_regex_traits<char> : public re_detail::cpp_regex_traits_base
{
typedef re_detail::cpp_regex_traits_base base_type;
private:
re_detail::message_data<char>* pmd;
const unsigned char* psyntax;
char* lower_map;
const std::ctype<char>* pctype;
const std::collate<char>* pcollate;
std::locale locale_inst;
unsigned sort_type;
char sort_delim;
cpp_regex_traits(const cpp_regex_traits&);
cpp_regex_traits& operator=(const cpp_regex_traits&);
public:
typedef char char_type;
typedef unsigned char uchar_type;
typedef unsigned int size_type;
typedef std::string string_type;
typedef std::locale locale_type;
cpp_regex_traits();
~cpp_regex_traits();
void swap(cpp_regex_traits&);
static std::size_t BOOST_REGEX_CALL length(const char_type* p)
{
return std::strlen(p);
}
unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const
{
return psyntax[c];
}
char BOOST_REGEX_CALL translate(char c, bool icase)const
{
return icase ? lower_map[(size_type)(uchar_type)c] : c;
}
void BOOST_REGEX_CALL transform(std::string& out, const std::string& in)const
{
out = pcollate->transform(in.c_str(), in.c_str() + in.size()).c_str();
}
void BOOST_REGEX_CALL transform_primary(std::string& out, const std::string& in)const;
static bool BOOST_REGEX_CALL is_separator(char c)
{
return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r'));
}
static bool BOOST_REGEX_CALL is_combining(char)
{
return false;
}
bool BOOST_REGEX_CALL is_class(char c, boost::uint_fast32_t f)const
{
if(pctype->is((std::ctype<char>::mask)(f & char_class_all_base), c))
return true;
if((f & char_class_underscore) && (c == '_'))
return true;
if((f & char_class_blank) && ((c == ' ') || (c == '\t')))
return true;
return false;
}
int BOOST_REGEX_CALL toi(char c)const;
int BOOST_REGEX_CALL toi(const char*& first, const char* last, int radix)const;
boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const char* first, const char* last)const;
bool BOOST_REGEX_CALL lookup_collatename(std::string& s, const char* first, const char* last)const;
std::string BOOST_REGEX_CALL error_string(unsigned id)const;
locale_type BOOST_REGEX_CALL imbue(locale_type l);
locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; }
struct sentry
{
sentry(const cpp_regex_traits<char>&){}
operator void*() { return this; }
};
};
#ifndef BOOST_NO_WREGEX
template<>
class BOOST_REGEX_DECL cpp_regex_traits<wchar_t> : public re_detail::cpp_regex_traits_base
{
typedef re_detail::cpp_regex_traits_base base_type;
public:
typedef wchar_t char_type;
typedef unsigned short uchar_type;
typedef unsigned int size_type;
typedef std::basic_string<wchar_t> string_type;
typedef std::locale locale_type;
private:
re_detail::message_data<wchar_t>* pmd;
const unsigned char* psyntax;
wchar_t* lower_map;
const std::ctype<wchar_t>* pctype;
const std::collate<wchar_t>* pcollate;
const std::codecvt<wchar_t, char, std::mbstate_t>* pcdv;
std::locale locale_inst;
unsigned int BOOST_REGEX_CALL do_syntax_type(size_type c)const;
unsigned sort_type;
wchar_t sort_delim;
cpp_regex_traits(const cpp_regex_traits&);
cpp_regex_traits& operator=(const cpp_regex_traits&);
public:
static std::size_t BOOST_REGEX_CALL length(const char_type* p)
{
return std::wcslen(p);
}
unsigned int BOOST_REGEX_CALL syntax_type(size_type c)const
{
return (c < UCHAR_MAX) ? psyntax[c] : do_syntax_type(c);
}
wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool icase)const
{
return icase ? (((uchar_type)c) <= UCHAR_MAX) ? lower_map[c] : pctype->tolower(c) : c;
}
void BOOST_REGEX_CALL transform(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in)const
{
out = pcollate->transform(in.c_str(), in.c_str() + in.size());
}
void BOOST_REGEX_CALL transform_primary(std::basic_string<wchar_t>& out, const std::basic_string<wchar_t>& in)const;
static bool BOOST_REGEX_CALL is_separator(wchar_t c)
{
return BOOST_REGEX_MAKE_BOOL((c == L'\n') || (c == L'\r') || (c == (wchar_t)0x2028) || (c == (wchar_t)0x2029));
}
static bool BOOST_REGEX_CALL is_combining(wchar_t c)
{ return re_detail::is_combining(c); }
bool BOOST_REGEX_CALL is_class(wchar_t c, boost::uint_fast32_t f)const
{
if(pctype->is((std::ctype<wchar_t>::mask)(f & char_class_all_base), c))
return true;
if((f & char_class_underscore) && (c == '_'))
return true;
if((f & char_class_blank) && ((c == ' ') || (c == '\t')))
return true;
if((f & char_class_unicode) && ((uchar_type)c > (uchar_type)255))
return true;
return false;
}
int BOOST_REGEX_CALL toi(wchar_t c)const;
int BOOST_REGEX_CALL toi(const wchar_t*& first, const wchar_t* last, int radix)const;
boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const;
bool BOOST_REGEX_CALL lookup_collatename(std::basic_string<wchar_t>& s, const wchar_t* first, const wchar_t* last)const;
std::string BOOST_REGEX_CALL error_string(unsigned id)const;
cpp_regex_traits();
~cpp_regex_traits();
locale_type BOOST_REGEX_CALL imbue(locale_type l);
locale_type BOOST_REGEX_CALL getloc()const{ return locale_inst; }
std::size_t BOOST_REGEX_CALL strwiden(wchar_t *s1, std::size_t len, const char *s2)const;
void swap(cpp_regex_traits&);
struct sentry
{
sentry(const cpp_regex_traits<wchar_t>&){}
operator void*() { return this; }
};
};
#endif // BOOST_NO_WREGEX
#endif // BOOST_NO_STD_LOCALE
#ifdef BOOST_REGEX_USE_WIN32_LOCALE
template <class charT>
class regex_traits : public w32_regex_traits<charT>
{
};
#elif defined(BOOST_REGEX_USE_C_LOCALE)
template <class charT>
class regex_traits : public c_regex_traits<charT>
{
};
#elif defined(BOOST_REGEX_USE_CPP_LOCALE)
template <class charT>
class regex_traits : public cpp_regex_traits<charT>
{
};
#else
#error No default localisation model defined
#endif
#ifdef __BORLANDC__
#pragma option pop
#endif
} // namespace boost
#endif // include

View File

@ -1,6 +1,6 @@
/*
*
* Copyright (c) 1998-2002
* Copyright (c) 1998-2004
* Dr John Maddock
*
* Use, modification and distribution are subject to the
@ -13,8 +13,7 @@
* LOCATION: see http://www.boost.org for most recent version.
* FILE basic_regex.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares template class basic_regex (note that member function
* bodies are in regex_compile.hpp).
* DESCRIPTION: Declares template class basic_regex.
*/
#ifndef BOOST_REGEX_V4_BASIC_REGEX_HPP
@ -25,28 +24,166 @@
#endif
namespace boost{
//
// class reg_expression
// represents the compiled
// regular expression:
//
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4251 4231 4660)
#endif
namespace re_detail{
//
// forward declaration, we will need this one later:
//
template <class charT, class traits>
class basic_regex_parser;
//
// class regex_data:
// represents the data we wish to expose to the matching algorithms.
//
template <class charT, class traits>
struct regex_data
{
typedef regex_constants::syntax_option_type flag_type;
typedef std::size_t size_type;
regex_data(const ::boost::shared_ptr<
::boost::regex_traits_wrapper<traits> >& t)
: m_ptraits(t) {}
regex_data()
: m_ptraits(new ::boost::regex_traits_wrapper<traits>()) {}
::boost::shared_ptr<
::boost::regex_traits_wrapper<traits>
> m_ptraits; // traits class instance
flag_type m_flags; // flags with which we were compiled
int m_status; // error code (0 implies OK).
const charT* m_expression; // the original expression
std::ptrdiff_t m_expression_len; // the length of the original expression
size_type m_mark_count; // the number of marked sub-expressions
re_detail::re_syntax_base* m_first_state; // the first state of the machine
unsigned m_restart_type; // search optimisation type
unsigned char m_startmap[1 << CHAR_BIT]; // which characters can start a match
unsigned int m_can_be_null; // whether we can match a null string
re_detail::raw_storage m_data; // the buffer in which our states are constructed
};
//
// class basic_regex_implementation
// pimpl implementation class for basic_regex.
//
template <class charT, class traits>
class basic_regex_implementation
: public regex_data<charT, traits>
{
public:
typedef regex_constants::syntax_option_type flag_type;
typedef std::ptrdiff_t difference_type;
typedef std::size_t size_type;
typedef typename traits::locale_type locale_type;
typedef const charT* const_iterator;
basic_regex_implementation(){}
basic_regex_implementation(const ::boost::shared_ptr<
::boost::regex_traits_wrapper<traits> >& t)
: regex_data<charT, traits>(t) {}
void assign(const charT* arg_first,
const charT* arg_last,
flag_type f)
{
regex_data<charT, traits>* pdat = this;
basic_regex_parser<charT, traits> parser(pdat);
parser.parse(arg_first, arg_last, f);
}
locale_type BOOST_REGEX_CALL imbue(locale_type l)
{
return this->m_ptraits->imbue(l);
}
locale_type BOOST_REGEX_CALL getloc()const
{
return this->m_ptraits->getloc();
}
std::basic_string<charT> BOOST_REGEX_CALL str()const
{
std::basic_string<charT> result;
if(this->m_status == 0)
result = std::basic_string<charT>(this->m_expression, this->m_expression_len);
return result;
}
const_iterator BOOST_REGEX_CALL expression()const
{
return this->m_expression;
}
//
// begin, end:
const_iterator BOOST_REGEX_CALL begin()const
{
return (!this->m_status ? 0 : this->m_expression);
}
const_iterator BOOST_REGEX_CALL end()const
{
return (!this->m_status ? 0 : this->m_expression + this->m_expression_len);
}
flag_type BOOST_REGEX_CALL flags()const
{
return this->m_flags;
}
size_type BOOST_REGEX_CALL size()const
{
return this->m_expression_len;
}
int BOOST_REGEX_CALL status()const
{
return this->m_status;
}
size_type BOOST_REGEX_CALL mark_count()const
{
return this->m_mark_count;
}
const re_detail::re_syntax_base* get_first_state()const
{
return this->m_first_state;
}
unsigned get_restart_type()const
{
return this->m_restart_type;
}
const unsigned char* get_map()const
{
return this->m_startmap;
}
const ::boost::regex_traits_wrapper<traits>& get_traits()const
{
return *(this->m_ptraits);
}
bool can_be_null()const
{
return this->m_can_be_null;
}
const regex_data<charT, traits>& get_data()const
{
basic_regex_implementation<charT, traits> const* p = this;
return *static_cast<const regex_data<charT, traits>*>(p);
}
};
} // namespace re_detail
//
// class basic_regex:
// represents the compiled
// regular expression:
//
#ifdef BOOST_REGEX_NO_FWD
template <class charT, class traits = regex_traits<charT>, class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
template <class charT, class traits = regex_traits<charT> >
#else
template <class charT, class traits, class Allocator >
template <class charT, class traits >
#endif
class reg_expression : public regbase
class basic_regex : public regbase
{
public:
// typedefs:
typedef typename traits::size_type traits_size_type;
typedef typename traits::uchar_type traits_uchar_type;
typedef typename traits::string_type traits_string_type;
typedef charT char_type;
typedef traits traits_type;
@ -56,10 +193,8 @@ public:
typedef const charT& const_reference;
typedef const charT* const_iterator;
typedef const_iterator iterator;
typedef typename Allocator::difference_type difference_type;
typedef typename Allocator::size_type size_type;
typedef Allocator allocator_type;
typedef Allocator alloc_type;
typedef std::ptrdiff_t difference_type;
typedef std::size_t size_type;
typedef regex_constants::syntax_option_type flag_type;
// locale_type
// placeholder for actual locale type used by the
@ -67,319 +202,411 @@ public:
typedef typename traits::locale_type locale_type;
public:
explicit reg_expression(const Allocator& a = Allocator());
explicit reg_expression(const charT* p, flag_type f = regex_constants::normal, const Allocator& a = Allocator());
reg_expression(const charT* p1, const charT* p2, flag_type f = regex_constants::normal, const Allocator& a = Allocator());
reg_expression(const charT* p, size_type len, flag_type f, const Allocator& a = Allocator());
reg_expression(const reg_expression&);
~reg_expression();
reg_expression& BOOST_REGEX_CALL operator=(const reg_expression&);
reg_expression& BOOST_REGEX_CALL operator=(const charT* ptr)
explicit basic_regex(){}
explicit basic_regex(const charT* p, flag_type f = regex_constants::normal)
{
set_expression(ptr, regex_constants::normal | regex_constants::use_except);
return *this;
assign(p, f);
}
basic_regex(const charT* p1, const charT* p2, flag_type f = regex_constants::normal)
{
assign(p1, p2, f);
}
basic_regex(const charT* p, size_type len, flag_type f)
{
assign(p, len, f);
}
basic_regex(const basic_regex& that)
: m_pimpl(that.m_pimpl) {}
~basic_regex(){}
basic_regex& BOOST_REGEX_CALL operator=(const basic_regex& that)
{
return assign(that);
}
basic_regex& BOOST_REGEX_CALL operator=(const charT* ptr)
{
return assign(ptr);
}
//
// assign:
reg_expression& assign(const reg_expression& that)
{ return *this = that; }
reg_expression& assign(const charT* ptr, flag_type f = regex_constants::normal)
{
set_expression(ptr, f | regex_constants::use_except);
return *this;
basic_regex& assign(const basic_regex& that)
{
m_pimpl = that.m_pimpl;
return *this;
}
reg_expression& assign(const charT* ptr, size_type len, flag_type f)
basic_regex& assign(const charT* p, flag_type f = regex_constants::normal)
{
std::basic_string<charT> s(ptr, len);
set_expression(s.c_str(), f | regex_constants::use_except);
return *this;
return assign(p, p + traits::length(p), f);
}
basic_regex& assign(const charT* p, size_type len, flag_type f)
{
return assign(p, p + len, f);
}
reg_expression& assign(const charT* arg_first,
const charT* arg_last,
flag_type f = regex_constants::normal)
{
set_expression(arg_first, arg_last, f | regex_constants::use_except);
return *this;
}
basic_regex& assign(const charT* p1,
const charT* p2,
flag_type f = regex_constants::normal);
#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
template <class ST, class SA>
unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal)
{ return set_expression(p.data(), p.data() + p.size(), f); }
{
return set_expression(p.data(), p.data() + p.size(), f);
}
template <class ST, class SA>
explicit reg_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal, const Allocator& a = Allocator())
: data(a), pkmp(0), error_code_(REG_EMPTY), _expression(0) { set_expression(p, f | regex_constants::use_except); }
explicit basic_regex(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal)
{
assign(p, f);
}
template <class InputIterator>
reg_expression(InputIterator arg_first, InputIterator arg_last, flag_type f = regex_constants::normal, const Allocator& al = Allocator())
: data(al), pkmp(0), error_code_(REG_EMPTY), _expression(0)
basic_regex(InputIterator arg_first, InputIterator arg_last, flag_type f = regex_constants::normal)
{
typedef typename traits::string_type seq_type;
seq_type a(arg_first, arg_last);
assign(&*a.begin(), &*a.begin() + a.size(), f);
}
template <class ST, class SA>
basic_regex& BOOST_REGEX_CALL operator=(const std::basic_string<charT, ST, SA>& p)
{
return assign(p.data(), p.data() + p.size(), regex_constants::normal);
}
template <class string_traits, class A>
basic_regex& BOOST_REGEX_CALL assign(
const std::basic_string<charT, string_traits, A>& s,
flag_type f = regex_constants::normal)
{
return assign(s.data(), s.data() + s.size(), f);
}
template <class InputIterator>
basic_regex& BOOST_REGEX_CALL assign(InputIterator arg_first,
InputIterator arg_last,
flag_type f = regex_constants::normal)
{
typedef typename traits::string_type seq_type;
seq_type a(arg_first, arg_last);
const charT* p1 = &*a.begin();
const charT* p2 = &*a.begin() + a.size();
return assign(p1, p2, f);
}
#else
unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal)
{
return set_expression(p.data(), p.data() + p.size(), f);
}
basic_regex(const std::basic_string<charT>& p, flag_type f = regex_constants::normal)
{
assign(p, f);
}
basic_regex& BOOST_REGEX_CALL operator=(const std::basic_string<charT>& p)
{
return assign(p.data(), p.data() + p.size(), regex_constants::normal);
}
basic_regex& BOOST_REGEX_CALL assign(
const std::basic_string<charT>& s,
flag_type f = regex_constants::normal)
{
return assign(s.data(), s.data() + s.size(), f);
}
#endif
//
// locale:
locale_type BOOST_REGEX_CALL imbue(locale_type l);
locale_type BOOST_REGEX_CALL getloc()const
{
return m_pimpl.get() ? m_pimpl->getloc() : locale_type();
}
//
// getflags:
// retained for backwards compatibility only, "flags"
// is now the prefered name:
flag_type BOOST_REGEX_CALL getflags()const
{
return flags();
}
flag_type BOOST_REGEX_CALL flags()const
{
return m_pimpl.get() ? m_pimpl->flags() : 0;
}
//
// str:
std::basic_string<charT> BOOST_REGEX_CALL str()const
{
return m_pimpl.get() ? m_pimpl->str() : std::basic_string<charT>();
}
//
// begin, end:
const_iterator BOOST_REGEX_CALL begin()const
{
return (m_pimpl.get() ? m_pimpl->begin() : 0);
}
const_iterator BOOST_REGEX_CALL end()const
{
return (m_pimpl.get() ? m_pimpl->end() : 0);
}
//
// swap:
void BOOST_REGEX_CALL swap(basic_regex& that)throw()
{
m_pimpl.swap(that.m_pimpl);
}
//
// size:
size_type BOOST_REGEX_CALL size()const
{
return (m_pimpl.get() ? m_pimpl->size() : 0);
}
//
// max_size:
size_type BOOST_REGEX_CALL max_size()const
{
return UINT_MAX;
}
//
// empty:
bool BOOST_REGEX_CALL empty()const
{
return (m_pimpl.get() ? 0 != m_pimpl->status() : 0);
}
size_type BOOST_REGEX_CALL mark_count()const
{
return (m_pimpl.get() ? m_pimpl->mark_count() : 0);
}
int status()const
{
return (m_pimpl.get() ? m_pimpl->status() : regex_constants::error_empty);
}
int BOOST_REGEX_CALL compare(const basic_regex& that) const
{
if(m_pimpl.get() == that.m_pimpl.get())
return 0;
if(!m_pimpl.get())
return -1;
if(!that.m_pimpl.get())
return 1;
if(status() != that.status())
return status() - that.status();
if(flags() != that.flags())
return flags() - that.flags();
return str().compare(that.str());
}
bool BOOST_REGEX_CALL operator==(const basic_regex& e)const
{
return compare(e) == 0;
}
bool BOOST_REGEX_CALL operator != (const basic_regex& e)const
{
return compare(e) != 0;
}
bool BOOST_REGEX_CALL operator<(const basic_regex& e)const
{
return compare(e) < 0;
}
bool BOOST_REGEX_CALL operator>(const basic_regex& e)const
{
return compare(e) > 0;
}
bool BOOST_REGEX_CALL operator<=(const basic_regex& e)const
{
return compare(e) <= 0;
}
bool BOOST_REGEX_CALL operator>=(const basic_regex& e)const
{
return compare(e) >= 0;
}
//
// The following are deprecated as public interfaces
// but are available for compatibility with earlier versions.
const charT* BOOST_REGEX_CALL expression()const
{
return (m_pimpl.get() && !m_pimpl->status() ? m_pimpl->expression() : 0);
}
unsigned int BOOST_REGEX_CALL set_expression(const charT* p1, const charT* p2, flag_type f = regex_constants::normal)
{
assign(p1, p2, f | regex_constants::no_except);
return status();
}
unsigned int BOOST_REGEX_CALL set_expression(const charT* p, flag_type f = regex_constants::normal)
{
assign(p, f | regex_constants::no_except);
return status();
}
unsigned int BOOST_REGEX_CALL error_code()const
{
return status();
}
//
// private access methods:
//
const re_detail::re_syntax_base* get_first_state()const
{
assert(0 != m_pimpl.get());
return m_pimpl->get_first_state();
}
unsigned get_restart_type()const
{
assert(0 != m_pimpl.get());
return m_pimpl->get_restart_type();
}
const unsigned char* get_map()const
{
assert(0 != m_pimpl.get());
return m_pimpl->get_map();
}
const ::boost::regex_traits_wrapper<traits>& get_traits()const
{
assert(0 != m_pimpl.get());
return m_pimpl->get_traits();
}
bool can_be_null()const
{
assert(0 != m_pimpl.get());
return m_pimpl->can_be_null();
}
const re_detail::regex_data<charT, traits>& get_data()const
{
assert(0 != m_pimpl.get());
return m_pimpl->get_data();
}
private:
shared_ptr<re_detail::basic_regex_implementation<charT, traits> > m_pimpl;
};
//
// out of line members;
// these are the only members that mutate the basic_regex object,
// and are designed to provide the strong exception guarentee
// (in the event of a throw, the state of the object remains unchanged).
//
template <class charT, class traits>
basic_regex<charT, traits>& basic_regex<charT, traits>::assign(const charT* p1,
const charT* p2,
flag_type f)
{
shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp;
if(!m_pimpl.get())
{
temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>());
}
else
{
temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>(m_pimpl->m_ptraits));
}
temp->assign(p1, p2, f);
temp.swap(m_pimpl);
return *this;
}
template <class charT, class traits>
typename basic_regex<charT, traits>::locale_type BOOST_REGEX_CALL basic_regex<charT, traits>::imbue(locale_type l)
{
shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp(new re_detail::basic_regex_implementation<charT, traits>());
locale_type result = temp->imbue(l);
temp.swap(m_pimpl);
return result;
}
//
// non-members:
//
template <class charT, class traits>
void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2)
{
e1.swap(e2);
}
#ifndef BOOST_NO_STD_LOCALE
template <class charT, class traits, class traits2>
std::basic_ostream<charT, traits>&
operator << (std::basic_ostream<charT, traits>& os,
const basic_regex<charT, traits2>& e)
{
return (os << e.str());
}
#else
template <class traits>
std::ostream& operator << (std::ostream& os, const basic_regex<char, traits>& e)
{
return (os << e.str());
}
#endif
//
// class reg_expression:
// this is provided for backwards compatibility only,
// it is deprecated, no not use!
//
#ifdef BOOST_REGEX_NO_FWD
template <class charT, class traits = regex_traits<charT> >
#else
template <class charT, class traits >
#endif
class reg_expression : public basic_regex<charT, traits>
{
public:
typedef typename basic_regex<charT, traits>::flag_type flag_type;
typedef typename basic_regex<charT, traits>::size_type size_type;
explicit reg_expression(){}
explicit reg_expression(const charT* p, flag_type f = regex_constants::normal)
: basic_regex<charT, traits>(p, f){}
reg_expression(const charT* p1, const charT* p2, flag_type f = regex_constants::normal)
: basic_regex<charT, traits>(p1, p2, f){}
reg_expression(const charT* p, size_type len, flag_type f)
: basic_regex<charT, traits>(p, len, f){}
reg_expression(const reg_expression& that)
: basic_regex<charT, traits>(that) {}
~reg_expression(){}
reg_expression& BOOST_REGEX_CALL operator=(const reg_expression& that)
{
return this->assign(that);
}
#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
template <class ST, class SA>
explicit reg_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal)
: basic_regex<charT, traits>(p, f)
{
}
template <class InputIterator>
reg_expression(InputIterator arg_first, InputIterator arg_last, flag_type f = regex_constants::normal)
: basic_regex<charT, traits>(arg_first, arg_last, f)
{
std::basic_string<charT> a(arg_first, arg_last);
set_expression(a.data(), a.data() + a.size(), f | regex_constants::use_except);
}
template <class ST, class SA>
reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string<charT, ST, SA>& p)
{
set_expression(p.c_str(), p.c_str() + p.size(), regex_constants::normal | regex_constants::use_except);
return *this;
}
template <class string_traits, class A>
reg_expression& BOOST_REGEX_CALL assign(
const std::basic_string<charT, string_traits, A>& s,
flag_type f = regex_constants::normal)
{
set_expression(s.c_str(), s.c_str() + s.size(), f | regex_constants::use_except);
return *this;
}
template <class InputIterator>
reg_expression& BOOST_REGEX_CALL assign(InputIterator arg_first,
InputIterator arg_last,
flag_type f = regex_constants::normal)
{
std::basic_string<charT> a(arg_first, arg_last);
set_expression(a.data(), a.data() + a.size(), f | regex_constants::use_except);
this->assign(p);
return *this;
}
#else
unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal)
{ return set_expression(p.data(), p.data() + p.size(), f | regex_constants::use_except); }
reg_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal, const Allocator& a = Allocator())
: data(a), pkmp(0) { set_expression(p, f | regex_constants::use_except); }
explicit reg_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal)
: basic_regex<charT, traits>(p, f)
{
}
reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string<charT>& p)
{
set_expression(p.c_str(), p.c_str() + p.size(), regex_constants::normal | regex_constants::use_except);
return *this;
}
reg_expression& BOOST_REGEX_CALL assign(
const std::basic_string<charT>& s,
flag_type f = regex_constants::normal)
{
set_expression(s.c_str(), s.c_str() + s.size(), f | regex_constants::use_except);
return *this;
}
#endif
//
// allocator access:
Allocator BOOST_REGEX_CALL get_allocator()const;
//
// locale:
locale_type BOOST_REGEX_CALL imbue(locale_type l){ return traits_inst.imbue(l); }
locale_type BOOST_REGEX_CALL getloc()const{ return traits_inst.getloc(); }
//
// getflags:
// retained for backwards compatibility only, the base class has "flags"
// member which is now the prefered name:
flag_type BOOST_REGEX_CALL getflags()const
{ return this->flags(); }
//
// str:
std::basic_string<charT> BOOST_REGEX_CALL str()const
{
std::basic_string<charT> result;
if(this->error_code() == 0)
result = std::basic_string<charT>(_expression, _expression_len);
return result;
}
//
// begin, end:
const_iterator BOOST_REGEX_CALL begin()const
{ return (this->error_code() ? 0 : _expression); }
const_iterator BOOST_REGEX_CALL end()const
{ return (this->error_code() ? 0 : _expression + _expression_len); }
//
// swap:
void BOOST_REGEX_CALL swap(reg_expression&)throw();
//
// size:
size_type BOOST_REGEX_CALL size()const
{ return (this->error_code() ? 0 : _expression_len); }
//
// max_size:
size_type BOOST_REGEX_CALL max_size()const
{ return UINT_MAX; }
//
// empty:
bool BOOST_REGEX_CALL empty()const
{ return 0 != this->error_code(); }
unsigned BOOST_REGEX_CALL mark_count()const { return (this->error_code() ? 0 : marks); }
int BOOST_REGEX_CALL compare(const reg_expression&) const;
bool BOOST_REGEX_CALL operator==(const reg_expression& e)const
{ return compare(e) == 0; }
bool operator != (const reg_expression& e)
{ return compare(e) != 0; }
bool BOOST_REGEX_CALL operator<(const reg_expression& e)const
{ return compare(e) < 0; }
bool BOOST_REGEX_CALL operator>(const reg_expression& e)const
{ return compare(e) > 0; }
bool BOOST_REGEX_CALL operator<=(const reg_expression& e)const
{ return compare(e) <= 0; }
bool BOOST_REGEX_CALL operator>=(const reg_expression& e)const
{ return compare(e) >= 0; }
//
// The following are deprecated as public interfaces
// but are available for compatibility with earlier versions.
allocator_type BOOST_REGEX_CALL allocator()const;
const charT* BOOST_REGEX_CALL expression()const { return (this->error_code() ? 0 : _expression); }
unsigned int BOOST_REGEX_CALL set_expression(const charT* p, const charT* end, flag_type f = regex_constants::normal);
unsigned int BOOST_REGEX_CALL set_expression(const charT* p, flag_type f = regex_constants::normal) { return set_expression(p, p + traits_type::length(p), f); }
//
// this should be private but template friends don't work:
const traits_type& get_traits()const { return traits_inst; }
unsigned int BOOST_REGEX_CALL error_code()const
{
return error_code_;
}
private:
traits_type traits_inst; // traits class in use
re_detail::raw_storage<Allocator> data; // our state machine
unsigned _restart_type; // search method to use
unsigned marks; // number of marked sub-expressions
int repeats; // number of repeats
unsigned char* startmap; // characters that can match the first state(s) in the machine
std::size_t _expression_len; // length of the expression
std::size_t _leading_len; // length of any leading literal
const charT* _leading_string; // leading literal string
std::size_t _leading_string_len; // and it's length
re_detail::kmp_info<charT>* pkmp; // pointer to Knuth Morris Pratt state machine when available
unsigned error_code_; // our current status
charT* _expression; // the expression we just compiled if any
void BOOST_REGEX_CALL compile_maps();
void BOOST_REGEX_CALL compile_map(re_detail::re_syntax_base* node, unsigned char* _map, unsigned int* pnull, unsigned char mask, re_detail::re_syntax_base* terminal = 0)const;
bool BOOST_REGEX_CALL probe_start(re_detail::re_syntax_base* node, charT c, re_detail::re_syntax_base* terminal)const;
bool BOOST_REGEX_CALL probe_start_null(re_detail::re_syntax_base* node, re_detail::re_syntax_base* terminal)const;
void BOOST_REGEX_CALL fixup_apply(re_detail::re_syntax_base* b, unsigned cbraces);
void BOOST_REGEX_CALL move_offsets(re_detail::re_syntax_base* j, unsigned size);
re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set(const charT*& first, const charT* last);
re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_aux(re_detail::jstack<traits_string_type, Allocator>& singles, re_detail::jstack<traits_string_type, Allocator>& ranges, re_detail::jstack<boost::uint_fast32_t, Allocator>& classes, re_detail::jstack<traits_string_type, Allocator>& equivalents, bool isnot, const re_detail::_narrow_type&);
re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_aux(re_detail::jstack<traits_string_type, Allocator>& singles, re_detail::jstack<traits_string_type, Allocator>& ranges, re_detail::jstack<boost::uint_fast32_t, Allocator>& classes, re_detail::jstack<traits_string_type, Allocator>& equivalents, bool isnot, const re_detail::_wide_type&);
re_detail::re_syntax_base* BOOST_REGEX_CALL compile_set_simple(re_detail::re_syntax_base* dat, unsigned long cls, bool isnot = false);
unsigned int BOOST_REGEX_CALL parse_inner_set(const charT*& first, const charT* last);
re_detail::re_syntax_base* BOOST_REGEX_CALL add_simple(re_detail::re_syntax_base* dat, re_detail::syntax_element_type type, unsigned int size = sizeof(re_detail::re_syntax_base));
re_detail::re_syntax_base* BOOST_REGEX_CALL add_literal(re_detail::re_syntax_base* dat, charT c);
charT BOOST_REGEX_CALL parse_escape(const charT*& first, const charT* last);
void BOOST_REGEX_CALL parse_range(const charT*& first, const charT* last, unsigned& min, unsigned& max);
bool BOOST_REGEX_CALL skip_space(const charT*& first, const charT* last);
unsigned int BOOST_REGEX_CALL probe_restart(re_detail::re_syntax_base* dat);
unsigned int BOOST_REGEX_CALL fixup_leading_rep(re_detail::re_syntax_base* dat, re_detail::re_syntax_base* end);
void BOOST_REGEX_CALL fail(unsigned int err);
protected:
static int BOOST_REGEX_CALL repeat_count(const reg_expression& e)
{ return e.repeats; }
static unsigned int BOOST_REGEX_CALL restart_type(const reg_expression& e)
{ return e._restart_type; }
static const re_detail::re_syntax_base* BOOST_REGEX_CALL first(const reg_expression& e)
{ return (const re_detail::re_syntax_base*)e.data.data(); }
static const unsigned char* BOOST_REGEX_CALL get_map(const reg_expression& e)
{ return e.startmap; }
static std::size_t BOOST_REGEX_CALL leading_length(const reg_expression& e)
{ return e._leading_len; }
static const re_detail::kmp_info<charT>* get_kmp(const reg_expression& e)
{ return e.pkmp; }
static bool BOOST_REGEX_CALL can_start(charT c, const unsigned char* _map, unsigned char mask, const re_detail::_wide_type&);
static bool BOOST_REGEX_CALL can_start(charT c, const unsigned char* _map, unsigned char mask, const re_detail::_narrow_type&);
};
template <class charT, class traits, class Allocator >
void swap(reg_expression<charT, traits, Allocator>& a, reg_expression<charT, traits, Allocator>& b)
{
a.swap(b);
}
#ifndef BOOST_NO_STD_LOCALE
template <class charT, class traits, class traits2, class Allocator>
std::basic_ostream<charT, traits>&
operator << (std::basic_ostream<charT, traits>& os,
const reg_expression<charT, traits2, Allocator>& e)
{
return (os << e.str());
}
#else
template <class traits, class Allocator>
std::ostream& operator << (std::ostream& os, const reg_expression<char, traits, Allocator>& e)
{
return (os << e.str());
}
#endif
//
// We want to rename reg_expression basic_regex but maintain
// backwards compatibility, so class basic_regex is just a thin
// wrapper around reg_expression:
//
#ifdef BOOST_REGEX_NO_FWD
template <class charT, class traits = regex_traits<charT>, class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
#else
template <class charT, class traits, class Allocator >
#endif
class basic_regex : public reg_expression<charT, traits, Allocator>
{
public:
typedef typename reg_expression<charT, traits, Allocator>::flag_type flag_type;
typedef typename reg_expression<charT, traits, Allocator>::size_type size_type;
explicit basic_regex(const Allocator& a = Allocator())
: reg_expression<charT, traits, Allocator>(a){}
explicit basic_regex(const charT* p, flag_type f = regex_constants::normal, const Allocator& a = Allocator())
: reg_expression<charT, traits, Allocator>(p,f,a){}
basic_regex(const charT* p1, const charT* p2, flag_type f = regex_constants::normal, const Allocator& a = Allocator())
: reg_expression<charT, traits, Allocator>(p1,p2,f,a){}
basic_regex(const charT* p, size_type len, flag_type f, const Allocator& a = Allocator())
: reg_expression<charT, traits, Allocator>(p,len,f,a){}
basic_regex(const basic_regex& that)
: reg_expression<charT, traits, Allocator>(that){}
~basic_regex(){}
basic_regex& BOOST_REGEX_CALL operator=(const basic_regex& that)
{
this->assign(that);
return *this;
}
basic_regex& BOOST_REGEX_CALL operator=(const charT* ptr)
{
this->assign(ptr);
return *this;
}
#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !(defined(__IBMCPP__) && (__IBMCPP__ <= 502))
template <class ST, class SA>
explicit basic_regex(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal, const Allocator& a = Allocator())
: reg_expression<charT, traits, Allocator>(p,f,a){}
template <class I>
basic_regex(I arg_first, I arg_last, flag_type f = regex_constants::normal, const Allocator& al = Allocator())
: reg_expression<charT, traits, Allocator>(arg_first, arg_last, f, al){}
template <class ST, class SA>
basic_regex& BOOST_REGEX_CALL operator=(const std::basic_string<charT, ST, SA>& p)
{
this->assign(p);
return *this;
}
#else
basic_regex(const std::basic_string<charT>& p, flag_type f = regex_constants::normal, const Allocator& a = Allocator())
: reg_expression<charT, traits, Allocator>(p,f,a){}
basic_regex& BOOST_REGEX_CALL operator=(const std::basic_string<charT>& p)
{
this->assign(p);
return *this;
}
#endif
};
#ifdef BOOST_MSVC

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,197 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE c_regex_traits.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares regular expression traits class that wraps the global C locale.
*/
#ifndef BOOST_C_REGEX_TRAITS_HPP_INCLUDED
#define BOOST_C_REGEX_TRAITS_HPP_INCLUDED
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#ifndef BOOST_REGEX_WORKAROUND_HPP
#include <boost/regex/v4/regex_workaround.hpp>
#endif
#include <cctype>
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std{
using ::strlen; using ::tolower;
}
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost{
template <class charT>
struct c_regex_traits;
template<>
struct BOOST_REGEX_DECL c_regex_traits<char>
{
c_regex_traits(){}
typedef char char_type;
typedef std::size_t size_type;
typedef std::string string_type;
struct locale_type{};
typedef boost::uint32_t char_class_type;
static size_type length(const char_type* p)
{
return (std::strlen)(p);
}
char translate(char c) const
{
return c;
}
char translate_nocase(char c) const
{
return static_cast<char>((std::tolower)(static_cast<unsigned char>(c)));
}
static string_type BOOST_REGEX_CALL transform(const char* p1, const char* p2);
static string_type BOOST_REGEX_CALL transform_primary(const char* p1, const char* p2);
static char_class_type BOOST_REGEX_CALL lookup_classname(const char* p1, const char* p2);
static string_type BOOST_REGEX_CALL lookup_collatename(const char* p1, const char* p2);
static bool BOOST_REGEX_CALL isctype(char, char_class_type);
static int BOOST_REGEX_CALL value(char, int);
locale_type imbue(locale_type l)
{ return l; }
locale_type getloc()const
{ return locale_type(); }
private:
// this type is not copyable:
c_regex_traits(const c_regex_traits&);
c_regex_traits& operator=(const c_regex_traits&);
};
#ifndef BOOST_NO_WREGEX
template<>
struct BOOST_REGEX_DECL c_regex_traits<wchar_t>
{
c_regex_traits(){}
typedef wchar_t char_type;
typedef std::size_t size_type;
typedef std::wstring string_type;
struct locale_type{};
typedef boost::uint32_t char_class_type;
static size_type length(const char_type* p)
{
return (std::wcslen)(p);
}
wchar_t translate(wchar_t c) const
{
return c;
}
wchar_t translate_nocase(wchar_t c) const
{
return (std::towlower)(c);
}
static string_type BOOST_REGEX_CALL transform(const wchar_t* p1, const wchar_t* p2);
static string_type BOOST_REGEX_CALL transform_primary(const wchar_t* p1, const wchar_t* p2);
static char_class_type BOOST_REGEX_CALL lookup_classname(const wchar_t* p1, const wchar_t* p2);
static string_type BOOST_REGEX_CALL lookup_collatename(const wchar_t* p1, const wchar_t* p2);
static bool BOOST_REGEX_CALL isctype(wchar_t, char_class_type);
static int BOOST_REGEX_CALL value(wchar_t, int);
locale_type imbue(locale_type l)
{ return l; }
locale_type getloc()const
{ return locale_type(); }
private:
// this type is not copyable:
c_regex_traits(const c_regex_traits&);
c_regex_traits& operator=(const c_regex_traits&);
};
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
//
// Provide an unsigned short version as well, so the user can link to this
// no matter whether they build with /Zc:wchar_t or not (MSVC specific).
//
template<>
struct BOOST_REGEX_DECL c_regex_traits<unsigned short>
{
c_regex_traits(){}
typedef unsigned short char_type;
typedef std::size_t size_type;
typedef std::basic_string<unsigned short> string_type;
struct locale_type{};
typedef boost::uint32_t char_class_type;
static size_type length(const char_type* p)
{
return (std::wcslen)((const wchar_t*)p);
}
unsigned short translate(unsigned short c) const
{
return c;
}
unsigned short translate_nocase(unsigned short c) const
{
return (std::towlower)((wchar_t)c);
}
static string_type BOOST_REGEX_CALL transform(const unsigned short* p1, const unsigned short* p2);
static string_type BOOST_REGEX_CALL transform_primary(const unsigned short* p1, const unsigned short* p2);
static char_class_type BOOST_REGEX_CALL lookup_classname(const unsigned short* p1, const unsigned short* p2);
static string_type BOOST_REGEX_CALL lookup_collatename(const unsigned short* p1, const unsigned short* p2);
static bool BOOST_REGEX_CALL isctype(unsigned short, char_class_type);
static int BOOST_REGEX_CALL value(unsigned short, int);
locale_type imbue(locale_type l)
{ return l; }
locale_type getloc()const
{ return locale_type(); }
private:
// this type is not copyable:
c_regex_traits(const c_regex_traits&);
c_regex_traits& operator=(const c_regex_traits&);
};
#endif
#endif // BOOST_NO_WREGEX
}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif

View File

@ -42,10 +42,6 @@ public:
typedef unsigned int size_type;
typedef regex_traits<char> base_type;
char BOOST_REGEX_CALL translate(char c, bool)const
{
return static_cast<const regex_traits<char>*>(this)->translate(c, true);
}
};
#ifndef BOOST_NO_WREGEX
@ -58,17 +54,6 @@ public:
typedef unsigned int size_type;
typedef regex_traits<wchar_t> base_type;
wchar_t BOOST_REGEX_CALL translate(wchar_t c, bool)const
{
return static_cast<const regex_traits<wchar_t>*>(this)->translate(c, true);
}
boost::uint_fast32_t BOOST_REGEX_CALL lookup_classname(const wchar_t* first, const wchar_t* last)const
{
boost::uint_fast32_t result = static_cast<const regex_traits<wchar_t>*>(this)->lookup_classname(first, last);
if((result & base_type::char_class_upper) == base_type::char_class_upper)
result |= base_type::char_class_alpha;
return result;
}
};
#endif
} // namespace deprecated

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,13 @@
#include <boost/regex/config.hpp>
#endif
#include <boost/regex/v4/match_flags.hpp>
#include <boost/regex/v4/error_type.hpp>
#ifdef __cplusplus
#include <cstddef>
#else
#include <stddef.h>
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
@ -46,8 +53,12 @@ typedef size_t regsize_t;
typedef struct
{
unsigned int re_magic;
unsigned int re_nsub; /* number of parenthesized subexpressions */
const char* re_endp; /* end pointer for REG_PEND */
#ifdef __cplusplus
std::size_t re_nsub; /* number of parenthesized subexpressions */
#else
size_t re_nsub;
#endif
const char* re_endp; /* end pointer for REG_PEND */
void* guts; /* none of your business :-) */
match_flag_type eflags; /* none of your business :-) */
} regex_tA;
@ -56,7 +67,11 @@ typedef struct
typedef struct
{
unsigned int re_magic;
unsigned int re_nsub; /* number of parenthesized subexpressions */
#ifdef __cplusplus
std::size_t re_nsub; /* number of parenthesized subexpressions */
#else
size_t re_nsub;
#endif
const wchar_t* re_endp; /* end pointer for REG_PEND */
void* guts; /* none of your business :-) */
match_flag_type eflags; /* none of your business :-) */
@ -102,6 +117,39 @@ typedef enum{
REG_STARTEND = 00004
} reg_exec_flags;
//
// POSIX error codes:
//
typedef unsigned reg_error_t;
typedef reg_error_t reg_errcode_t; // backwards compatibility
static const reg_error_t REG_NOERROR = 0; /* Success. */
static const reg_error_t REG_NOMATCH = 1; /* Didn't find a match (for regexec). */
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
static const reg_error_t REG_BADPAT = 2; /* Invalid pattern. */
static const reg_error_t REG_ECOLLATE = 3; /* Undefined collating element. */
static const reg_error_t REG_ECTYPE = 4; /* Invalid character class name. */
static const reg_error_t REG_EESCAPE = 5; /* Trailing backslash. */
static const reg_error_t REG_ESUBREG = 6; /* Invalid back reference. */
static const reg_error_t REG_EBRACK = 7; /* Unmatched left bracket. */
static const reg_error_t REG_EPAREN = 8; /* Parenthesis imbalance. */
static const reg_error_t REG_EBRACE = 9; /* Unmatched \{. */
static const reg_error_t REG_BADBR = 10; /* Invalid contents of \{\}. */
static const reg_error_t REG_ERANGE = 11; /* Invalid range end. */
static const reg_error_t REG_ESPACE = 12; /* Ran out of memory. */
static const reg_error_t REG_BADRPT = 13; /* No preceding re for repetition op. */
static const reg_error_t REG_EEND = 14; /* unexpected end of expression */
static const reg_error_t REG_ESIZE = 15; /* expression too big */
static const reg_error_t REG_ERPAREN = 8; /* = REG_EPAREN : unmatched right parenthesis */
static const reg_error_t REG_EMPTY = 17; /* empty expression */
static const reg_error_t REG_E_MEMORY = 15; /* = REG_ESIZE : out of memory */
static const reg_error_t REG_ECOMPLEXITY = 18; /* complexity too high */
static const reg_error_t REG_ESTACK = 19; /* out of stack space */
static const reg_error_t REG_E_UNKNOWN = 20; /* unknown error */
static const reg_error_t REG_ENOSYS = 20; /* = REG_E_UNKNOWN : Reserved. */
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA*, const char*, int);
BOOST_REGEX_DECL regsize_t BOOST_REGEX_CCALL regerrorA(int, const regex_tA*, char*, regsize_t);
BOOST_REGEX_DECL int BOOST_REGEX_CCALL regexecA(const regex_tA*, const char*, regsize_t, regmatch_t*, int);
@ -128,34 +176,6 @@ BOOST_REGEX_DECL void BOOST_REGEX_CCALL regfreeW(regex_tW*);
#define regex_t regex_tA
#endif
/* regerror() flags */
typedef enum
{
REG_NOERROR = 0, /* Success. */
REG_NOMATCH = 1, /* Didn't find a match (for regexec). */
/* POSIX regcomp return error codes. (In the order listed in the
standard.) */
REG_BADPAT = 2, /* Invalid pattern. */
REG_ECOLLATE = 3, /* Undefined collating element. */
REG_ECTYPE = 4, /* Invalid character class name. */
REG_EESCAPE = 5, /* Trailing backslash. */
REG_ESUBREG = 6, /* Invalid back reference. */
REG_EBRACK = 7, /* Unmatched left bracket. */
REG_EPAREN = 8, /* Parenthesis imbalance. */
REG_EBRACE = 9, /* Unmatched \{. */
REG_BADBR = 10, /* Invalid contents of \{\}. */
REG_ERANGE = 11, /* Invalid range end. */
REG_ESPACE = 12, /* Ran out of memory. */
REG_BADRPT = 13, /* No preceding re for repetition op. */
REG_EEND = 14, /* unexpected end of expression */
REG_ESIZE = 15, /* expression too big */
REG_ERPAREN = 16, /* unmatched right parenthesis */
REG_EMPTY = 17, /* empty expression */
REG_E_MEMORY = REG_ESIZE, /* out of memory */
REG_E_UNKNOWN = 18 /* unknown error */
} reg_errcode_t;
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
@ -165,10 +185,10 @@ typedef enum
} // namespace
#endif
#if defined(__cplusplus)
//
// C++ high level wrapper goes here:
//
#if defined(__cplusplus)
#include <string>
#include <vector>
namespace boost{
@ -248,15 +268,12 @@ public:
std::size_t Position(int i = 0)const;
std::size_t Length(int i = 0)const;
bool Matched(int i = 0)const;
unsigned int Marks()const;
std::size_t Marks()const;
std::string What(int i = 0)const;
std::string operator[](int i)const { return What(i); }
#ifdef __MINGW32__
static const std::size_t npos = ~0u;
#else
static const std::size_t npos;
#endif
friend struct re_detail::pred1;
friend struct re_detail::pred2;
friend struct re_detail::pred3;
@ -271,7 +288,7 @@ public:
#endif
#endif /* include guard */
#endif // include guard

View File

@ -0,0 +1,62 @@
/*
*
* Copyright (c) 2003
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE escape_syntax_type.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares regular expression escape synatx type enumerator.
*/
#ifndef BOOST_REGEX_ERROR_TYPE_HPP
#define BOOST_REGEX_ERROR_TYPE_HPP
#ifdef __cplusplus
namespace boost{
#endif
#ifdef __cplusplus
namespace regex_constants{
enum error_type{
error_ok = 0, // not used
error_no_match = 1, // not used
error_bad_pattern = 2,
error_collate = 3,
error_ctype = 4,
error_escape = 5,
error_backref = 6,
error_brack = 7,
error_paren = 8,
error_brace = 9,
error_badbrace = 10,
error_range = 11,
error_space = 12,
error_badrepeat = 13,
error_end = 14, // not used
error_size = 15,
error_right_paren = 16, // not used
error_empty = 17,
error_complexity = 18,
error_stack = 19,
error_unknown = 20
};
}
}
#endif // __cplusplus
#endif

View File

@ -47,7 +47,7 @@ namespace boost{
# pragma option push -Jgx
# endif
template class BOOST_REGEX_DECL reg_expression< BOOST_REGEX_CHAR_T >;
template class BOOST_REGEX_DECL basic_regex< BOOST_REGEX_CHAR_T >;
# ifndef BOOST_REGEX_INSTANTIATE
# pragma option pop
@ -57,7 +57,7 @@ template class BOOST_REGEX_DECL reg_expression< BOOST_REGEX_CHAR_T >;
# include BOOST_ABI_SUFFIX
#endif
#elif (defined(BOOST_MSVC) && defined(_MSC_EXTENSIONS)) || defined(__GNUC__)
#elif defined(BOOST_MSVC) || defined(BOOST_INTEL) || (defined(__GNUC__) && (__GNUC__ >= 3))
# ifndef BOOST_REGEX_INSTANTIATE
# ifdef __GNUC__
@ -72,7 +72,22 @@ template class BOOST_REGEX_DECL reg_expression< BOOST_REGEX_CHAR_T >;
# pragma warning(disable : 4251 4231 4660)
# endif
template class BOOST_REGEX_DECL reg_expression< BOOST_REGEX_CHAR_T >;
template class BOOST_REGEX_DECL basic_regex< BOOST_REGEX_CHAR_T >;
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
template class BOOST_REGEX_DECL match_results< const BOOST_REGEX_CHAR_T* >;
#endif
#ifndef BOOST_NO_STD_ALLOCATOR
template class BOOST_REGEX_DECL ::boost::re_detail::perl_matcher<BOOST_REGEX_CHAR_T const *, match_results< const BOOST_REGEX_CHAR_T* >::allocator_type, boost::regex_traits<BOOST_REGEX_CHAR_T > >;
#endif
#if !(defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB <= 1))
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
template class BOOST_REGEX_DECL match_results< std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator >;
#endif
#ifndef BOOST_NO_STD_ALLOCATOR
template class BOOST_REGEX_DECL ::boost::re_detail::perl_matcher< std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator, match_results< std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator >::allocator_type, boost::regex_traits<BOOST_REGEX_CHAR_T > >;
#endif
#endif
# ifdef BOOST_MSVC
# pragma warning(pop)

View File

@ -72,6 +72,13 @@ struct regex_iterator_traits<wchar_t*> : pointer_iterator_traits<wchar_t>{};
template<>
struct regex_iterator_traits<const wchar_t*> : const_pointer_iterator_traits<wchar_t>{};
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
template<>
struct regex_iterator_traits<unsigned short*> : pointer_iterator_traits<unsigned short>{};
template<>
struct regex_iterator_traits<const unsigned short*> : const_pointer_iterator_traits<unsigned short>{};
#endif
#if defined(__SGI_STL_PORT) && defined(__STL_DEBUG)
template<>
struct regex_iterator_traits<std::string::iterator> : pointer_iterator_traits<char>{};

View File

@ -23,58 +23,57 @@
# include <boost/cstdint.hpp>
#endif
#include <boost/detail/workaround.hpp>
#ifdef __cplusplus
#include <boost/detail/workaround.hpp>
namespace boost{
namespace regex_constants{
#else
#define BOOST_WORKAROUND(x, y) 1
#endif
typedef enum _match_flags
{
match_default = 0,
match_not_bol = 1, /* first is not start of line*/
match_not_eol = match_not_bol << 1, /* last is not end of line*/
match_not_bob = match_not_eol << 1, /* first is not start of buffer*/
match_not_eob = match_not_bob << 1, /* last is not end of buffer*/
match_not_bow = match_not_eob << 1, /* first is not start of word*/
match_not_eow = match_not_bow << 1, /* last is not end of word*/
match_not_dot_newline = match_not_eow << 1, /* \n is not matched by '.'*/
match_not_dot_null = match_not_dot_newline << 1, /* '\0' is not matched by '.'*/
match_prev_avail = match_not_dot_null << 1, /* *--first is a valid expression*/
match_init = match_prev_avail << 1, /* internal use*/
match_any = match_init << 1, /* don't care what we match*/
match_not_null = match_any << 1, /* string can't be null*/
match_continuous = match_not_null << 1, /* each grep match must continue from*/
/* uninterupted from the previous one*/
match_partial = match_continuous << 1, /* find partial matches*/
match_stop = match_partial << 1, /* stop after first match (grep) V3 only*/
match_not_initial_null = match_stop, /* don't match initial null, V4 only*/
match_all = match_stop << 1, /* must find the whole of input even if match_any is set*/
match_perl = match_all << 1, /* Use perl matching rules*/
match_posix = match_perl << 1, /* Use POSIX matching rules*/
match_nosubs = match_posix << 1, /* don't trap marked subs*/
match_extra = match_nosubs << 1, /* include full capture information for repeated captures*/
match_single_line = match_extra << 1, /* treat text as single line and ignor any \n's when matching ^ and $.*/
match_unused1 = match_single_line << 1, /* unused*/
match_unused2 = match_unused1 << 1, /* unused*/
match_unused3 = match_unused2 << 1, /* unused*/
match_not_bol = 1, // first is not start of line
match_not_eol = match_not_bol << 1, // last is not end of line
match_not_bob = match_not_eol << 1, // first is not start of buffer
match_not_eob = match_not_bob << 1, // last is not end of buffer
match_not_bow = match_not_eob << 1, // first is not start of word
match_not_eow = match_not_bow << 1, // last is not end of word
match_not_dot_newline = match_not_eow << 1, // \n is not matched by '.'
match_not_dot_null = match_not_dot_newline << 1, // '\0' is not matched by '.'
match_prev_avail = match_not_dot_null << 1, // *--first is a valid expression
match_init = match_prev_avail << 1, // internal use
match_any = match_init << 1, // don't care what we match
match_not_null = match_any << 1, // string can't be null
match_continuous = match_not_null << 1, // each grep match must continue from
// uninterupted from the previous one
match_partial = match_continuous << 1, // find partial matches
match_stop = match_partial << 1, // stop after first match (grep) V3 only
match_not_initial_null = match_stop, // don't match initial null, V4 only
match_all = match_stop << 1, // must find the whole of input even if match_any is set
match_perl = match_all << 1, // Use perl matching rules
match_posix = match_perl << 1, // Use POSIX matching rules
match_nosubs = match_posix << 1, // don't trap marked subs
match_extra = match_nosubs << 1, // include full capture information for repeated captures
match_single_line = match_extra << 1, // treat text as single line and ignor any \n's when matching ^ and $.
match_unused1 = match_single_line << 1, // unused
match_unused2 = match_unused1 << 1, // unused
match_unused3 = match_unused2 << 1, // unused
match_max = match_unused3,
format_perl = 0, /* perl style replacement*/
format_default = 0, /* ditto.*/
format_sed = match_max << 1, /* sed style replacement.*/
format_all = format_sed << 1, /* enable all extentions to sytax.*/
format_no_copy = format_all << 1, /* don't copy non-matching segments.*/
format_first_only = format_no_copy << 1, /* Only replace first occurance.*/
format_is_if = format_first_only << 1 /* internal use only.*/
format_perl = 0, // perl style replacement
format_default = 0, // ditto.
format_sed = match_max << 1, // sed style replacement.
format_all = format_sed << 1, // enable all extentions to sytax.
format_no_copy = format_all << 1, // don't copy non-matching segments.
format_first_only = format_no_copy << 1, // Only replace first occurance.
format_is_if = format_first_only << 1, // internal use only.
format_literal = format_is_if << 1 // treat string as a literal
} match_flags;
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) || defined(__SUNPRO_CC)
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
typedef unsigned long match_flag_type;
#else
typedef match_flags match_flag_type;
@ -90,11 +89,11 @@ inline match_flags operator^(match_flags m1, match_flags m2)
inline match_flags operator~(match_flags m1)
{ return static_cast<match_flags>(~static_cast<boost::int32_t>(m1)); }
inline match_flags& operator&=(match_flags& m1, match_flags m2)
{ m1 = static_cast<match_flags>(m1&m2); return m1; }
{ m1 = m1&m2; return m1; }
inline match_flags& operator|=(match_flags& m1, match_flags m2)
{ m1 = static_cast<match_flags>(m1|m2); return m1; }
{ m1 = m1|m2; return m1; }
inline match_flags& operator^=(match_flags& m1, match_flags m2)
{ m1 = static_cast<match_flags>(m1^m2); return m1; }
{ m1 = m1^m2; return m1; }
#endif
#endif
@ -136,6 +135,6 @@ using regex_constants::format_first_only;
//using regex_constants::format_is_if;
} // namespace boost
#endif /* __cplusplus */
#endif /* include guard */
#endif // __cplusplus
#endif // include guard

View File

@ -24,10 +24,12 @@
#endif
namespace boost{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4251 4231 4660)
#endif
template <class BidiIterator
, class Allocator = BOOST_DEFAULT_ALLOCATOR(sub_match<BidiIterator> )
>
template <class BidiIterator, class Allocator>
class match_results
{
private:
@ -73,7 +75,7 @@ public:
// size:
size_type size() const
{ return (m_subs.size() >= 2) ? m_subs.size() - 2 : 0; }
{ return empty() ? 0 : m_subs.size() - 2; }
size_type max_size() const
{ return m_subs.max_size(); }
bool empty() const
@ -94,7 +96,7 @@ public:
const sub_match<BidiIterator>& s = m_subs[sub];
if(s.matched)
{
return boost::re_detail::distance((BidiIterator)(m_base), (BidiIterator)(s.first));
return ::boost::re_detail::distance((BidiIterator)(m_base), (BidiIterator)(s.first));
}
}
return ~static_cast<difference_type>(0);
@ -108,7 +110,7 @@ public:
const sub_match<BidiIterator>& s = m_subs[sub];
if(s.matched)
{
result = s;
result = s.str();
}
}
return result;
@ -134,7 +136,7 @@ public:
}
const_iterator begin() const
{
return (m_subs.size() >= 2) ? (m_subs.begin() + 2) : m_subs.end();
return (m_subs.size() > 2) ? (m_subs.begin() + 2) : m_subs.end();
}
const_iterator end() const
{
@ -151,7 +153,26 @@ public:
string_type format(const string_type& fmt,
match_flag_type flags = format_default) const
{
return regex_format(*this, fmt, flags);
return regex_format<BidiIterator, char_type>(*this, fmt, flags);
}
// format with locale:
template <class OutputIterator, class RegexT>
OutputIterator format(OutputIterator out,
const string_type& fmt,
match_flag_type flags,
const RegexT& re) const
{
return ::boost::re_detail::regex_format_imp(out, *this, fmt.data(), fmt.data() + fmt.size(), flags, re.get_traits());
}
template <class RegexT>
string_type format(const string_type& fmt,
match_flag_type flags,
const RegexT& re) const
{
string_type result;
re_detail::string_out_iterator<string_type> i(result);
::boost::re_detail::regex_format_imp(i, *this, fmt.data(), fmt.data() + fmt.size(), flags, re.get_traits());
return result;
}
allocator_type get_allocator() const
@ -233,6 +254,10 @@ public:
{
m_base = pos;
}
BidiIterator base()const
{
return m_base;
}
void BOOST_REGEX_CALL set_first(BidiIterator i)
{
// set up prefix:
@ -280,13 +305,13 @@ void BOOST_REGEX_CALL match_results<BidiIterator, Allocator>::maybe_assign(const
{
//
// leftmost takes priority over longest:
base1 = boost::re_detail::distance(base, p1->first);
base2 = boost::re_detail::distance(base, p2->first);
base1 = ::boost::re_detail::distance(base, p1->first);
base2 = ::boost::re_detail::distance(base, p2->first);
if(base1 < base2) return;
if(base2 < base1) break;
len1 = boost::re_detail::distance((BidiIterator)p1->first, (BidiIterator)p1->second);
len2 = boost::re_detail::distance((BidiIterator)p2->first, (BidiIterator)p2->second);
len1 = ::boost::re_detail::distance((BidiIterator)p1->first, (BidiIterator)p1->second);
len2 = ::boost::re_detail::distance((BidiIterator)p2->first, (BidiIterator)p2->second);
if((len1 != len2) || ((p1->matched == false) && (p2->matched == true)))
break;
if((p1->matched == true) && (p2->matched == false))
@ -325,6 +350,9 @@ std::ostream& operator << (std::ostream& os,
}
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
} // namespace boost
#ifdef BOOST_HAS_ABI_HEADERS

View File

@ -19,7 +19,9 @@
#define BOOST_REGEX_V4_MEM_BLOCK_CACHE_HPP
#include <new>
#include <boost/regex/v4/regex_synch.hpp>
#ifdef BOOST_HAS_THREADS
#include <boost/regex/pending/static_mutex.hpp>
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
@ -38,6 +40,9 @@ struct mem_block_cache
// this member has to be statically initialsed:
mem_block_node* next;
unsigned cached_blocks;
#ifdef BOOST_HAS_THREADS
boost::static_mutex mut;
#endif
~mem_block_cache()
{
@ -51,7 +56,7 @@ struct mem_block_cache
void* get()
{
#ifdef BOOST_HAS_THREADS
re_detail::cs_guard g(*re_detail::p_re_lock);
boost::static_mutex::scoped_lock g(mut);
#endif
if(next)
{
@ -65,7 +70,7 @@ struct mem_block_cache
void put(void* p)
{
#ifdef BOOST_HAS_THREADS
re_detail::cs_guard g(*re_detail::p_re_lock);
boost::static_mutex::scoped_lock g(mut);
#endif
if(cached_blocks >= BOOST_REGEX_MAX_CACHE_BLOCKS)
{

View File

@ -24,7 +24,37 @@ namespace re_detail{
//
// error checking API:
//
BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex::flag_type ef, match_flag_type mf);
BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type ef, match_flag_type mf);
//
// function can_start:
//
template <class charT>
bool can_start(charT c, const unsigned char* map, unsigned char mask)
{
return ((c < static_cast<charT>(0)) ? true : ((c >= static_cast<charT>(1 << CHAR_BIT)) ? true : map[c] & mask));
}
inline bool can_start(char c, const unsigned char* map, unsigned char mask)
{
return map[(unsigned char)c] & mask;
}
inline bool can_start(signed char c, const unsigned char* map, unsigned char mask)
{
return map[(unsigned char)c] & mask;
}
inline bool can_start(unsigned char c, const unsigned char* map, unsigned char mask)
{
return map[c] & mask;
}
inline bool can_start(unsigned short c, const unsigned char* map, unsigned char mask)
{
return ((c >= (1 << CHAR_BIT)) ? true : map[c] & mask);
}
#if defined(WCHAR_MIN) && (WCHAR_MIN == 0) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
inline bool can_start(wchar_t c, const unsigned char* map, unsigned char mask)
{
return ((c >= (1 << CHAR_BIT)) ? true : map[c] & mask);
}
#endif
//
@ -36,7 +66,9 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex::flag_type ef
// which succeeds when it should not.
//
#ifndef _RWSTD_VER
# define STR_COMP(s,p) s.compare(p)
template <class C, class T, class A>
inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
{ return s.compare(p); }
#else
template <class C, class T, class A>
inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
@ -47,31 +79,43 @@ inline int string_compare(const std::string& s, const char* p)
inline int string_compare(const std::wstring& s, const wchar_t* p)
{ return std::wcscmp(s.c_str(), p); }
#endif
# define STR_COMP(s,p) string_compare(s,p)
#endif
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
template <class Seq, class C>
inline int string_compare(const Seq& s, const C* p)
{
std::size_t i = 0;
while((i < s.size()) && (p[i] == s[i]))
{
++i;
}
return (i == s.size()) ? -p[i] : s[i] - p[i];
}
#endif
# define STR_COMP(s,p) string_compare(s,p)
template<class charT>
inline const charT* re_skip_past_null(const charT* p)
{
while (*p != 0) ++p;
while (*p != static_cast<charT>(0)) ++p;
return ++p;
}
template <class iterator, class charT, class traits_type, class Allocator>
template <class iterator, class charT, class traits_type, class char_classT>
iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
iterator last,
const re_set_long* set_,
const reg_expression<charT, traits_type, Allocator>& e)
const re_set_long<char_classT>* set_,
const regex_data<charT, traits_type>& e, bool icase)
{
const charT* p = reinterpret_cast<const charT*>(set_+1);
iterator ptr;
unsigned int i;
bool icase = e.flags() & regex_constants::icase;
//bool icase = e.m_flags & regex_constants::icase;
if(next == last) return next;
typedef typename traits_type::string_type traits_string_type;
const traits_type& traits_inst = e.get_traits();
const ::boost::regex_traits_wrapper<traits_type>& traits_inst = *(e.m_ptraits);
// dwa 9/13/00 suppress incorrect MSVC warning - it claims this is never
// referenced
@ -82,12 +126,12 @@ iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
for(i = 0; i < set_->csingles; ++i)
{
ptr = next;
if(*p == 0)
if(*p == static_cast<charT>(0))
{
// treat null string as special case:
if(traits_inst.translate(*ptr, icase) != *p)
{
while(*p == 0)++p;
while(*p == static_cast<charT>(0))++p;
continue;
}
return set_->isnot ? next : (ptr == next) ? ++next : ptr;
@ -102,7 +146,7 @@ iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
++ptr;
}
if(*p == 0) // if null we've matched
if(*p == static_cast<charT>(0)) // if null we've matched
return set_->isnot ? next : (ptr == next) ? ++next : ptr;
p = re_skip_past_null(p); // skip null
@ -114,23 +158,25 @@ iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
if(set_->cranges || set_->cequivalents)
{
traits_string_type s2(1, col);
traits_string_type s1;
//
// try and match a range, NB only a single character can match
if(set_->cranges)
{
if((e.flags() & regex_constants::collate) == 0)
s1 = s2;
if((e.m_flags & regex_constants::collate) == 0)
s1.assign(1, col);
else
traits_inst.transform(s1, s2);
{
charT a[2] = { col, charT(0), };
s1 = traits_inst.transform(a, a + 1);
}
for(i = 0; i < set_->cranges; ++i)
{
if(STR_COMP(s1, p) <= 0)
if(STR_COMP(s1, p) >= 0)
{
do{ ++p; }while(*p);
++p;
if(STR_COMP(s1, p) >= 0)
if(STR_COMP(s1, p) <= 0)
return set_->isnot ? next : ++next;
}
else
@ -148,7 +194,8 @@ iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
// try and match an equivalence class, NB only a single character can match
if(set_->cequivalents)
{
traits_inst.transform_primary(s1, s2);
charT a[2] = { col, charT(0), };
s1 = traits_inst.transform_primary(a, a +1);
for(i = 0; i < set_->cequivalents; ++i)
{
if(STR_COMP(s1, p) == 0)
@ -159,47 +206,19 @@ iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
}
}
}
if(traits_inst.is_class(col, set_->cclasses) == true)
if(traits_inst.isctype(col, set_->cclasses) == true)
return set_->isnot ? next : ++next;
return set_->isnot ? ++next : next;
}
template <class charT, class traits, class Allocator>
struct access_t : public reg_expression<charT, traits, Allocator>
{
typedef typename is_byte<charT>::width_type width_type;
typedef reg_expression<charT, traits, Allocator> base_type;
typedef charT char_type;
typedef traits traits_type;
typedef Allocator alloc_type;
static int repeat_count(const base_type& b)
{ return base_type::repeat_count(b); }
static unsigned int restart_type(const base_type& b)
{ return base_type::restart_type(b); }
static const re_syntax_base* first(const base_type& b)
{ return base_type::first(b); }
static const unsigned char* get_map(const base_type& b)
{ return base_type::get_map(b); }
static std::size_t leading_length(const base_type& b)
{ return base_type::leading_length(b); }
static const kmp_info<charT>* get_kmp(const base_type& b)
{ return base_type::get_kmp(b); }
static bool can_start(char_type c, const unsigned char* _map, unsigned char mask)
{
return reg_expression<char_type, traits_type, alloc_type>::can_start(c, _map, mask, width_type());
}
};
template <class BidiIterator>
class repeater_count
{
repeater_count** stack;
repeater_count* next;
int id;
unsigned count; // the number of iterations so far
BidiIterator start_pos; // where the last repeat started
std::size_t count; // the number of iterations so far
BidiIterator start_pos; // where the last repeat started
public:
repeater_count(repeater_count** s)
{
@ -230,10 +249,10 @@ public:
{
*stack = next;
}
unsigned get_count() { return count; }
std::size_t get_count() { return count; }
int get_id() { return id; }
int operator++() { return ++count; }
bool check_null_repeat(const BidiIterator& pos, unsigned max)
std::size_t operator++() { return ++count; }
bool check_null_repeat(const BidiIterator& pos, std::size_t max)
{
// this is called when we are about to start a new repeat,
// if the last one was NULL move our count to max,
@ -268,22 +287,25 @@ enum saved_state_type
saved_state_count = 14
};
template <class BidiIterator, class Allocator, class traits, class Allocator2>
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4251 4231 4660)
#endif
template <class BidiIterator, class Allocator, class traits>
class perl_matcher
{
public:
typedef typename traits::char_type char_type;
typedef perl_matcher<BidiIterator, Allocator, traits, Allocator2> self_type;
typedef perl_matcher<BidiIterator, Allocator, traits> self_type;
typedef bool (self_type::*matcher_proc_type)(void);
typedef access_t<char_type, traits, Allocator2> access;
typedef typename traits::size_type traits_size_type;
typedef typename traits::uchar_type traits_uchar_type;
typedef typename is_byte<char_type>::width_type width_type;
typedef typename regex_iterator_traits<BidiIterator>::difference_type difference_type;
perl_matcher(BidiIterator first, BidiIterator end,
match_results<BidiIterator, Allocator>& what,
const reg_expression<char_type, traits, Allocator2>& e,
const basic_regex<char_type, traits>& e,
match_flag_type f);
bool match();
@ -334,7 +356,12 @@ private:
bool match_char_repeat();
bool match_dot_repeat_fast();
bool match_dot_repeat_slow();
bool backtrack_till_match(unsigned count);
bool match_backstep();
bool match_assert_backref();
bool match_toggle_case();
#ifdef BOOST_REGEX_RECURSIVE
bool backtrack_till_match(std::size_t count);
#endif
// find procs stored in s_find_vtable:
bool find_restart_any();
@ -361,9 +388,9 @@ private:
// where the current search started from, acts as base for $` during grep:
BidiIterator search_base;
// the expression being examined:
const reg_expression<char_type, traits, Allocator2>& re;
const basic_regex<char_type, traits>& re;
// the expression's traits class:
const traits& traits_inst;
const ::boost::regex_traits_wrapper<traits>& traits_inst;
// the next state in the machine being matched:
const re_syntax_base* pstate;
// matching flags in use:
@ -378,10 +405,16 @@ private:
bool m_has_partial_match;
// set to true whenever we get a match:
bool m_has_found_match;
// set to true whenever we're inside an independent sub-expression:
bool m_independent;
// the current repeat being examined:
repeater_count<BidiIterator>* next_count;
// the first repeat being examined (top of linked list):
repeater_count<BidiIterator> rep_obj;
// the mask to pass when matching word boundaries:
typename traits::char_class_type m_word_mask;
// the bitmask to use when determining whether a match_any matches a newline or not:
unsigned char match_any_mask;
#ifdef BOOST_REGEX_NON_RECURSIVE
//
@ -411,7 +444,7 @@ private:
void push_assertion(const re_syntax_base* ps, bool positive);
void push_alt(const re_syntax_base* ps);
void push_repeater_count(int i, repeater_count<BidiIterator>** s);
void push_single_repeat(unsigned c, const re_repeat* r, BidiIterator last_position, int id);
void push_single_repeat(std::size_t c, const re_repeat* r, BidiIterator last_position, int id);
void push_non_greedy_repeat(const re_syntax_base* ps);
@ -426,11 +459,20 @@ private:
unsigned used_block_count;
#endif
// these operations aren't allowed, so are declared private:
perl_matcher& operator=(const perl_matcher&);
perl_matcher(const perl_matcher&);
// these operations aren't allowed, so are declared private,
// bodies are provided to keep explicit-instantiation requests happy:
perl_matcher& operator=(const perl_matcher&)
{
return *this;
}
perl_matcher(const perl_matcher& that)
: m_result(that.m_result), re(that.re), traits_inst(that.traits_inst), rep_obj(0) {}
};
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
} // namespace re_detail
#ifdef BOOST_HAS_ABI_HEADERS

View File

@ -31,14 +31,14 @@
namespace boost{
namespace re_detail{
template <class BidiIterator, class Allocator, class traits, class Allocator2>
perl_matcher<BidiIterator, Allocator, traits, Allocator2>::perl_matcher(BidiIterator first, BidiIterator end,
template <class BidiIterator, class Allocator, class traits>
perl_matcher<BidiIterator, Allocator, traits>::perl_matcher(BidiIterator first, BidiIterator end,
match_results<BidiIterator, Allocator>& what,
const reg_expression<char_type, traits, Allocator2>& e,
const basic_regex<char_type, traits>& e,
match_flag_type f)
: m_result(what), base(first), last(end),
position(first), re(e), traits_inst(e.get_traits()),
next_count(&rep_obj), rep_obj(&next_count)
m_independent(false), next_count(&rep_obj), rep_obj(&next_count)
{
typedef typename regex_iterator_traits<BidiIterator>::iterator_category category;
@ -54,7 +54,9 @@ perl_matcher<BidiIterator, Allocator, traits, Allocator2>::perl_matcher(BidiIter
estimate_max_state_count(static_cast<category*>(0));
if(!(m_match_flags & (match_perl|match_posix)))
{
if((re.flags() & regex_constants::perlex) || (re.flags() & regex_constants::literal))
if((re.flags() & (regbase::main_option_type|regbase::no_perl_ex)) == 0)
m_match_flags |= match_perl;
else if((re.flags() & (regbase::main_option_type|regbase::emacs_ex)) == (regbase::basic_syntax_group|regbase::emacs_ex))
m_match_flags |= match_perl;
else
m_match_flags |= match_posix;
@ -70,32 +72,40 @@ perl_matcher<BidiIterator, Allocator, traits, Allocator2>::perl_matcher(BidiIter
m_stack_base = 0;
m_backup_state = 0;
#endif
// find the value to use for matching word boundaries:
const char_type w = static_cast<char_type>('w');
m_word_mask = traits_inst.lookup_classname(&w, &w+1);
// find bitmask to use for matching '.':
match_any_mask = static_cast<unsigned char>((f & match_not_dot_newline) ? re_detail::test_not_newline : re_detail::test_newline);
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::estimate_max_state_count(std::random_access_iterator_tag*)
template <class BidiIterator, class Allocator, class traits>
void perl_matcher<BidiIterator, Allocator, traits>::estimate_max_state_count(std::random_access_iterator_tag*)
{
static const difference_type k = 100000;
difference_type dist = boost::re_detail::distance(base, last);
traits_size_type states = static_cast<traits_size_type>(re.size());
states *= states;
difference_type lim = (std::numeric_limits<difference_type>::max)() - 100000 - states;
if(dist > (difference_type)(lim / states))
max_state_count = lim;
difference_type lim = ((std::numeric_limits<difference_type>::max)() - k) / states;
if(dist >= lim)
max_state_count = (std::numeric_limits<difference_type>::max)();
else
max_state_count = 100000 + states * dist;
max_state_count = k + states * dist;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::estimate_max_state_count(void*)
template <class BidiIterator, class Allocator, class traits>
void perl_matcher<BidiIterator, Allocator, traits>::estimate_max_state_count(void*)
{
// we don't know how long the sequence is:
max_state_count = BOOST_REGEX_MAX_STATE_COUNT;
}
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::protected_call(
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::protected_call(
protected_proc_type proc)
{
/*
__try{
return (this->*proc)();
}__except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode())
@ -103,24 +113,30 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::protected_call(
reset_stack_guard_page();
}
// we only get here after a stack overflow:
raise_error<traits>(traits_inst, REG_E_MEMORY);
raise_error<traits>(traits_inst, regex_constants::error_size);
// and we never really get here at all:
return false;
*/
::boost::re_detail::concrete_protected_call
<perl_matcher<BidiIterator, Allocator, traits> >
obj(this, proc);
return obj.execute();
}
#endif
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match()
{
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
return protected_call(&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_imp);
return protected_call(&perl_matcher<BidiIterator, Allocator, traits>::match_imp);
#else
return match_imp();
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_imp()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_imp()
{
// initialise our stack if we are non-recursive:
#ifdef BOOST_REGEX_NON_RECURSIVE
@ -158,28 +174,28 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_imp()
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find()
{
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
return protected_call(&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_imp);
return protected_call(&perl_matcher<BidiIterator, Allocator, traits>::find_imp);
#else
return find_imp();
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_imp()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find_imp()
{
static matcher_proc_type const s_find_vtable[7] =
{
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_any,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_word,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_buf,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_prefix,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_lit,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_lit,
&perl_matcher<BidiIterator, Allocator, traits>::find_restart_any,
&perl_matcher<BidiIterator, Allocator, traits>::find_restart_word,
&perl_matcher<BidiIterator, Allocator, traits>::find_restart_line,
&perl_matcher<BidiIterator, Allocator, traits>::find_restart_buf,
&perl_matcher<BidiIterator, Allocator, traits>::match_prefix,
&perl_matcher<BidiIterator, Allocator, traits>::find_restart_lit,
&perl_matcher<BidiIterator, Allocator, traits>::find_restart_lit,
};
// initialise our stack if we are non-recursive:
@ -197,7 +213,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_imp()
// reset our state machine:
position = base;
search_base = base;
pstate = access::first(re);
pstate = re.get_first_state();
m_presult->set_size((m_match_flags & match_nosubs) ? 1 : re.mark_count(), base, last);
m_presult->set_base(base);
m_match_flags |= regex_constants::match_init;
@ -230,7 +246,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_imp()
// find out what kind of expression we have:
unsigned type = (m_match_flags & match_continuous) ?
static_cast<unsigned int>(regbase::restart_continue)
: static_cast<unsigned int>(access::restart_type(re));
: static_cast<unsigned int>(re.get_restart_type());
// call the appropriate search routine:
matcher_proc_type proc = s_find_vtable[type];
@ -249,12 +265,12 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_imp()
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_prefix()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_prefix()
{
m_has_partial_match = false;
m_has_found_match = false;
pstate = access::first(re);
pstate = re.get_first_state();
m_presult->set_first(position);
restart = position;
match_all_states();
@ -282,8 +298,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_prefix()
return m_has_found_match;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_endmark()
{
int index = static_cast<const re_brace*>(pstate)->index;
if(index > 0)
@ -291,7 +307,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark()
if((m_match_flags & match_nosubs) == 0)
m_presult->set_second(position, index);
}
else if(index < 0)
else if((index < 0) && (index != -4))
{
// matched forward lookahead:
pstate = 0;
@ -301,8 +317,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark()
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_literal()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_literal()
{
unsigned int len = static_cast<const re_literal*>(pstate)->length;
const char_type* what = reinterpret_cast<const char_type*>(static_cast<const re_literal*>(pstate) + 1);
@ -318,8 +334,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_literal()
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_start_line()
{
if(position == base)
{
@ -341,13 +357,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line
--t;
if(position != last)
{
if(traits_inst.is_separator(*t) && !((*t == '\r') && (*position == '\n')) )
if(is_separator(*t) && !((*t == static_cast<char_type>('\r')) && (*position == static_cast<char_type>('\n'))) )
{
pstate = pstate->next.p;
return true;
}
}
else if(traits_inst.is_separator(*t))
else if(is_separator(*t))
{
pstate = pstate->next.p;
return true;
@ -355,22 +371,22 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_end_line()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_end_line()
{
if(position != last)
{
if(m_match_flags & match_single_line)
return false;
// we're not yet at the end so *first is always valid:
if(traits_inst.is_separator(*position))
if(is_separator(*position))
{
if((position != base) || (m_match_flags & match_prev_avail))
{
// check that we're not in the middle of \r\n sequence
BidiIterator t(position);
--t;
if((*t == '\r') && (*position == '\n'))
if((*t == static_cast<char_type>('\r')) && (*position == static_cast<char_type>('\n')))
{
return false;
}
@ -387,12 +403,12 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_end_line()
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_wild()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_wild()
{
if(position == last)
return false;
if(traits_inst.is_separator(*position) && (m_match_flags & match_not_dot_newline))
if(is_separator(*position) && ((match_any_mask & static_cast<const re_dot*>(pstate)->mask) == 0))
return false;
if((*position == char_type(0)) && (m_match_flags & match_not_dot_null))
return false;
@ -401,8 +417,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_wild()
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_match()
{
if((m_match_flags & match_not_null) && (position == (*m_presult)[0].first))
return false;
@ -430,17 +446,17 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match()
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_boundary()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_word_boundary()
{
bool b; // indcates whether next character is a word character
if(position != last)
{
// prev and this character must be opposites:
#if defined(BOOST_REGEX_USE_C_LOCALE) && defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ < 95)
b = traits::is_class(*position, traits::char_class_word);
b = traits::isctype(*position, m_word_mask);
#else
b = traits_inst.is_class(*position, traits::char_class_word);
b = traits_inst.isctype(*position, m_word_mask);
#endif
}
else
@ -457,7 +473,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_bound
else
{
--position;
b ^= traits_inst.is_class(*position, traits::char_class_word);
b ^= traits_inst.isctype(*position, m_word_mask);
++position;
}
if(b)
@ -468,13 +484,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_bound
return false; // no match if we get to here...
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_word()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_within_word()
{
if(position == last)
return false;
// both prev and this character must be traits::char_class_word:
if(traits_inst.is_class(*position, traits::char_class_word))
// both prev and this character must be m_word_mask:
if(traits_inst.isctype(*position, m_word_mask))
{
bool b;
if((position == base) && ((m_match_flags & match_prev_avail) == 0))
@ -482,7 +498,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_wor
else
{
--position;
b = traits_inst.is_class(*position, traits::char_class_word);
b = traits_inst.isctype(*position, m_word_mask);
++position;
}
if(b)
@ -494,12 +510,12 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_wor
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_word_start()
{
if(position == last)
return false; // can't be starting a word if we're already at the end of input
if(!traits_inst.is_class(*position, traits::char_class_word))
if(!traits_inst.isctype(*position, m_word_mask))
return false; // next character isn't a word character
if((position == base) && ((m_match_flags & match_prev_avail) == 0))
{
@ -511,7 +527,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start
// otherwise inside buffer:
BidiIterator t(position);
--t;
if(traits_inst.is_class(*t, traits::char_class_word))
if(traits_inst.isctype(*t, m_word_mask))
return false; // previous character not non-word
}
// OK we have a match:
@ -519,14 +535,14 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_end()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_word_end()
{
if((position == base) && ((m_match_flags & match_prev_avail) == 0))
return false; // start of buffer can't be end of word
BidiIterator t(position);
--t;
if(traits_inst.is_class(*t, traits::char_class_word) == false)
if(traits_inst.isctype(*t, m_word_mask) == false)
return false; // previous character wasn't a word character
if(position == last)
@ -537,15 +553,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_end()
else
{
// otherwise inside buffer:
if(traits_inst.is_class(*position, traits::char_class_word))
if(traits_inst.isctype(*position, m_word_mask))
return false; // next character is a word character
}
pstate = pstate->next.p;
return true; // if we fall through to here then we've succeeded
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_start()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_buffer_start()
{
if((position != base) || (m_match_flags & match_not_bob))
return false;
@ -554,8 +570,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_sta
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_end()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_buffer_end()
{
if((position != last) || (m_match_flags & match_not_eob))
return false;
@ -564,8 +580,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_end
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_backref()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_backref()
{
// compare with what we previously matched:
BidiIterator i = (*m_presult)[static_cast<const re_brace*>(pstate)->index].first;
@ -581,13 +597,14 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_backref()
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_long_set()
{
typedef typename traits::char_class_type char_class_type;
// let the traits class do the work:
if(position == last)
return false;
BidiIterator t = re_is_set_member(position, last, static_cast<const re_set_long*>(pstate), re);
BidiIterator t = re_is_set_member(position, last, static_cast<const re_set_long<char_class_type>*>(pstate), re.get_data(), icase);
if(t != position)
{
pstate = pstate->next.p;
@ -597,12 +614,12 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set()
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_set()
{
if(position == last)
return false;
if(static_cast<const re_set*>(pstate)->_map[(traits_uchar_type)traits_inst.translate(*position, icase)])
if(static_cast<const re_set*>(pstate)->_map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
pstate = pstate->next.p;
++position;
@ -611,42 +628,42 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set()
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_jump()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_jump()
{
pstate = static_cast<const re_jump*>(pstate)->alt.p;
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_combining()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_combining()
{
if(position == last)
return false;
if(traits_inst.is_combining(traits_inst.translate(*position, icase)))
if(is_combining(traits_inst.translate(*position, icase)))
return false;
++position;
while((position != last) && traits_inst.is_combining(traits_inst.translate(*position, icase)))
while((position != last) && is_combining(traits_inst.translate(*position, icase)))
++position;
pstate = pstate->next.p;
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_soft_buffer_end()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_soft_buffer_end()
{
if(m_match_flags & match_not_eob)
return false;
BidiIterator p(position);
while((p != last) && traits_inst.is_separator(traits_inst.translate(*p, icase)))++p;
while((p != last) && is_separator(traits_inst.translate(*p, icase)))++p;
if(p != last)
return false;
pstate = pstate->next.p;
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_restart_continue()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_restart_continue()
{
if(position == search_base)
{
@ -656,23 +673,53 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_restart_co
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_any()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_backstep()
{
std::ptrdiff_t maxlen = ::boost::re_detail::distance(search_base, position);
if(maxlen < static_cast<const re_brace*>(pstate)->index)
return false;
std::advance(position, -static_cast<const re_brace*>(pstate)->index);
pstate = pstate->next.p;
return true;
}
template <class BidiIterator, class Allocator, class traits>
inline bool perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref()
{
// return true if marked sub-expression N has been matched:
bool result = (*m_presult)[static_cast<const re_brace*>(pstate)->index].matched;
pstate = pstate->next.p;
return result;
}
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case()
{
// change our case sensitivity:
this->icase = static_cast<const re_case*>(pstate)->icase;
pstate = pstate->next.p;
return true;
}
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find_restart_any()
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
const unsigned char* _map = access::get_map(re);
const unsigned char* _map = re.get_map();
while(true)
{
// skip everything we can't match:
while((position != last) && !access::can_start(*position, _map, (unsigned char)mask_any) )
while((position != last) && !can_start(*position, _map, (unsigned char)mask_any) )
++position;
if(position == last)
{
// run out of characters, try a null match if possible:
if(access::first(re)->can_be_null)
if(re.can_be_null())
return match_prefix();
break;
}
@ -689,29 +736,29 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_any
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_word()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find_restart_word()
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
// do search optimised for word starts:
const unsigned char* _map = access::get_map(re);
const unsigned char* _map = re.get_map();
if((m_match_flags & match_prev_avail) || (position != base))
--position;
else if(match_prefix())
return true;
do
{
while((position != last) && traits_inst.is_class(*position, traits::char_class_word))
while((position != last) && traits_inst.isctype(*position, m_word_mask))
++position;
while((position != last) && !traits_inst.is_class(*position, traits::char_class_word))
while((position != last) && !traits_inst.isctype(*position, m_word_mask))
++position;
if(position == last)
break;
if(access::can_start(*position, _map, (unsigned char)mask_any) )
if(can_start(*position, _map, (unsigned char)mask_any) )
{
if(match_prefix())
return true;
@ -725,28 +772,28 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_wor
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_line()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find_restart_line()
{
// do search optimised for line starts:
const unsigned char* _map = access::get_map(re);
const unsigned char* _map = re.get_map();
if(match_prefix())
return true;
while(position != last)
{
while((position != last) && (*position != '\n'))
while((position != last) && !is_separator(*position))
++position;
if(position == last)
return false;
++position;
if(position == last)
{
if((access::first(re)->can_be_null) && match_prefix())
if(re.can_be_null() && match_prefix())
return true;
return false;
}
if( access::can_start(*position, _map, (unsigned char)mask_any) )
if( can_start(*position, _map, (unsigned char)mask_any) )
{
if(match_prefix())
return true;
@ -758,23 +805,24 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_lin
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_buf()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find_restart_buf()
{
if((position == base) && ((m_match_flags & match_not_bob) == 0))
return match_prefix();
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_lit()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::find_restart_lit()
{
#if 0
if(position == last)
return false; // can't possibly match if we're at the end already
unsigned type = (m_match_flags & match_continuous) ?
static_cast<unsigned int>(regbase::restart_continue)
: static_cast<unsigned int>(access::restart_type(re));
: static_cast<unsigned int>(re.get_restart_type());
const kmp_info<char_type>* info = access::get_kmp(re);
int len = info->len;
@ -823,6 +871,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_lit
std::advance(position, -j);
return match_prefix();
}
#endif
return false;
}

View File

@ -40,10 +40,10 @@ struct saved_state
{
union{
unsigned int id;
// these ensure that this struct gets the same alignment as derived structs:
void* padding1;
std::size_t padding2;
std::ptrdiff_t padding3;
// this padding ensures correct alignment on 64-bit platforms:
std::size_t padding1;
std::ptrdiff_t padding2;
void* padding3;
};
saved_state(unsigned i) : id(i) {}
};
@ -109,44 +109,47 @@ struct save_state_init
template <class BidiIterator>
struct saved_single_repeat : public saved_state
{
unsigned count;
std::size_t count;
const re_repeat* rep;
BidiIterator last_position;
saved_single_repeat(unsigned c, const re_repeat* r, BidiIterator lp, int arg_id)
saved_single_repeat(std::size_t c, const re_repeat* r, BidiIterator lp, int arg_id)
: saved_state(arg_id), count(c), rep(r), last_position(lp){}
};
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_all_states()
{
static matcher_proc_type const s_match_vtable[26] =
static matcher_proc_type const s_match_vtable[29] =
{
(&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat,
(&perl_matcher<BidiIterator, Allocator, traits>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits>::match_match,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_backstep,
&perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case,
};
push_recursion_stopper();
@ -158,8 +161,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states
if(!(this->*proc)())
{
if(state_count > max_state_count)
raise_error(traits_inst, REG_ESPACE);
if((m_match_flags & match_partial) && (position == last))
raise_error(traits_inst, regex_constants::error_space);
if((m_match_flags & match_partial) && (position == last) && (position != search_base))
m_has_partial_match = true;
if(false == unwind(false))
return m_recursive_result;
@ -169,8 +172,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states
return m_recursive_result;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::extend_stack()
template <class BidiIterator, class Allocator, class traits>
void perl_matcher<BidiIterator, Allocator, traits>::extend_stack()
{
if(used_block_count)
{
@ -186,11 +189,11 @@ void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::extend_stack()
m_backup_state = block;
}
else
raise_error(traits_inst, REG_E_MEMORY);
raise_error(traits_inst, regex_constants::error_size);
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_matched_paren(int index, const sub_match<BidiIterator>& sub)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_matched_paren(int index, const sub_match<BidiIterator>& sub)
{
assert(index);
saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
@ -205,8 +208,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_matc
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_recursion_stopper()
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_recursion_stopper()
{
saved_state* pmp = m_backup_state;
--pmp;
@ -220,8 +223,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_recu
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_assertion(const re_syntax_base* ps, bool positive)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_assertion(const re_syntax_base* ps, bool positive)
{
saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
--pmp;
@ -235,8 +238,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_asse
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_alt(const re_syntax_base* ps)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_alt(const re_syntax_base* ps)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
--pmp;
@ -250,8 +253,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_alt(
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_non_greedy_repeat(const re_syntax_base* ps)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_non_greedy_repeat(const re_syntax_base* ps)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
--pmp;
@ -265,8 +268,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_non_
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_repeater_count(int i, repeater_count<BidiIterator>** s)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_repeater_count(int i, repeater_count<BidiIterator>** s)
{
saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
--pmp;
@ -280,8 +283,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_repe
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_single_repeat(unsigned c, const re_repeat* r, BidiIterator last_position, int id)
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::push_single_repeat(std::size_t c, const re_repeat* r, BidiIterator last_position, int id)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
--pmp;
@ -295,8 +298,8 @@ inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::push_sing
m_backup_state = pmp;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
{
int index = static_cast<const re_brace*>(pstate)->index;
switch(index)
@ -316,10 +319,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
case -3:
{
// independent sub-expression, currently this is always recursive:
bool old_independent = m_independent;
m_independent = true;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
bool r = match_all_states();
pstate = next_pstate;
m_independent = old_independent;
#ifdef BOOST_REGEX_MATCH_EXTRA
if(r && (m_match_flags & match_extra))
{
@ -349,6 +355,37 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
#endif
return r;
}
case -4:
{
// conditional expression:
const re_alt* alt = static_cast<const re_alt*>(pstate->next.p);
BOOST_ASSERT(alt->type == syntax_element_alt);
pstate = alt->next.p;
if(pstate->type == syntax_element_assert_backref)
{
if(!match_assert_backref())
pstate = alt->alt.p;
break;
}
else
{
// zero width assertion, have to match this recursively:
BOOST_ASSERT(pstate->type == syntax_element_startmark);
bool negated = static_cast<const re_brace*>(pstate)->index == -2;
BidiIterator saved_position = position;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
bool r = match_all_states();
position = saved_position;
if(negated)
r = !r;
if(r)
pstate = next_pstate;
else
pstate = alt->alt.p;
break;
}
}
default:
{
assert(index > 0);
@ -364,11 +401,11 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_alt()
{
bool take_first, take_second;
const re_jump* jmp = static_cast<const re_jump*>(pstate);
const re_alt* jmp = static_cast<const re_alt*>(pstate);
// find out which of these two alternatives we need to take:
if(position == last)
@ -378,8 +415,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
}
else
{
take_first = access::can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, jmp->_map, (unsigned char)mask_skip);
take_first = can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = can_start(*position, jmp->_map, (unsigned char)mask_skip);
}
if(take_first)
@ -401,8 +438,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
return false; // neither option is possible
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_rep()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -422,8 +459,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
}
else
{
take_first = access::can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, rep->_map, (unsigned char)mask_skip);
take_first = can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = can_start(*position, rep->_map, (unsigned char)mask_skip);
}
if(take_first || (next_count->get_id() != rep->id))
@ -452,7 +489,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
return false;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// try and take the repeat if we can:
if((next_count->get_count() < rep->max) && take_first)
@ -501,8 +539,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow()
{
unsigned count = 0;
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
@ -515,7 +553,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
return false;
++count;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// repeat for as long as we can:
while(count < rep->max)
@ -541,18 +580,21 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_slow_dot);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast()
{
if(m_match_flags & (match_not_dot_newline | match_not_dot_null))
if(m_match_flags & match_not_dot_null)
return match_dot_repeat_slow();
if((static_cast<const re_dot*>(pstate->next.p)->mask & match_any_mask) == 0)
return match_dot_repeat_slow();
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
unsigned count = (std::min)(static_cast<unsigned>(re_detail::distance(position, last)), static_cast<unsigned>(rep->greedy ? rep->max : rep->min));
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
unsigned count = static_cast<unsigned>((std::min)(static_cast<unsigned>(::boost::re_detail::distance(position, last)), static_cast<unsigned>(greedy ? rep->max : rep->min)));
if(rep->min > count)
{
position = last;
@ -560,7 +602,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
}
std::advance(position, count);
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -577,12 +619,12 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_fast_dot);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -594,21 +636,22 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
assert(1 == static_cast<const re_literal*>(rep->next.p)->length);
const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(rep->next.p) + 1);
unsigned count = 0;
std::size_t count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (traits_inst.translate(*position, icase) == what))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
@ -622,7 +665,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -639,7 +682,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_char);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
#ifdef __BORLANDC__
#pragma option pop
@ -649,8 +692,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -661,25 +704,26 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
#endif
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
unsigned count = 0;
std::size_t count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((position != end) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((count < desired) && (position != last) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
@ -689,7 +733,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -706,7 +750,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_short_set);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
#ifdef __BORLANDC__
#pragma option pop
@ -716,8 +760,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -726,27 +770,29 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
typedef typename traits::char_class_type mask_type;
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const re_set_long* set = static_cast<const re_set_long*>(pstate->next.p);
unsigned count = 0;
const re_set_long<mask_type>* set = static_cast<const re_set_long<mask_type>*>(pstate->next.p);
std::size_t count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((std::size_t)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (position != re_is_set_member(position, last, set, re)))
while((position != end) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re)))
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
++count;
@ -756,7 +802,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
{
if((rep->leading) && (count < rep->max))
restart = position;
@ -773,7 +819,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
if(count < rep->max)
push_single_repeat(count, rep, position, saved_state_rep_long_set);
pstate = rep->alt.p;
return (position == last) ? (rep->can_be_null & mask_skip) : access::can_start(*position, rep->_map, mask_skip);
return (position == last) ? (rep->can_be_null & mask_skip) : can_start(*position, rep->_map, mask_skip);
}
#ifdef __BORLANDC__
#pragma option pop
@ -790,25 +836,25 @@ unwinding does in the recursive implementation.
****************************************************************************/
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind(bool have_match)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind(bool have_match)
{
static unwind_proc_type const s_unwind_table[14] =
{
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_recursion_stopper,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_counter,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_block,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_single_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_non_greedy_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_end,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_paren,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_recursion_stopper,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_assertion,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_alt,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_repeater_counter,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_extra_block,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_greedy_single_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_slow_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_fast_dot_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_short_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::unwind_non_greedy_repeat,
};
m_recursive_result = have_match;
@ -828,15 +874,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind(bool have
return pstate ? true : false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_end(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_end(bool)
{
pstate = 0; // nothing left to search
return false; // end of stack nothing more to search
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren(bool have_match)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_paren(bool have_match)
{
saved_matched_paren<BidiIterator>* pmp = static_cast<saved_matched_paren<BidiIterator>*>(m_backup_state);
// restore previous values if no match was found:
@ -858,16 +904,16 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_paren(boo
return true; // keep looking
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_recursion_stopper(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_recursion_stopper(bool)
{
boost::re_detail::inplace_destroy(m_backup_state++);
pstate = 0; // nothing left to search
return false; // end of stack nothing more to search
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_assertion(bool r)
{
saved_assertion<BidiIterator>* pmp = static_cast<saved_assertion<BidiIterator>*>(m_backup_state);
pstate = pmp->pstate;
@ -879,8 +925,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_assertion
return !result; // return false if the assertion was matched to stop search.
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_alt(bool r)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
if(!r)
@ -893,8 +939,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_alt(bool
return r;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_counter(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_repeater_counter(bool)
{
saved_repeater<BidiIterator>* pmp = static_cast<saved_repeater<BidiIterator>*>(m_backup_state);
boost::re_detail::inplace_destroy(pmp++);
@ -902,8 +948,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_repeater_
return true; // keep looking
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_block(bool)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_extra_block(bool)
{
saved_extra_block* pmp = static_cast<saved_extra_block*>(m_backup_state);
void* condemmed = m_stack_base;
@ -914,16 +960,16 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_extra_blo
return true; // keep looking
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
inline void perl_matcher<BidiIterator, Allocator, traits, Allocator2>::destroy_single_repeat()
template <class BidiIterator, class Allocator, class traits>
inline void perl_matcher<BidiIterator, Allocator, traits>::destroy_single_repeat()
{
saved_single_repeat<BidiIterator>* p = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
boost::re_detail::inplace_destroy(p++);
m_backup_state = p;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_single_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_greedy_single_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -935,7 +981,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_si
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
assert(rep->next.p != 0);
assert(rep->alt.p != 0);
@ -953,13 +999,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_si
--position;
--count;
++state_count;
}while(count && !access::can_start(*position, rep->_map, mask_skip));
}while(count && !can_start(*position, rep->_map, mask_skip));
// if we've hit base, destroy this state:
if(count == 0)
{
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -971,8 +1017,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_greedy_si
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_slow_dot_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -984,7 +1030,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
assert(rep->type == syntax_element_dot_rep);
assert(rep->next.p != 0);
assert(rep->alt.p != 0);
@ -1008,7 +1054,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
++count;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1021,7 +1067,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1033,8 +1079,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_fast_dot_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -1046,7 +1092,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
assert(count < rep->max);
position = pmp->last_position;
@ -1059,7 +1105,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
++position;
++count;
++state_count;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
@ -1073,7 +1119,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1085,8 +1131,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_char_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -1098,7 +1144,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
pstate = rep->next.p;
const char_type what = *reinterpret_cast<const char_type*>(static_cast<const re_literal*>(pstate) + 1);
position = pmp->last_position;
@ -1124,7 +1170,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
++ position;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1137,7 +1183,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1149,8 +1195,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_short_set_repeat(bool r)
{
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
@ -1162,7 +1208,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
pstate = rep->next.p;
const unsigned char* map = static_cast<const re_set*>(rep->next.p)->_map;
position = pmp->last_position;
@ -1178,7 +1224,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
// wind forward until we can skip out of the repeat:
do
{
if(!map[(traits_uchar_type)traits_inst.translate(*position, icase)])
if(!map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
// failed repeat match, discard this state and look for another:
destroy_single_repeat();
@ -1188,7 +1234,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
++ position;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1201,7 +1247,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1213,9 +1259,10 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_long_set_repeat(bool r)
{
typedef typename traits::char_class_type mask_type;
saved_single_repeat<BidiIterator>* pmp = static_cast<saved_single_repeat<BidiIterator>*>(m_backup_state);
// if we have a match, just discard this state:
@ -1226,16 +1273,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
}
const re_repeat* rep = pmp->rep;
unsigned count = pmp->count;
std::size_t count = pmp->count;
pstate = rep->next.p;
const re_set_long* set = static_cast<const re_set_long*>(pstate);
const re_set_long<mask_type>* set = static_cast<const re_set_long<mask_type>*>(pstate);
position = pmp->last_position;
assert(rep->type == syntax_element_long_set_rep);
assert(rep->next.p != 0);
assert(rep->alt.p != 0);
assert(rep->next.p->type == syntax_element_long_set);
assert(position != last);
assert(count < rep->max);
if(position != last)
@ -1243,7 +1289,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
// wind forward until we can skip out of the repeat:
do
{
if(position == re_is_set_member(position, last, set, re))
if(position == re_is_set_member(position, last, set, re.get_data(), icase))
{
// failed repeat match, discard this state and look for another:
destroy_single_repeat();
@ -1253,7 +1299,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
++count;
++state_count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}while((count < rep->max) && (position != last) && !can_start(*position, rep->_map, mask_skip));
}
if(position == last)
{
@ -1266,7 +1312,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(!access::can_start(*position, rep->_map, mask_skip))
if(!can_start(*position, rep->_map, mask_skip))
return true;
}
else
@ -1278,8 +1324,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
return false;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_non_greedy_repeat(bool r)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::unwind_non_greedy_repeat(bool r)
{
saved_position<BidiIterator>* pmp = static_cast<saved_position<BidiIterator>*>(m_backup_state);
if(!r)

View File

@ -45,48 +45,51 @@ public:
const sub_match<BidiIterator>& get() { return sub; }
};
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_all_states()
{
static matcher_proc_type const s_match_vtable[26] =
static matcher_proc_type const s_match_vtable[29] =
{
(&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat,
(&perl_matcher<BidiIterator, Allocator, traits>::match_startmark),
&perl_matcher<BidiIterator, Allocator, traits>::match_endmark,
&perl_matcher<BidiIterator, Allocator, traits>::match_literal,
&perl_matcher<BidiIterator, Allocator, traits>::match_start_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_end_line,
&perl_matcher<BidiIterator, Allocator, traits>::match_wild,
&perl_matcher<BidiIterator, Allocator, traits>::match_match,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_boundary,
&perl_matcher<BidiIterator, Allocator, traits>::match_within_word,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_word_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_start,
&perl_matcher<BidiIterator, Allocator, traits>::match_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_set,
&perl_matcher<BidiIterator, Allocator, traits>::match_jump,
&perl_matcher<BidiIterator, Allocator, traits>::match_alt,
&perl_matcher<BidiIterator, Allocator, traits>::match_rep,
&perl_matcher<BidiIterator, Allocator, traits>::match_combining,
&perl_matcher<BidiIterator, Allocator, traits>::match_soft_buffer_end,
&perl_matcher<BidiIterator, Allocator, traits>::match_restart_continue,
(::boost::is_random_access_iterator<BidiIterator>::value ? &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast : &perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow),
&perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat,
&perl_matcher<BidiIterator, Allocator, traits>::match_backstep,
&perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref,
&perl_matcher<BidiIterator, Allocator, traits>::match_toggle_case,
};
if(state_count > max_state_count)
raise_error(traits_inst, REG_ESPACE);
raise_error(traits_inst, regex_constants::error_space);
while(pstate)
{
matcher_proc_type proc = s_match_vtable[pstate->type];
++state_count;
if(!(this->*proc)())
{
if((m_match_flags & match_partial) && (position == last))
if((m_match_flags & match_partial) && (position == last) && (position != search_base))
m_has_partial_match = true;
return 0;
}
@ -94,8 +97,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_all_states
return true;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_startmark()
{
int index = static_cast<const re_brace*>(pstate)->index;
bool r = true;
@ -123,10 +126,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
case -3:
{
// independent sub-expression:
bool old_independent = m_independent;
m_independent = true;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
r = match_all_states();
pstate = next_pstate;
m_independent = old_independent;
#ifdef BOOST_REGEX_MATCH_EXTRA
if(r && (m_match_flags & match_extra))
{
@ -156,6 +162,37 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
#endif
break;
}
case -4:
{
// conditional expression:
const re_alt* alt = static_cast<const re_alt*>(pstate->next.p);
BOOST_ASSERT(alt->type == syntax_element_alt);
pstate = alt->next.p;
if(pstate->type == syntax_element_assert_backref)
{
if(!match_assert_backref())
pstate = alt->alt.p;
break;
}
else
{
// zero width assertion, have to match this recursively:
BOOST_ASSERT(pstate->type == syntax_element_startmark);
bool negated = static_cast<const re_brace*>(pstate)->index == -2;
BidiIterator saved_position = position;
const re_syntax_base* next_pstate = static_cast<const re_jump*>(pstate->next.p)->alt.p->next.p;
pstate = pstate->next.p->next.p;
bool r = match_all_states();
position = saved_position;
if(negated)
r = !r;
if(r)
pstate = next_pstate;
else
pstate = alt->alt.p;
break;
}
}
default:
{
assert(index > 0);
@ -185,11 +222,11 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_startmark(
return r;
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_alt()
{
bool take_first, take_second;
const re_jump* jmp = static_cast<const re_jump*>(pstate);
const re_alt* jmp = static_cast<const re_alt*>(pstate);
// find out which of these two alternatives we need to take:
if(position == last)
@ -199,8 +236,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
}
else
{
take_first = access::can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, jmp->_map, (unsigned char)mask_skip);
take_first = can_start(*position, jmp->_map, (unsigned char)mask_take);
take_second = can_start(*position, jmp->_map, (unsigned char)mask_skip);
}
if(take_first)
@ -230,8 +267,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_alt()
return false; // neither option is possible
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_rep()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -261,8 +298,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
}
else
{
take_first = access::can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = access::can_start(*position, rep->_map, (unsigned char)mask_skip);
take_first = can_start(*position, rep->_map, (unsigned char)mask_take);
take_second = can_start(*position, rep->_map, (unsigned char)mask_skip);
}
if(next_count->get_count() < rep->min)
@ -277,8 +314,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
}
return false;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// try and take the repeat if we can:
if((next_count->get_count() < rep->max) && take_first)
@ -327,8 +364,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_rep()
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_slow()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_slow()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -345,7 +382,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
return false;
++count;
}
if(rep->greedy)
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
if(greedy)
{
// normal repeat:
while(count < rep->max)
@ -387,41 +425,51 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat_fast()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_dot_repeat_fast()
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
if(m_match_flags & (match_not_dot_newline | match_not_dot_null))
if(m_match_flags & match_not_dot_null)
return match_dot_repeat_slow();
if((static_cast<const re_dot*>(pstate->next.p)->mask & match_any_mask) == 0)
return match_dot_repeat_slow();
//
// start by working out how much we can skip:
//
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
unsigned count = (std::min)(static_cast<unsigned>(re_detail::distance(position, last)), (rep->greedy ? rep->max : rep->min));
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4267)
#endif
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t count = (std::min)(static_cast<std::size_t>(::boost::re_detail::distance(position, last)), static_cast<std::size_t>(greedy ? rep->max : rep->min));
if(rep->min > count)
{
position = last;
return false; // not enough text left to match
}
std::advance(position, count);
if((rep->leading) && (count < rep->max) && (rep->greedy))
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
++position;
++count;
}
if((rep->leading) && (count == UINT_MAX))
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
@ -440,8 +488,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_char_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -457,17 +505,18 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((unsigned)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (traits_inst.translate(*position, icase) == what))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
@ -477,19 +526,19 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
if((traits_inst.translate(*position, icase) == what))
{
@ -529,8 +578,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -545,41 +594,42 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((unsigned)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((position != end) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && map[(traits_uchar_type)traits_inst.translate(*position, icase)])
while((count < desired) && (position != last) && map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
if(map[(traits_uchar_type)traits_inst.translate(*position, icase)])
if(map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
@ -599,7 +649,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
if(position == last)
return false;
position = save_pos;
if(map[(traits_uchar_type)traits_inst.translate(*position, icase)])
if(map[static_cast<unsigned char>(traits_inst.translate(*position, icase))])
{
++position;
++count;
@ -617,8 +667,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_repeat()
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::match_long_set_repeat()
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -627,47 +677,49 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
#ifdef __BORLANDC__
#pragma option push -w-8008 -w-8066 -w-8004
#endif
typedef typename traits::char_class_type char_class_type;
const re_repeat* rep = static_cast<const re_repeat*>(pstate);
const re_set_long* set = static_cast<const re_set_long*>(pstate->next.p);
const re_set_long<char_class_type>* set = static_cast<const re_set_long<char_class_type>*>(pstate->next.p);
unsigned count = 0;
//
// start by working out how much we can skip:
//
unsigned desired = rep->greedy ? rep->max : rep->min;
bool greedy = (rep->greedy) && (!(m_match_flags & regex_constants::match_any) || m_independent);
std::size_t desired = greedy ? rep->max : rep->min;
if(::boost::is_random_access_iterator<BidiIterator>::value)
{
BidiIterator end = position;
std::advance(end, (std::min)((unsigned)re_detail::distance(position, last), desired));
std::advance(end, (std::min)((unsigned)::boost::re_detail::distance(position, last), desired));
BidiIterator origin(position);
while((position != end) && (position != re_is_set_member(position, last, set, re)))
while((position != end) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
}
count = (unsigned)re_detail::distance(origin, position);
count = (unsigned)::boost::re_detail::distance(origin, position);
}
else
{
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re)))
while((count < desired) && (position != last) && (position != re_is_set_member(position, last, set, re.get_data(), icase)))
{
++position;
++count;
}
}
if((rep->leading) && (count < rep->max) && (rep->greedy))
if((rep->leading) && (count < rep->max) && greedy)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
if(greedy)
return backtrack_till_match(count - rep->min);
// non-greedy, keep trying till we get a match:
BidiIterator save_pos;
do
{
while((position != last) && (count < rep->max) && !access::can_start(*position, rep->_map, mask_skip))
while((position != last) && (count < rep->max) && !can_start(*position, rep->_map, mask_skip))
{
if(position != re_is_set_member(position, last, set, re))
if(position != re_is_set_member(position, last, set, re.get_data(), icase))
{
++position;
++count;
@ -687,7 +739,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
if(position == last)
return false;
position = save_pos;
if(position != re_is_set_member(position, last, set, re))
if(position != re_is_set_member(position, last, set, re.get_data(), icase))
{
++position;
++count;
@ -705,8 +757,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
#endif
}
template <class BidiIterator, class Allocator, class traits, class Allocator2>
bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::backtrack_till_match(unsigned count)
template <class BidiIterator, class Allocator, class traits>
bool perl_matcher<BidiIterator, Allocator, traits>::backtrack_till_match(std::size_t count)
{
#ifdef BOOST_MSVC
#pragma warning(push)
@ -735,7 +787,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::backtrack_till_m
}
do
{
while(count && !access::can_start(*position, rep->_map, mask_skip))
while(count && !can_start(*position, rep->_map, mask_skip))
{
--position;
--count;

View File

@ -0,0 +1,132 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE: primary_transform.hpp
* VERSION: see <boost/version.hpp>
* DESCRIPTION: Heuristically determines the sort string format in use
* by the current locale.
*/
#ifndef BOOST_REGEX_PRIMARY_TRANSFORM
#define BOOST_REGEX_PRIMARY_TRANSFORM
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost{
namespace re_detail{
enum{
sort_C,
sort_fixed,
sort_delim,
sort_unknown
};
template <class S, class charT>
unsigned count_chars(const S& s, charT c)
{
//
// Count how many occurances of character c occur
// in string s: if c is a delimeter between collation
// fields, then this should be the same value for all
// sort keys:
//
unsigned int count = 0;
for(unsigned pos = 0; pos < s.size(); ++pos)
{
if(s[pos] == c) ++count;
}
return count;
}
template <class traits, class charT>
unsigned find_sort_syntax(const traits* pt, charT* delim)
{
//
// compare 'a' with 'A' to see how similar they are,
// should really use a-accute but we can't portably do that,
//
typedef typename traits::string_type string_type;
typedef typename traits::char_type char_type;
// Suppress incorrect warning for MSVC
(void)pt;
char_type a[2] = {'a', '\0', };
string_type sa(pt->transform(a, a+1));
if(sa == a)
{
*delim = 0;
return sort_C;
}
char_type A[2] = { 'A', '\0', };
string_type sA(pt->transform(A, A+1));
char_type c[2] = { ';', '\0', };
string_type sc(pt->transform(c, c+1));
int pos = 0;
while((pos <= static_cast<int>(sa.size())) && (pos <= static_cast<int>(sA.size())) && (sa[pos] == sA[pos])) ++pos;
--pos;
if(pos < 0)
{
*delim = 0;
return sort_unknown;
}
//
// at this point sa[pos] is either the end of a fixed width field
// or the character that acts as a delimiter:
//
charT maybe_delim = sa[pos];
if((pos != 0) && (count_chars(sa, maybe_delim) == count_chars(sA, maybe_delim)) && (count_chars(sa, maybe_delim) == count_chars(sc, maybe_delim)))
{
*delim = maybe_delim;
return sort_delim;
}
//
// OK doen't look like a delimiter, try for fixed width field:
//
if((sa.size() == sA.size()) && (sa.size() == sc.size()))
{
// note assumes that the fixed width field is less than
// numeric_limits<charT>::max(), should be true for all types
// I can't imagine 127 character fields...
*delim = static_cast<charT>(++pos);
return sort_fixed;
}
//
// don't know what it is:
//
*delim = 0;
return sort_unknown;
}
} // namespace re_detail
} // namespace boost
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif

View File

@ -0,0 +1,65 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE basic_regex_creator.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares template class basic_regex_creator which fills in
* the data members of a regex_data object.
*/
#ifndef BOOST_REGEX_V4_PROTECTED_CALL_HPP
#define BOOST_REGEX_V4_PROTECTED_CALL_HPP
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
namespace boost{
namespace re_detail{
class BOOST_REGEX_DECL abstract_protected_call
{
public:
bool BOOST_REGEX_CALL execute()const;
private:
virtual bool call()const = 0;
};
template <class T>
class concrete_protected_call
: public abstract_protected_call
{
public:
typedef bool (T::*proc_type)();
concrete_protected_call(T* o, proc_type p)
: obj(o), proc(p) {}
private:
virtual bool call()const;
T* obj;
proc_type proc;
};
template <class T>
bool concrete_protected_call<T>::call()const
{
return (obj->*proc)();
}
}
} // namespace boost
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif

View File

@ -33,32 +33,59 @@ class BOOST_REGEX_DECL regbase
public:
enum flag_type_
{
escape_in_lists = 1, // '\' special inside [...]
char_classes = escape_in_lists << 1, // [[:CLASS:]] allowed
intervals = char_classes << 1, // {x,y} allowed
limited_ops = intervals << 1, // all of + ? and | are normal characters
newline_alt = limited_ops << 1, // \n is the same as |
bk_plus_qm = newline_alt << 1, // uses \+ and \?
bk_braces = bk_plus_qm << 1, // uses \{ and \}
bk_parens = bk_braces << 1, // uses \( and \)
bk_refs = bk_parens << 1, // \d allowed
bk_vbar = bk_refs << 1, // uses \|
//
// Divide the flags up into logical groups:
// bits 0-7 indicate main synatx type.
// bits 8-15 indicate syntax subtype.
// bits 16-31 indicate options that are common to all
// regex syntaxes.
// In all cases the default is 0.
//
// Main synatx group:
//
perl_syntax_group = 0, // default
basic_syntax_group = 1, // POSIX basic
literal = 2, // all characters are literals
main_option_type = literal | basic_syntax_group | perl_syntax_group, // everything!
//
// options specific to perl group:
//
no_bk_refs = 1 << 8, // \d not allowed
no_perl_ex = 1 << 9, // disable perl extensions
no_mod_m = 1 << 10, // disable Perl m modifier
mod_x = 1 << 11, // Perl x modifier
mod_s = 1 << 12, // force s modifier on (overrides match_not_dot_newline)
no_mod_s = 1 << 13, // force s modifier off (overrides match_not_dot_newline)
use_except = bk_vbar << 1, // exception on error
failbit = use_except << 1, // error flag
literal = failbit << 1, // all characters are literals
icase = literal << 1, // characters are matched regardless of case
nocollate = 0, // don't use locale specific collation (deprecated)
collate = icase << 1, // use locale specific collation
perlex = collate << 1, // perl extensions
nosubs = perlex << 1, // don't mark sub-expressions
optimize = 0, // not really supported
//
// options specific to basic group:
//
no_char_classes = 1 << 8, // [[:CLASS:]] not allowed
no_intervals = 1 << 9, // {x,y} not allowed
bk_plus_qm = 1 << 10, // uses \+ and \?
bk_vbar = 1 << 11, // use \| for alternatives
emacs_ex = 1 << 12, // enables emacs extensions
basic = char_classes | intervals | limited_ops | bk_braces | bk_parens | bk_refs | collate,
extended = char_classes | intervals | bk_refs | collate,
normal = perlex | escape_in_lists | char_classes | intervals | bk_refs | nocollate,
emacs = bk_braces | bk_parens | bk_refs | bk_vbar,
awk = extended | escape_in_lists,
//
// options common to all groups:
//
no_escape_in_lists = 1 << 16, // '\' not special inside [...]
newline_alt = 1 << 17, // \n is the same as |
no_except = 1 << 18, // no exception on error
failbit = 1 << 19, // error flag
icase = 1 << 20, // characters are matched regardless of case
nocollate = 0, // don't use locale specific collation (deprecated)
collate = 1 << 21, // use locale specific collation
nosubs = 1 << 22, // don't mark sub-expressions
optimize = 0, // not really supported
basic = basic_syntax_group | collate | no_escape_in_lists,
extended = no_bk_refs | collate | no_perl_ex | no_escape_in_lists,
normal = 0,
emacs = basic_syntax_group | collate | emacs_ex | bk_vbar,
awk = no_bk_refs | collate | no_perl_ex,
grep = basic | newline_alt,
egrep = extended | newline_alt,
sed = basic,
@ -80,18 +107,6 @@ public:
restart_fixed_lit = 6,
restart_count = 7
};
flag_type BOOST_REGEX_CALL flags()const
{
return _flags;
}
regbase();
regbase(const regbase& b);
void swap(regbase& that)
{ std::swap(_flags, that._flags); }
protected:
flag_type _flags;
};
//
@ -101,26 +116,24 @@ namespace regex_constants{
enum flag_type_
{
escape_in_lists = ::boost::regbase::escape_in_lists,
char_classes = ::boost::regbase::char_classes,
intervals = ::boost::regbase::intervals,
limited_ops = ::boost::regbase::limited_ops,
newline_alt = ::boost::regbase::newline_alt,
bk_plus_qm = ::boost::regbase::bk_plus_qm,
bk_braces = ::boost::regbase::bk_braces,
bk_parens = ::boost::regbase::bk_parens,
bk_refs = ::boost::regbase::bk_refs,
bk_vbar = ::boost::regbase::bk_vbar,
use_except = ::boost::regbase::use_except,
no_except = ::boost::regbase::no_except,
failbit = ::boost::regbase::failbit,
literal = ::boost::regbase::literal,
icase = ::boost::regbase::icase,
nocollate = ::boost::regbase::nocollate,
collate = ::boost::regbase::collate,
perlex = ::boost::regbase::perlex,
nosubs = ::boost::regbase::nosubs,
optimize = ::boost::regbase::optimize,
bk_plus_qm = ::boost::regbase::bk_plus_qm,
bk_vbar = ::boost::regbase::bk_vbar,
no_intervals = ::boost::regbase::no_intervals,
no_char_classes = ::boost::regbase::no_char_classes,
no_escape_in_lists = ::boost::regbase::no_escape_in_lists,
no_mod_m = ::boost::regbase::no_mod_m,
mod_x = ::boost::regbase::mod_x,
mod_s = ::boost::regbase::mod_s,
no_mod_s = ::boost::regbase::no_mod_s,
basic = ::boost::regbase::basic,
extended = ::boost::regbase::extended,

View File

@ -13,7 +13,7 @@
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares boost::reg_expression<> and associated
* DESCRIPTION: Declares boost::basic_regex<> and associated
* functions and classes. This header is the main
* entry point for the template regex code.
*/
@ -21,42 +21,35 @@
#ifndef BOOST_RE_REGEX_HPP_INCLUDED
#define BOOST_RE_REGEX_HPP_INCLUDED
#ifndef BOOST_RE_CREGEX_HPP
#include <boost/cregex.hpp>
#endif
#ifdef __cplusplus
// what follows is all C++ don't include in C builds!!
#ifdef BOOST_REGEX_DEBUG
# include <iosfwd>
#endif
#include <new>
#include <cstring>
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#ifndef BOOST_REGEX_WORKAROUND_HPP
#include <boost/regex/v4/regex_workaround.hpp>
#endif
#ifndef BOOST_REGEX_FWD_HPP
#include <boost/regex_fwd.hpp>
#endif
#ifndef BOOST_REGEX_STACK_HPP
#include <boost/regex/v4/regex_stack.hpp>
#endif
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
#include <boost/regex/v4/regex_raw_buffer.hpp>
#endif
#ifndef BOOST_REGEX_KMP_HPP
#include <boost/regex/v4/regex_kmp.hpp>
#endif
#ifndef BOOST_RE_PAT_EXCEPT_HPP
#include <boost/regex/pattern_except.hpp>
#endif
#ifndef BOOST_REGEX_TRAITS_HPP
#include <boost/regex/regex_traits.hpp>
#endif
#include <boost/scoped_array.hpp>
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
#include <boost/regex/v4/error_type.hpp>
#endif
#ifndef BOOST_REGEX_V4_MATCH_FLAGS
#include <boost/regex/v4/match_flags.hpp>
#endif
#ifndef BOOST_REGEX_RAW_BUFFER_HPP
#include <boost/regex/v4/regex_raw_buffer.hpp>
#endif
#ifndef BOOST_RE_PAT_EXCEPT_HPP
#include <boost/regex/pattern_except.hpp>
#endif
#ifndef BOOST_REGEX_V4_CHAR_REGEX_TRAITS_HPP
#include <boost/regex/v4/char_regex_traits.hpp>
@ -70,12 +63,15 @@
#ifndef BOOST_REGEX_V4_ITERATOR_TRAITS_HPP
#include <boost/regex/v4/iterator_traits.hpp>
#endif
#ifndef BOOST_REGEX_V4_ITERATOR_TRAITS_HPP
#include <boost/regex/v4/iterator_traits.hpp>
#endif
#ifndef BOOST_REGEX_V4_BASIC_REGEX_HPP
#include <boost/regex/v4/basic_regex.hpp>
#endif
#ifndef BOOST_REGEX_V4_BASIC_REGEX_CREATOR_HPP
#include <boost/regex/v4/basic_regex_creator.hpp>
#endif
#ifndef BOOST_REGEX_V4_BASIC_REGEX_PARSER_HPP
#include <boost/regex/v4/basic_regex_parser.hpp>
#endif
#ifndef BOOST_REGEX_V4_SUB_MATCH_HPP
#include <boost/regex/v4/sub_match.hpp>
#endif
@ -85,10 +81,12 @@
#ifndef BOOST_REGEX_V4_MATCH_RESULTS_HPP
#include <boost/regex/v4/match_results.hpp>
#endif
#ifndef BOOST_REGEX_COMPILE_HPP
#include <boost/regex/v4/regex_compile.hpp>
#ifndef BOOST_REGEX_V4_PROTECTED_CALL_HPP
#include <boost/regex/v4/protected_call.hpp>
#endif
#ifndef BOOST_REGEX_MATCHER_HPP
#include <boost/regex/v4/perl_matcher.hpp>
#endif
//
// template instances:
//
@ -103,7 +101,7 @@
#endif
#ifndef BOOST_NO_WREGEX
#define BOOST_REGEX_CHAR_T boost::regex_wchar_type
#define BOOST_REGEX_CHAR_T wchar_t
#ifdef BOOST_REGEX_WIDE_INSTANTIATE
# define BOOST_REGEX_INSTANTIATE
#endif
@ -114,12 +112,24 @@
#endif
#endif
#if !defined(BOOST_NO_WREGEX) && defined(BOOST_REGEX_HAS_OTHER_WCHAR_T)
#define BOOST_REGEX_CHAR_T unsigned short
#ifdef BOOST_REGEX_US_INSTANTIATE
# define BOOST_REGEX_INSTANTIATE
#endif
#include <boost/regex/v4/instances.hpp>
#undef BOOST_REGEX_CHAR_T
#ifdef BOOST_REGEX_INSTANTIATE
# undef BOOST_REGEX_INSTANTIATE
#endif
#endif
namespace boost{
#ifdef BOOST_REGEX_NO_FWD
typedef reg_expression<char, regex_traits<char>, BOOST_DEFAULT_ALLOCATOR(char)> regex;
typedef basic_regex<char, regex_traits<char> > regex;
#ifndef BOOST_NO_WREGEX
typedef reg_expression<wchar_t, regex_traits<wchar_t>, BOOST_DEFAULT_ALLOCATOR(wchar_t)> wregex;
typedef basic_regex<wchar_t, regex_traits<wchar_t> > wregex;
#endif
#endif
@ -137,6 +147,12 @@ typedef match_results<std::wstring::const_iterator> wsmatch;
#ifndef BOOST_REGEX_V4_REGEX_SEARCH_HPP
#include <boost/regex/v4/regex_search.hpp>
#endif
#ifndef BOOST_REGEX_ITERATOR_HPP
#include <boost/regex/v4/regex_iterator.hpp>
#endif
#ifndef BOOST_REGEX_TOKEN_ITERATOR_HPP
#include <boost/regex/v4/regex_token_iterator.hpp>
#endif
#ifndef BOOST_REGEX_V4_REGEX_GREP_HPP
#include <boost/regex/v4/regex_grep.hpp>
#endif
@ -149,12 +165,6 @@ typedef match_results<std::wstring::const_iterator> wsmatch;
#ifndef BOOST_REGEX_SPLIT_HPP
#include <boost/regex/v4/regex_split.hpp>
#endif
#ifndef BOOST_REGEX_ITERATOR_HPP
#include <boost/regex/v4/regex_iterator.hpp>
#endif
#ifndef BOOST_REGEX_TOKEN_ITERATOR_HPP
#include <boost/regex/v4/regex_token_iterator.hpp>
#endif
#endif // __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_fwd.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Forward declares boost::reg_expression<> and
* DESCRIPTION: Forward declares boost::basic_regex<> and
* associated typedefs.
*/
@ -21,9 +21,8 @@
#define BOOST_REGEX_FWD_HPP_INCLUDED
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/config.hpp>
#include <boost/regex/config.hpp>
#endif
#include <boost/regex/config/allocator.hpp>
//
// define BOOST_REGEX_NO_FWD if this
@ -35,27 +34,32 @@
# endif
#else
//
// If there isn't good enough wide character support then there will
// be no wide character regular expressions:
//
#if (defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_CWCTYPE) || defined(BOOST_NO_STD_WSTRING)) && !defined(BOOST_NO_WREGEX)
# define BOOST_NO_WREGEX
#endif
namespace boost{
template <class charT>
class regex_traits;
class cpp_regex_traits;
template <class charT>
struct c_regex_traits;
template <class charT>
class w32_regex_traits;
template <class charT, class traits = regex_traits<charT>, class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
class reg_expression;
template <class charT, class traits = regex_traits<charT>, class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
#ifdef BOOST_REGEX_USE_WIN32_LOCALE
template <class charT, class implementationT = w32_regex_traits<charT> >
struct regex_traits;
#elif defined(BOOST_REGEX_USE_CPP_LOCALE)
template <class charT, class implementationT = cpp_regex_traits<charT> >
struct regex_traits;
#else
template <class charT, class implementationT = c_regex_traits<charT> >
struct regex_traits;
#endif
template <class charT, class traits = regex_traits<charT> >
class basic_regex;
typedef basic_regex<char, regex_traits<char>, BOOST_DEFAULT_ALLOCATOR(char) > regex;
typedef basic_regex<char, regex_traits<char> > regex;
#ifndef BOOST_NO_WREGEX
typedef basic_regex<wchar_t, regex_traits<wchar_t>, BOOST_DEFAULT_ALLOCATOR(wchar_t) > wregex;
typedef basic_regex<wchar_t, regex_traits<wchar_t> > wregex;
#endif
} // namespace boost

View File

@ -30,21 +30,20 @@ namespace boost{
// regex_grep:
// find all non-overlapping matches within the sequence first last:
//
template <class Predicate, class BidiIterator, class charT, class traits, class Allocator>
template <class Predicate, class BidiIterator, class charT, class traits>
inline unsigned int regex_grep(Predicate foo,
BidiIterator first,
BidiIterator last,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
if(e.flags() & regex_constants::failbit)
return false;
typedef detail::rebind_allocator<sub_match<BidiIterator>, Allocator> binder;
typedef typename binder::type match_allocator_type;
//typedef Allocator match_allocator_type;
match_results<BidiIterator, match_allocator_type> m;
re_detail::perl_matcher<BidiIterator, match_allocator_type, traits, Allocator> matcher(first, last, m, e, flags);
typedef typename match_results<BidiIterator>::allocator_type match_allocator_type;
match_results<BidiIterator> m;
re_detail::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags);
unsigned int count = 0;
while(matcher.find())
{
@ -85,17 +84,17 @@ inline unsigned int regex_grep(Predicate foo,
// this isn't really a partial specialisation, but template function
// overloading - if the compiler doesn't support partial specialisation
// then it really won't support this either:
template <class Predicate, class charT, class Allocator, class traits>
template <class Predicate, class charT, class traits>
inline unsigned int regex_grep(Predicate foo, const charT* str,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_grep(foo, str, str + traits::length(str), e, flags);
}
template <class Predicate, class ST, class SA, class Allocator, class charT, class traits>
template <class Predicate, class ST, class SA, class charT, class traits>
inline unsigned int regex_grep(Predicate foo, const std::basic_string<charT, ST, SA>& s,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_grep(foo, s.begin(), s.end(), e, flags);

View File

@ -29,30 +29,29 @@ namespace boost{
template <class BidirectionalIterator,
class charT,
class traits,
class Allocator>
class traits>
class regex_iterator_implementation
{
typedef basic_regex<charT, traits, Allocator> regex_type;
typedef basic_regex<charT, traits> regex_type;
match_results<BidirectionalIterator> what; // current match
BidirectionalIterator base; // start of sequence
BidirectionalIterator end; // end of sequence
const regex_type* pre; // the expression
const regex_type re; // the expression
match_flag_type flags; // flags for matching
public:
regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
: base(), end(last), pre(p), flags(f){}
: base(), end(last), re(*p), flags(f){}
bool init(BidirectionalIterator first)
{
base = first;
return regex_search(first, end, what, *pre, flags);
return regex_search(first, end, what, re, flags);
}
bool compare(const regex_iterator_implementation& that)
{
if(this == &that) return true;
return (pre == that.pre) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
return (&re.get_data() == &that.re.get_data()) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
}
const match_results<BidirectionalIterator>& get()
{ return what; }
@ -64,17 +63,18 @@ public:
match_flag_type f(flags);
if(!what.length())
f |= regex_constants::match_not_initial_null;
bool result = regex_search(next_start, end, what, *pre, f);
bool result = regex_search(next_start, end, what, re, f);
if(result)
what.set_base(base);
return result;
}
private:
regex_iterator_implementation& operator=(const regex_iterator_implementation&);
};
template <class BidirectionalIterator,
class charT = BOOST_DEDUCED_TYPENAME re_detail::regex_iterator_traits<BidirectionalIterator>::value_type,
class traits = regex_traits<charT>,
class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
class traits = regex_traits<charT> >
class regex_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
@ -86,10 +86,10 @@ class regex_iterator
#endif
{
private:
typedef regex_iterator_implementation<BidirectionalIterator, charT, traits, Allocator> impl;
typedef regex_iterator_implementation<BidirectionalIterator, charT, traits> impl;
typedef shared_ptr<impl> pimpl;
public:
typedef basic_regex<charT, traits, Allocator> regex_type;
typedef basic_regex<charT, traits> regex_type;
typedef match_results<BidirectionalIterator> value_type;
typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
difference_type;
@ -163,6 +163,18 @@ typedef regex_iterator<const wchar_t*> wcregex_iterator;
typedef regex_iterator<std::wstring::const_iterator> wsregex_iterator;
#endif
// make_regex_iterator:
template <class charT, class traits>
inline regex_iterator<const charT*, charT, traits> make_regex_iterator(const charT* p, const basic_regex<charT, traits>& e, regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_iterator<const charT*, charT, traits>(p, p+traits::length(p), e, m);
}
template <class charT, class traits, class ST, class SA>
inline regex_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits> make_regex_iterator(const std::basic_string<charT, ST, SA>& p, const basic_regex<charT, traits>& e, regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits>(p.begin(), p.end(), e, m);
}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif

View File

@ -55,7 +55,7 @@ kmp_info<charT>* kmp_compile(iterator first, iterator last, charT, Trans transla
typedef typename boost::detail::rebind_allocator<char, Allocator>::type atype;
int i, j, m;
i = 0;
m = static_cast<int>(boost::re_detail::distance(first, last));
m = static_cast<int>(::boost::re_detail::distance(first, last));
++m;
unsigned int size = sizeof(kmp_info<charT>) + sizeof(int)*m + sizeof(charT)*m;
--m;

View File

@ -22,14 +22,6 @@
#ifndef BOOST_REGEX_MATCH_HPP
#define BOOST_REGEX_MATCH_HPP
#ifndef BOOST_REGEX_MAX_STATE_COUNT
# define BOOST_REGEX_MAX_STATE_COUNT 100000000
#endif
#include <boost/limits.hpp>
#include <boost/regex/v4/perl_matcher.hpp>
namespace boost{
#ifdef BOOST_HAS_ABI_HEADERS
@ -41,22 +33,22 @@ namespace boost{
// returns true if the specified regular expression matches
// the whole of the input. Fills in what matched in m.
//
template <class BidiIterator, class Allocator, class charT, class traits, class Allocator2>
template <class BidiIterator, class Allocator, class charT, class traits>
bool regex_match(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
re_detail::perl_matcher<BidiIterator, Allocator, traits, Allocator2> matcher(first, last, m, e, flags);
re_detail::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags);
return matcher.match();
}
template <class iterator, class charT, class traits, class Allocator2>
template <class iterator, class charT, class traits>
bool regex_match(iterator first, iterator last,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
match_results<iterator> m;
return regex_match(first, last, m, e, flags);
return regex_match(first, last, m, e, flags | regex_constants::match_any);
}
//
// query_match convenience interfaces:
@ -65,40 +57,40 @@ bool regex_match(iterator first, iterator last,
// this isn't really a partial specialisation, but template function
// overloading - if the compiler doesn't support partial specialisation
// then it really won't support this either:
template <class charT, class Allocator, class traits, class Allocator2>
template <class charT, class Allocator, class traits>
inline bool regex_match(const charT* str,
match_results<const charT*, Allocator>& m,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_match(str, str + traits::length(str), m, e, flags);
}
template <class ST, class SA, class Allocator, class charT, class traits, class Allocator2>
template <class ST, class SA, class Allocator, class charT, class traits>
inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
template <class charT, class traits, class Allocator2>
template <class charT, class traits>
inline bool regex_match(const charT* str,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
match_results<const charT*> m;
return regex_match(str, str + traits::length(str), m, e, flags);
return regex_match(str, str + traits::length(str), m, e, flags | regex_constants::match_any);
}
template <class ST, class SA, class charT, class traits, class Allocator2>
template <class ST, class SA, class charT, class traits>
inline bool regex_match(const std::basic_string<charT, ST, SA>& s,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
typedef typename std::basic_string<charT, ST, SA>::const_iterator iterator;
match_results<iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags);
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
#else // partial ordering
inline bool regex_match(const char* str,
@ -113,8 +105,52 @@ inline bool regex_match(const char* str,
match_flag_type flags = match_default)
{
match_results<const char*> m;
return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const char* str,
cmatch& m,
const basic_regex<char, cpp_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
}
inline bool regex_match(const char* str,
const basic_regex<char, cpp_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
match_results<const char*> m;
return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const char* str,
cmatch& m,
const basic_regex<char, c_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
}
inline bool regex_match(const char* str,
const basic_regex<char, c_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
match_results<const char*> m;
return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
inline bool regex_match(const char* str,
cmatch& m,
const basic_regex<char, w32_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
return regex_match(str, str + regex::traits_type::length(str), m, e, flags);
}
inline bool regex_match(const char* str,
const basic_regex<char, w32_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
match_results<const char*> m;
return regex_match(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
#endif
#ifndef BOOST_NO_WREGEX
inline bool regex_match(const wchar_t* str,
wcmatch& m,
@ -128,8 +164,52 @@ inline bool regex_match(const wchar_t* str,
match_flag_type flags = match_default)
{
match_results<const wchar_t*> m;
return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const wchar_t* str,
wcmatch& m,
const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
}
inline bool regex_match(const wchar_t* str,
const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
match_results<const wchar_t*> m;
return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const wchar_t* str,
wcmatch& m,
const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
}
inline bool regex_match(const wchar_t* str,
const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
match_results<const wchar_t*> m;
return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
inline bool regex_match(const wchar_t* str,
wcmatch& m,
const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
return regex_match(str, str + wregex::traits_type::length(str), m, e, flags);
}
inline bool regex_match(const wchar_t* str,
const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
match_results<const wchar_t*> m;
return regex_match(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
#endif
#endif
inline bool regex_match(const std::string& s,
smatch& m,
@ -143,11 +223,55 @@ inline bool regex_match(const std::string& s,
match_flag_type flags = match_default)
{
match_results<std::string::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const std::string& s,
smatch& m,
const basic_regex<char, cpp_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
inline bool regex_match(const std::string& s,
const basic_regex<char, cpp_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
match_results<std::string::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const std::string& s,
smatch& m,
const basic_regex<char, c_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
inline bool regex_match(const std::string& s,
const basic_regex<char, c_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
match_results<std::string::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
inline bool regex_match(const std::string& s,
smatch& m,
const basic_regex<char, w32_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
inline bool regex_match(const std::string& s,
const basic_regex<char, w32_regex_traits<char> >& e,
match_flag_type flags = match_default)
{
match_results<std::string::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
#endif
#if !defined(BOOST_NO_WREGEX)
inline bool regex_match(const std::basic_string<wchar_t>& s,
wsmatch& m,
match_results<std::basic_string<wchar_t>::const_iterator>& m,
const wregex& e,
match_flag_type flags = match_default)
{
@ -158,8 +282,52 @@ inline bool regex_match(const std::basic_string<wchar_t>& s,
match_flag_type flags = match_default)
{
match_results<std::basic_string<wchar_t>::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const std::basic_string<wchar_t>& s,
match_results<std::basic_string<wchar_t>::const_iterator>& m,
const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
inline bool regex_match(const std::basic_string<wchar_t>& s,
const basic_regex<wchar_t, cpp_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
match_results<std::basic_string<wchar_t>::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
inline bool regex_match(const std::basic_string<wchar_t>& s,
match_results<std::basic_string<wchar_t>::const_iterator>& m,
const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
inline bool regex_match(const std::basic_string<wchar_t>& s,
const basic_regex<wchar_t, c_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
match_results<std::basic_string<wchar_t>::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
inline bool regex_match(const std::basic_string<wchar_t>& s,
match_results<std::basic_string<wchar_t>::const_iterator>& m,
const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
return regex_match(s.begin(), s.end(), m, e, flags);
}
inline bool regex_match(const std::basic_string<wchar_t>& s,
const basic_regex<wchar_t, w32_regex_traits<wchar_t> >& e,
match_flag_type flags = match_default)
{
match_results<std::basic_string<wchar_t>::const_iterator> m;
return regex_match(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
#endif
#endif
#endif

View File

@ -28,40 +28,40 @@ namespace boost{
# include BOOST_ABI_PREFIX
#endif
template <class OutputIterator, class Iterator, class traits, class Allocator, class charT>
template <class OutputIterator, class Iterator, class traits, class charT>
inline OutputIterator regex_merge(OutputIterator out,
Iterator first,
Iterator last,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
const charT* fmt,
match_flag_type flags = match_default)
{
return regex_replace(out, first, last, e, fmt, flags);
}
template <class OutputIterator, class Iterator, class traits, class Allocator, class charT>
template <class OutputIterator, class Iterator, class traits, class charT>
inline OutputIterator regex_merge(OutputIterator out,
Iterator first,
Iterator last,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
const std::basic_string<charT>& fmt,
match_flag_type flags = match_default)
{
return regex_merge(out, first, last, e, fmt.c_str(), flags);
}
template <class traits, class Allocator, class charT>
template <class traits, class charT>
inline std::basic_string<charT> regex_merge(const std::basic_string<charT>& s,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
const charT* fmt,
match_flag_type flags = match_default)
{
return regex_replace(s, e, fmt, flags);
}
template <class traits, class Allocator, class charT>
template <class traits, class charT>
inline std::basic_string<charT> regex_merge(const std::basic_string<charT>& s,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
const std::basic_string<charT>& fmt,
match_flag_type flags = match_default)
{

View File

@ -25,6 +25,8 @@
#include <boost/regex/config.hpp>
#endif
#include <algorithm>
namespace boost{
namespace re_detail{
@ -93,43 +95,33 @@ enum{
//
// class raw_storage
// basically this is a simplified vector<unsigned char>
// this is used by reg_expression for expression storage
// this is used by basic_regex for expression storage
//
template <class Allocator>
class raw_storage
class BOOST_REGEX_DECL raw_storage
{
public:
typedef Allocator allocator_type;
typedef typename boost::detail::rebind_allocator<unsigned char, allocator_type>::type alloc_inst_type;
typedef typename alloc_inst_type::size_type size_type;
typedef typename alloc_inst_type::pointer pointer;
typedef std::size_t size_type;
typedef unsigned char* pointer;
private:
//
// empty member optimisation:
struct alloc_data : public alloc_inst_type
{
typename alloc_inst_type::pointer last;
alloc_data(const Allocator& a) : alloc_inst_type(a){}
} alloc_inst;
pointer start, end;
pointer last, start, end;
public:
raw_storage(const Allocator& a = Allocator());
raw_storage(size_type n, const Allocator& a = Allocator());
raw_storage();
raw_storage(size_type n);
~raw_storage()
{
alloc_inst.deallocate(start, (alloc_inst.last - start));
::operator delete(start);
}
void BOOST_REGEX_CALL resize(size_type n);
void* BOOST_REGEX_CALL extend(size_type n)
{
if(size_type(alloc_inst.last - end) < n)
if(size_type(last - end) < n)
resize(n + (end - start));
register void* result = end;
register pointer result = end;
end += n;
return result;
}
@ -143,7 +135,7 @@ public:
size_type BOOST_REGEX_CALL capacity()
{
return alloc_inst.last - start;
return last - start;
}
void* BOOST_REGEX_CALL data()const
@ -153,7 +145,7 @@ public:
size_type BOOST_REGEX_CALL index(void* ptr)
{
return reinterpret_cast<unsigned char*>(ptr) - reinterpret_cast<unsigned char*>(data());
return static_cast<pointer>(ptr) - static_cast<pointer>(data());
}
void BOOST_REGEX_CALL clear()
@ -164,78 +156,28 @@ public:
void BOOST_REGEX_CALL align()
{
// move end up to a boundary:
end = reinterpret_cast<unsigned char*>(start) + (((reinterpret_cast<unsigned char*>(end) - reinterpret_cast<unsigned char*>(start)) + padding_mask) & ~padding_mask);
end = start + (((end - start) + padding_mask) & ~padding_mask);
}
Allocator BOOST_REGEX_CALL allocator()const;
void swap(raw_storage& that)
{
std::swap(start, that.start);
std::swap(end, that.end);
std::swap(alloc_inst.last, that.alloc_inst.last);
std::swap(static_cast<alloc_inst_type&>(alloc_inst), static_cast<alloc_inst_type&>(that.alloc_inst));
std::swap(last, that.last);
}
};
template <class Allocator>
raw_storage<Allocator>::raw_storage(const Allocator& a)
: alloc_inst(a)
inline raw_storage::raw_storage()
{
start = end = alloc_inst.allocate(1024);
BOOST_REGEX_NOEH_ASSERT(start)
alloc_inst.last = start + 1024;
last = start = end = 0;
}
template <class Allocator>
raw_storage<Allocator>::raw_storage(size_type n, const Allocator& a)
: alloc_inst(a)
inline raw_storage::raw_storage(size_type n)
{
start = end = alloc_inst.allocate(n);
BOOST_REGEX_NOEH_ASSERT(start)
alloc_inst.last = start + n;
start = end = static_cast<pointer>(::operator new(n));
BOOST_REGEX_NOEH_ASSERT(start)
last = start + n;
}
template <class Allocator>
Allocator BOOST_REGEX_CALL raw_storage<Allocator>::allocator()const
{
return alloc_inst;
}
template <class Allocator>
void BOOST_REGEX_CALL raw_storage<Allocator>::resize(size_type n)
{
register size_type newsize = (alloc_inst.last - start) * 2;
register size_type datasize = end - start;
if(newsize < n)
newsize = n;
// extend newsize to WORD/DWORD boundary:
newsize = (newsize + padding_mask) & ~(padding_mask);
// allocate and copy data:
register unsigned char* ptr = alloc_inst.allocate(newsize);
BOOST_REGEX_NOEH_ASSERT(ptr)
std::memcpy(ptr, start, datasize);
// get rid of old buffer:
alloc_inst.deallocate(start, (alloc_inst.last - start));
// and set up pointers:
start = ptr;
end = ptr + datasize;
alloc_inst.last = ptr + newsize;
}
template <class Allocator>
void* BOOST_REGEX_CALL raw_storage<Allocator>::insert(size_type pos, size_type n)
{
jm_assert(pos <= size_type(end - start));
if(size_type(alloc_inst.last - end) < n)
resize(n + (end - start));
register void* result = start + pos;
std::memmove(start + pos + n, start + pos, (end - start) - pos);
end += n;
return result;
}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX

View File

@ -28,34 +28,54 @@ namespace boost{
# include BOOST_ABI_PREFIX
#endif
template <class OutputIterator, class Iterator, class traits, class Allocator, class charT>
template <class OutputIterator, class BidirectionalIterator, class traits, class charT>
OutputIterator regex_replace(OutputIterator out,
Iterator first,
Iterator last,
const reg_expression<charT, traits, Allocator>& e,
BidirectionalIterator first,
BidirectionalIterator last,
const basic_regex<charT, traits>& e,
const charT* fmt,
match_flag_type flags = match_default)
{
Iterator l = first;
re_detail::merge_out_predicate<OutputIterator, Iterator, charT, Allocator, traits> oi(out, l, fmt, flags, e.get_traits());
regex_grep(oi, first, last, e, flags);
return (flags & format_no_copy) ? out : std::copy(l, last, out);
regex_iterator<BidirectionalIterator, charT, traits> i(first, last, e, flags);
regex_iterator<BidirectionalIterator, charT, traits> j;
if(i == j)
{
if(!(flags & regex_constants::format_no_copy))
out = std::copy(first, last, out);
}
else
{
BidirectionalIterator last_m = first;
while(i != j)
{
if(!(flags & regex_constants::format_no_copy))
out = std::copy(i->prefix().first, i->prefix().second, out);
out = i->format(out, fmt, flags, e);
last_m = (*i)[0].second;
if(flags & regex_constants::format_first_only)
break;
++i;
}
if(!(flags & regex_constants::format_no_copy))
out = std::copy(last_m, last, out);
}
return out;
}
template <class OutputIterator, class Iterator, class traits, class Allocator, class charT>
template <class OutputIterator, class Iterator, class traits, class charT>
inline OutputIterator regex_replace(OutputIterator out,
Iterator first,
Iterator last,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
const std::basic_string<charT>& fmt,
match_flag_type flags = match_default)
{
return regex_replace(out, first, last, e, fmt.c_str(), flags);
}
template <class traits, class Allocator, class charT>
template <class traits, class charT>
std::basic_string<charT> regex_replace(const std::basic_string<charT>& s,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
const charT* fmt,
match_flag_type flags = match_default)
{
@ -65,9 +85,9 @@ std::basic_string<charT> regex_replace(const std::basic_string<charT>& s,
return result;
}
template <class traits, class Allocator, class charT>
template <class traits, class charT>
std::basic_string<charT> regex_replace(const std::basic_string<charT>& s,
const reg_expression<charT, traits, Allocator>& e,
const basic_regex<charT, traits>& e,
const std::basic_string<charT>& fmt,
match_flag_type flags = match_default)
{

View File

@ -26,16 +26,16 @@ namespace boost{
# include BOOST_ABI_PREFIX
#endif
template <class BidiIterator, class Allocator, class charT, class traits, class Allocator2>
template <class BidiIterator, class Allocator, class charT, class traits>
bool regex_search(BidiIterator first, BidiIterator last,
match_results<BidiIterator, Allocator>& m,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
if(e.flags() & regex_constants::failbit)
return false;
re_detail::perl_matcher<BidiIterator, Allocator, traits, Allocator2> matcher(first, last, m, e, flags);
re_detail::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags);
return matcher.find();
}
@ -46,24 +46,24 @@ bool regex_search(BidiIterator first, BidiIterator last,
// this isn't really a partial specialisation, but template function
// overloading - if the compiler doesn't support partial specialisation
// then it really won't support this either:
template <class charT, class Allocator, class traits, class Allocator2>
template <class charT, class Allocator, class traits>
inline bool regex_search(const charT* str,
match_results<const charT*, Allocator>& m,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_search(str, str + traits::length(str), m, e, flags);
}
template <class ST, class SA, class Allocator, class charT, class traits, class Allocator2>
template <class ST, class SA, class Allocator, class charT, class traits>
inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_search(s.begin(), s.end(), m, e, flags);
}
#else // partial specialisation
#else // partial overloads:
inline bool regex_search(const char* str,
cmatch& m,
const regex& e,
@ -71,6 +71,14 @@ inline bool regex_search(const char* str,
{
return regex_search(str, str + regex::traits_type::length(str), m, e, flags);
}
inline bool regex_search(const char* first, const char* last,
const regex& e,
match_flag_type flags = match_default)
{
cmatch m;
return regex_search(first, last, m, e, flags | regex_constants::match_any);
}
#ifndef BOOST_NO_WREGEX
inline bool regex_search(const wchar_t* str,
wcmatch& m,
@ -79,6 +87,13 @@ inline bool regex_search(const wchar_t* str,
{
return regex_search(str, str + wregex::traits_type::length(str), m, e, flags);
}
inline bool regex_search(const wchar_t* first, const wchar_t* last,
const wregex& e,
match_flag_type flags = match_default)
{
wcmatch m;
return regex_search(first, last, m, e, flags | regex_constants::match_any);
}
#endif
inline bool regex_search(const std::string& s,
smatch& m,
@ -99,9 +114,9 @@ inline bool regex_search(const std::basic_string<wchar_t>& s,
#endif
template <class BidiIterator, class charT, class traits, class Allocator2>
template <class BidiIterator, class charT, class traits>
bool regex_search(BidiIterator first, BidiIterator last,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
if(e.flags() & regex_constants::failbit)
@ -109,51 +124,34 @@ bool regex_search(BidiIterator first, BidiIterator last,
match_results<BidiIterator> m;
typedef typename match_results<BidiIterator>::allocator_type match_alloc_type;
re_detail::perl_matcher<BidiIterator, match_alloc_type, traits, Allocator2> matcher(first, last, m, e, flags);
re_detail::perl_matcher<BidiIterator, match_alloc_type, traits> matcher(first, last, m, e, flags | regex_constants::match_any);
return matcher.find();
}
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template <class charT, class traits, class Allocator2>
template <class charT, class traits>
inline bool regex_search(const charT* str,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_search(str, str + traits::length(str), e, flags);
}
template <class ST, class SA, class charT, class traits, class Allocator2>
template <class ST, class SA, class charT, class traits>
inline bool regex_search(const std::basic_string<charT, ST, SA>& s,
const reg_expression<charT, traits, Allocator2>& e,
const basic_regex<charT, traits>& e,
match_flag_type flags = match_default)
{
return regex_search(s.begin(), s.end(), e, flags);
}
#else // non-template function overloads
inline bool regex_search(const char* first, const char* last,
const regex& e,
match_flag_type flags = match_default)
{
cmatch m;
return regex_search(first, last, m, e, flags);
}
#ifndef BOOST_NO_WREGEX
inline bool regex_search(const wchar_t* first, const wchar_t* last,
const wregex& e,
match_flag_type flags = match_default)
{
wcmatch m;
return regex_search(first, last, m, e, flags);
}
#endif
inline bool regex_search(const char* str,
const regex& e,
match_flag_type flags = match_default)
{
cmatch m;
return regex_search(str, str + regex::traits_type::length(str), m, e, flags);
return regex_search(str, str + regex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
#ifndef BOOST_NO_WREGEX
inline bool regex_search(const wchar_t* str,
@ -161,7 +159,7 @@ inline bool regex_search(const wchar_t* str,
match_flag_type flags = match_default)
{
wcmatch m;
return regex_search(str, str + wregex::traits_type::length(str), m, e, flags);
return regex_search(str, str + wregex::traits_type::length(str), m, e, flags | regex_constants::match_any);
}
#endif
inline bool regex_search(const std::string& s,
@ -169,7 +167,7 @@ inline bool regex_search(const std::string& s,
match_flag_type flags = match_default)
{
smatch m;
return regex_search(s.begin(), s.end(), m, e, flags);
return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
#if !defined(BOOST_NO_WREGEX)
inline bool regex_search(const std::basic_string<wchar_t>& s,
@ -177,11 +175,12 @@ inline bool regex_search(const std::basic_string<wchar_t>& s,
match_flag_type flags = match_default)
{
wsmatch m;
return regex_search(s.begin(), s.end(), m, e, flags);
return regex_search(s.begin(), s.end(), m, e, flags | regex_constants::match_any);
}
#endif
#endif
#endif // BOOST_NO_WREGEX
#endif // partial overload
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX

View File

@ -30,14 +30,14 @@ namespace boost{
namespace re_detail{
template <class charT>
const reg_expression<charT>& get_default_expression(charT)
const basic_regex<charT>& get_default_expression(charT)
{
static const charT expression_text[4] = { '\\', 's', '+', '\00', };
static const reg_expression<charT> e(expression_text);
static const basic_regex<charT> e(expression_text);
return e;
}
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Alloc2>
template <class OutputIterator, class charT, class Traits1, class Alloc1>
class split_pred
{
typedef std::basic_string<charT, Traits1, Alloc1> string_type;
@ -50,12 +50,12 @@ public:
split_pred(iterator_type* a, OutputIterator* b, std::size_t* c)
: p_last(a), p_out(b), p_max(c), initial_max(*c) {}
bool operator()(const match_results<iterator_type, Alloc2>& what);
bool operator()(const match_results<iterator_type>& what);
};
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Alloc2>
bool split_pred<OutputIterator, charT, Traits1, Alloc1, Alloc2>::operator()
(const match_results<iterator_type, Alloc2>& what)
template <class OutputIterator, class charT, class Traits1, class Alloc1>
bool split_pred<OutputIterator, charT, Traits1, Alloc1>::operator()
(const match_results<iterator_type>& what)
{
*p_last = what[0].second;
if(what.size() > 1)
@ -63,7 +63,7 @@ bool split_pred<OutputIterator, charT, Traits1, Alloc1, Alloc2>::operator()
// output sub-expressions only:
for(unsigned i = 1; i < what.size(); ++i)
{
*(*p_out) = static_cast<string_type>(what[i]);
*(*p_out) = what.str(i);
++(*p_out);
if(0 == --*p_max) return false;
}
@ -75,7 +75,7 @@ bool split_pred<OutputIterator, charT, Traits1, Alloc1, Alloc2>::operator()
const sub_match<iterator_type>& sub = what[-1];
if((sub.first != sub.second) || (*p_max != initial_max))
{
*(*p_out) = static_cast<string_type>(sub);
*(*p_out) = sub.str();
++(*p_out);
return --*p_max;
}
@ -87,18 +87,18 @@ bool split_pred<OutputIterator, charT, Traits1, Alloc1, Alloc2>::operator()
} // namespace re_detail
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2, class Alloc2>
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2>
std::size_t regex_split(OutputIterator out,
std::basic_string<charT, Traits1, Alloc1>& s,
const reg_expression<charT, Traits2, Alloc2>& e,
const basic_regex<charT, Traits2>& e,
match_flag_type flags,
std::size_t max_split)
{
typedef typename std::basic_string<charT, Traits1, Alloc1>::const_iterator ci_t;
typedef typename detail::rebind_allocator<sub_match<ci_t>, Alloc2>::type match_allocator;
typedef typename std::basic_string<charT, Traits1, Alloc1>::const_iterator ci_t;
typedef typename match_results<ci_t>::allocator_type match_allocator;
ci_t last = s.begin();
std::size_t init_size = max_split;
re_detail::split_pred<OutputIterator, charT, Traits1, Alloc1, match_allocator> pred(&last, &out, &max_split);
re_detail::split_pred<OutputIterator, charT, Traits1, Alloc1> pred(&last, &out, &max_split);
ci_t i, j;
i = s.begin();
j = s.end();
@ -122,10 +122,10 @@ std::size_t regex_split(OutputIterator out,
return init_size - max_split;
}
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2, class Alloc2>
template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2>
inline std::size_t regex_split(OutputIterator out,
std::basic_string<charT, Traits1, Alloc1>& s,
const reg_expression<charT, Traits2, Alloc2>& e,
const basic_regex<charT, Traits2>& e,
match_flag_type flags = match_default)
{
return regex_split(out, s, e, flags, UINT_MAX);

View File

@ -177,7 +177,7 @@ void BOOST_REGEX_CALL jstack<T, Allocator>::pop_aux()const
{
// make sure that we have a valid item
// on TOS:
jm_assert(m_stack->next);
BOOST_ASSERT(m_stack->next);
register node* p = m_stack;
m_stack = p->next;
p->next = unused;

View File

@ -1,210 +0,0 @@
/*
*
* Copyright (c) 1998-2002
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_synch.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Thread synchronisation for regex code.
* Note this is an internal header file included
* by regex.hpp, do not include on its own.
*/
#ifndef BOOST_REGEX_SYNCH_HPP
#define BOOST_REGEX_SYNCH_HPP
#ifndef BOOST_REGEX_CONFIG_HPP
#include <boost/regex/config.hpp>
#endif
#if defined(BOOST_HAS_THREADS)
# if defined(BOOST_HAS_WINTHREADS)
# include <windows.h>
# elif defined(BOOST_HAS_BETHREADS)
# include <OS.h>
# include <cassert>
# elif defined(BOOST_HAS_PTHREADS)
# include <pthread.h>
# else
# error "Unknown threading API"
# endif
#endif
namespace boost{
namespace re_detail{
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
void BOOST_REGEX_CALL re_init_threads();
void BOOST_REGEX_CALL re_free_threads();
#ifdef BOOST_HAS_THREADS
# ifdef BOOST_HAS_BETHREADS
typedef sem_id CRITICAL_SECTION;
inline void BOOST_REGEX_CALL InitializeCriticalSection(CRITICAL_SECTION* ps)
{
*ps = create_sem(1, "regex++");
assert(*ps > 0);
}
inline void BOOST_REGEX_CALL DeleteCriticalSection(CRITICAL_SECTION* ps)
{
int t = delete_sem(*ps);
assert(t == B_NO_ERROR);
}
inline void BOOST_REGEX_CALL EnterCriticalSection(CRITICAL_SECTION* ps)
{
status_t t = acquire_sem(*ps);
assert(t == B_NO_ERROR);
}
inline void BOOST_REGEX_CALL LeaveCriticalSection(CRITICAL_SECTION* ps)
{
status_t t = release_sem(*ps);
assert(t == B_NO_ERROR);
}
# elif defined(BOOST_HAS_PTHREADS)
typedef pthread_mutex_t CRITICAL_SECTION;
inline void BOOST_REGEX_CALL InitializeCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_init(ps, 0);
}
inline void BOOST_REGEX_CALL DeleteCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_destroy(ps);
}
inline void BOOST_REGEX_CALL EnterCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_lock(ps);
}
inline void BOOST_REGEX_CALL LeaveCriticalSection(CRITICAL_SECTION* ps)
{
pthread_mutex_unlock(ps);
}
# elif !defined(BOOST_HAS_WINTHREADS)
# error "Unknown threading API"
# endif
template <class Lock>
class lock_guard
{
typedef Lock lock_type;
public:
lock_guard(lock_type& m, bool aq = true)
: mut(m), owned(false){ acquire(aq); }
~lock_guard()
{ acquire(false); }
void BOOST_REGEX_CALL acquire(bool aq = true)
{
if(aq && !owned)
{
mut.acquire(true);
owned = true;
}
else if(!aq && owned)
{
mut.acquire(false);
owned = false;
}
}
private:
lock_type& mut;
bool owned;
// VC6 warning suppression:
lock_guard& operator=(const lock_guard&);
};
class critical_section
{
public:
critical_section()
{ InitializeCriticalSection(&hmutex);}
critical_section(const critical_section&)
{ InitializeCriticalSection(&hmutex);}
const critical_section& BOOST_REGEX_CALL operator=(const critical_section&)
{return *this;}
~critical_section()
{DeleteCriticalSection(&hmutex);}
private:
void BOOST_REGEX_CALL acquire(bool aq)
{ if(aq) EnterCriticalSection(&hmutex);
else LeaveCriticalSection(&hmutex);
}
CRITICAL_SECTION hmutex;
public:
typedef lock_guard<critical_section> ro_guard;
typedef lock_guard<critical_section> rw_guard;
friend class lock_guard<critical_section>;
};
inline bool BOOST_REGEX_CALL operator==(const critical_section&, const critical_section&)
{
return false;
}
inline bool BOOST_REGEX_CALL operator<(const critical_section&, const critical_section&)
{
return true;
}
typedef lock_guard<critical_section> cs_guard;
BOOST_REGEX_DECL extern critical_section* p_re_lock;
BOOST_REGEX_DECL extern unsigned int re_lock_count;
#define BOOST_REGEX_GUARD(inst) boost::re_detail::critical_section::rw_guard g(inst);
#else // BOOST_HAS_THREADS
#define BOOST_REGEX_GUARD(inst)
#endif // BOOST_HAS_THREADS
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
} // namespace re_detail
} // namespace boost
#endif // sentry

View File

@ -23,8 +23,7 @@
#include <boost/detail/workaround.hpp>
#if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
|| BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
|| BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
|| BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))
|| BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
//
// Borland C++ Builder 6, and Visual C++ 6,
// can't cope with the array template constructor
@ -47,16 +46,15 @@ namespace boost{
template <class BidirectionalIterator,
class charT,
class traits,
class Allocator>
class traits>
class regex_token_iterator_implementation
{
typedef basic_regex<charT, traits, Allocator> regex_type;
typedef basic_regex<charT, traits> regex_type;
typedef sub_match<BidirectionalIterator> value_type;
match_results<BidirectionalIterator> what; // current match
BidirectionalIterator end; // end of search area
const regex_type* pre; // the expression
const regex_type re; // the expression
match_flag_type flags; // match flags
value_type result; // the current string result
int N; // the current sub-expression being enumerated
@ -64,16 +62,16 @@ class regex_token_iterator_implementation
public:
regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, int sub, match_flag_type f)
: end(last), pre(p), flags(f){ subs.push_back(sub); }
: end(last), re(*p), flags(f){ subs.push_back(sub); }
regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const std::vector<int>& v, match_flag_type f)
: end(last), pre(p), flags(f), subs(v){}
: end(last), re(*p), flags(f), subs(v){}
#if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
|| BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
|| BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
|| BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))
template <class T>
regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const T& submatches, match_flag_type f)
: end(last), pre(p), flags(f)
: end(last), re(*p), flags(f)
{
// assert that T really is an array:
BOOST_STATIC_ASSERT(::boost::is_array<T>::value);
@ -86,7 +84,7 @@ public:
#else
template <std::size_t CN>
regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const int (&submatches)[CN], match_flag_type f)
: end(last), pre(p), flags(f)
: end(last), re(*p), flags(f)
{
for(std::size_t i = 0; i < CN; ++i)
{
@ -98,7 +96,7 @@ public:
bool init(BidirectionalIterator first)
{
N = 0;
if(regex_search(first, end, what, *pre, flags) == true)
if(regex_search(first, end, what, re, flags) == true)
{
N = 0;
result = ((subs[N] == -1) ? what.prefix() : what[(int)subs[N]]);
@ -116,7 +114,7 @@ public:
bool compare(const regex_token_iterator_implementation& that)
{
if(this == &that) return true;
return (pre == that.pre)
return (&re.get_data() == &that.re.get_data())
&& (end == that.end)
&& (flags == that.flags)
&& (N == that.N)
@ -138,7 +136,7 @@ public:
if(what.prefix().first != what[0].second)
flags |= match_prev_avail;
BidirectionalIterator last_end(what[0].second);
if(regex_search(last_end, end, what, *pre, ((what[0].first == what[0].second) ? flags | regex_constants::match_not_initial_null : flags)))
if(regex_search(last_end, end, what, re, ((what[0].first == what[0].second) ? flags | regex_constants::match_not_initial_null : flags)))
{
N =0;
result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
@ -154,12 +152,13 @@ public:
}
return false;
}
private:
regex_token_iterator_implementation& operator=(const regex_token_iterator_implementation&);
};
template <class BidirectionalIterator,
class charT = BOOST_DEDUCED_TYPENAME re_detail::regex_iterator_traits<BidirectionalIterator>::value_type,
class traits = regex_traits<charT>,
class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
class traits = regex_traits<charT> >
class regex_token_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
@ -171,10 +170,10 @@ class regex_token_iterator
#endif
{
private:
typedef regex_token_iterator_implementation<BidirectionalIterator, charT, traits, Allocator> impl;
typedef regex_token_iterator_implementation<BidirectionalIterator, charT, traits> impl;
typedef shared_ptr<impl> pimpl;
public:
typedef basic_regex<charT, traits, Allocator> regex_type;
typedef basic_regex<charT, traits> regex_type;
typedef sub_match<BidirectionalIterator> value_type;
typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
difference_type;
@ -274,6 +273,39 @@ typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
typedef regex_token_iterator<std::wstring::const_iterator> wsregex_token_iterator;
#endif
template <class charT, class traits>
inline regex_token_iterator<const charT*, charT, traits> make_regex_token_iterator(const charT* p, const basic_regex<charT, traits>& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_token_iterator<const charT*, charT, traits>(p, p+traits::length(p), e, submatch, m);
}
template <class charT, class traits, class ST, class SA>
inline regex_token_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits> make_regex_token_iterator(const std::basic_string<charT, ST, SA>& p, const basic_regex<charT, traits>& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_token_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits>(p.begin(), p.end(), e, submatch, m);
}
#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
template <class charT, class traits, std::size_t N>
inline regex_token_iterator<const charT*, charT, traits> make_regex_token_iterator(const charT* p, const basic_regex<charT, traits>& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_token_iterator<const charT*, charT, traits>(p, p+traits::length(p), e, submatch, m);
}
template <class charT, class traits, class ST, class SA, std::size_t N>
inline regex_token_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits> make_regex_token_iterator(const std::basic_string<charT, ST, SA>& p, const basic_regex<charT, traits>& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_token_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits>(p.begin(), p.end(), e, submatch, m);
}
#endif
template <class charT, class traits>
inline regex_token_iterator<const charT*, charT, traits> make_regex_token_iterator(const charT* p, const basic_regex<charT, traits>& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_token_iterator<const charT*, charT, traits>(p, p+traits::length(p), e, submatch, m);
}
template <class charT, class traits, class ST, class SA>
inline regex_token_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits> make_regex_token_iterator(const std::basic_string<charT, ST, SA>& p, const basic_regex<charT, traits>& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
{
return regex_token_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits>(p.begin(), p.end(), e, submatch, m);
}
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
# pragma warning(pop)
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,288 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_traits_defaults.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares API's for access to regex_traits default properties.
*/
#ifndef BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
#define BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
#ifndef BOOST_REGEX_SYNTAX_TYPE_HPP
#include <boost/regex/v4/syntax_type.hpp>
#endif
#ifndef BOOST_REGEX_ERROR_TYPE_HPP
#include <boost/regex/v4/error_type.hpp>
#endif
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std{
using ::strlen;
}
#endif
namespace boost{ namespace re_detail{
//
// helpers to suppress warnings:
//
template <class charT>
inline bool is_extended(charT c)
{ return c > 256; }
inline bool is_extended(char)
{ return false; }
BOOST_REGEX_DECL const char* BOOST_REGEX_CALL get_default_syntax(regex_constants::syntax_type n);
BOOST_REGEX_DECL const char* BOOST_REGEX_CALL get_default_error_string(regex_constants::error_type n);
BOOST_REGEX_DECL regex_constants::syntax_type BOOST_REGEX_CALL get_default_syntax_type(char c);
BOOST_REGEX_DECL regex_constants::escape_syntax_type BOOST_REGEX_CALL get_default_escape_syntax_type(char c);
// is charT c a combining character?
BOOST_REGEX_DECL bool BOOST_REGEX_CALL is_combining_implementation(uint_least16_t s);
template <class charT>
inline bool is_combining(charT c)
{
return (c < static_cast<charT>(0)) ? false : ((c > static_cast<charT>((std::numeric_limits<uint_least16_t>::max)())) ? false : is_combining_implementation(static_cast<unsigned short>(c)));
}
template <>
inline bool is_combining<char>(char)
{
return false;
}
template <>
inline bool is_combining<signed char>(signed char)
{
return false;
}
template <>
inline bool is_combining<unsigned char>(unsigned char)
{
return false;
}
#ifdef _MSC_VER
template<>
inline bool is_combining<wchar_t>(wchar_t c)
{
return is_combining_implementation(static_cast<unsigned short>(c));
}
#elif !defined(__DECCXX) && defined(WCHAR_MIN) && (WCHAR_MIN == 0) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
#if defined(WCHAR_MAX) && (WCHAR_MAX <= USHRT_MAX)
template<>
inline bool is_combining<wchar_t>(wchar_t c)
{
return is_combining_implementation(static_cast<unsigned short>(c));
}
#else
template<>
inline bool is_combining<wchar_t>(wchar_t c)
{
return (c > (std::numeric_limits<uint_least16_t>::max)()) ? false : is_combining_implementation(static_cast<unsigned short>(c));
}
#endif
#endif
//
// is a charT c a line separator?
//
template <class charT>
inline bool is_separator(charT c)
{
return BOOST_REGEX_MAKE_BOOL(
(c == static_cast<charT>('\n'))
|| (c == static_cast<charT>('\r'))
|| (c == static_cast<charT>('\f'))
|| (static_cast<boost::uint16_t>(c) == 0x2028u)
|| (static_cast<boost::uint16_t>(c) == 0x2029u)
|| (static_cast<boost::uint16_t>(c) == 0x85u));
}
template <>
inline bool is_separator<char>(char c)
{
return BOOST_REGEX_MAKE_BOOL((c == '\n') || (c == '\r') || (c == '\f'));
}
//
// get a default collating element:
//
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL lookup_default_collate_name(const std::string& name);
//
// get the id of a character clasification, the individual
// traits classes then transform that id into a bitmask:
//
template <class charT>
struct character_pointer_range
{
const charT* p1;
const charT* p2;
bool operator < (const character_pointer_range& r)const
{
return std::lexicographical_compare(p1, p2, r.p1, r.p2);
}
bool operator == (const character_pointer_range& r)const
{
return ((p2 - p1) == (r.p2 - r.p1)) && std::equal(p1, p2, r.p1);
}
};
template <class charT>
int get_default_class_id(const charT* p1, const charT* p2)
{
static const charT data[] = {
'a', 'l', 'n', 'u', 'm',
'a', 'l', 'p', 'h', 'a',
'b', 'l', 'a', 'n', 'k',
'c', 'n', 't', 'r', 'l',
'd', 'i', 'g', 'i', 't',
'g', 'r', 'a', 'p', 'h',
'l', 'o', 'w', 'e', 'r',
'p', 'r', 'i', 'n', 't',
'p', 'u', 'n', 'c', 't',
's', 'p', 'a', 'c', 'e',
'u', 'n', 'i', 'c', 'o', 'd', 'e',
'u', 'p', 'p', 'e', 'r',
'w', 'o', 'r', 'd',
'x', 'd', 'i', 'g', 'i', 't',
};
static const character_pointer_range<charT> ranges[] =
{
{data+0, data+5,}, // alnum
{data+5, data+10,}, // alpha
{data+10, data+15,}, // blank
{data+15, data+20,}, // cntrl
{data+20, data+21,}, // d
{data+20, data+25,}, // digit
{data+25, data+30,}, // graph
{data+30, data+31,}, // l
{data+30, data+35,}, // lower
{data+35, data+40,}, // print
{data+40, data+45,}, // punct
{data+45, data+46,}, // s
{data+45, data+50,}, // space
{data+57, data+58,}, // u
{data+50, data+57,}, // unicode
{data+57, data+62,}, // upper
{data+62, data+63,}, // w
{data+62, data+66,}, // word
{data+66, data+72,}, // xdigit
};
static const character_pointer_range<charT>* ranges_begin = ranges;
static const character_pointer_range<charT>* ranges_end = ranges + (sizeof(ranges)/sizeof(ranges[0]));
character_pointer_range<charT> t = { p1, p2, };
const character_pointer_range<charT>* p = std::lower_bound(ranges_begin, ranges_end, t);
if((p != ranges_end) && (t == *p))
return static_cast<int>(p - ranges);
return -1;
}
//
// helper functions:
//
template <class charT>
std::ptrdiff_t global_length(const charT* p)
{
std::ptrdiff_t n = 0;
while(*p)
{
++p;
++n;
}
return n;
}
inline std::ptrdiff_t global_length(const char* p)
{
return (std::strlen)(p);
}
#ifndef BOOST_NO_WREGEX
inline std::ptrdiff_t global_length(const wchar_t* p)
{
return (std::wcslen)(p);
}
#endif
template <class charT>
inline charT BOOST_REGEX_CALL global_lower(charT c)
{
return c;
}
template <class charT>
inline charT BOOST_REGEX_CALL global_upper(charT c)
{
return c;
}
BOOST_REGEX_DECL char BOOST_REGEX_CALL global_lower(char c);
BOOST_REGEX_DECL char BOOST_REGEX_CALL global_upper(char c);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL global_lower(wchar_t c);
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL global_upper(wchar_t c);
#endif
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL global_lower(unsigned short c);
BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL global_upper(unsigned short c);
#endif
template <class charT>
int global_value(charT c)
{
static const charT zero = '0';
static const charT nine = '9';
static const charT a = 'a';
static const charT f = 'f';
static const charT A = 'A';
static const charT F = 'F';
if(c > f) return -1;
if(c >= a) return 10 + (c - a);
if(c > F) return -1;
if(c >= A) return 10 + (c - A);
if(c > nine) return -1;
if(c >= zero) return c - zero;
return -1;
}
template <class charT, class traits>
int global_toi(const charT*& p1, const charT* p2, int radix, const traits& t)
{
(void)t; // warning suppression
int next_value = t.value(*p1, radix);
if((p1 == p2) || (next_value < 0) || (next_value >= radix))
return -1;
int result = 0;
while(p1 != p2)
{
next_value = t.value(*p1, radix);
if((next_value < 0) || (next_value >= radix))
break;
result *= radix;
result += next_value;
++p1;
}
return result;
}
} // re_detail
} // boost
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif

View File

@ -0,0 +1,115 @@
/*
*
* Copyright (c) 1998-2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_workarounds.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares Misc workarounds.
*/
#ifndef BOOST_REGEX_WORKAROUND_HPP
#define BOOST_REGEX_WORKAROUND_HPP
#include <new>
#include <cstring>
#include <cstdlib>
#include <cstddef>
#include <cassert>
#include <string>
#include <stdexcept>
#include <iterator>
#include <iosfwd>
#include <vector>
#include <map>
#include <boost/limits.hpp>
#include <boost/assert.hpp>
#include <boost/cstdint.hpp>
#include <boost/throw_exception.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/mpl/bool_fwd.hpp>
#ifndef BOOST_NO_STD_LOCALE
# include <locale>
#endif
namespace boost{ namespace re_detail{
#ifdef BOOST_NO_STD_DISTANCE
template <class T>
std::ptrdiff_t distance(const T& x, const T& y)
{ return y - x; }
#else
using std::distance;
#endif
}}
#ifdef BOOST_REGEX_NO_BOOL
# define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>((x) ? true : false)
#else
# ifdef BOOST_MSVC
// warning suppression with VC6:
# pragma warning(disable: 4800)
# pragma warning(disable: 4786)
# endif
# define BOOST_REGEX_MAKE_BOOL(x) static_cast<bool>(x)
#endif
/*****************************************************************************
*
* Fix broken broken namespace support:
*
****************************************************************************/
#if defined(BOOST_NO_STDC_NAMESPACE) && defined(__cplusplus)
namespace std{
using ::ptrdiff_t;
using ::size_t;
using ::abs;
using ::memset;
using ::memcpy;
}
#endif
/*****************************************************************************
*
* helper functions pointer_construct/pointer_destroy:
*
****************************************************************************/
#ifdef __cplusplus
namespace boost{ namespace re_detail{
#ifdef BOOST_MSVC
#pragma warning (push)
#pragma warning (disable : 4100)
#endif
template <class T>
inline void pointer_destroy(T* p)
{ p->~T(); (void)p; }
#ifdef BOOST_MSVC
#pragma warning (pop)
#endif
template <class T>
inline void pointer_construct(T* p, const T& t)
{ new (p) T(t); }
}} // namespaces
#endif
#endif // include guard

View File

@ -36,6 +36,7 @@ enum mask_type
{
mask_take = 1,
mask_skip = 2,
mask_init = 4,
mask_any = mask_skip | mask_take,
mask_all = mask_any
};
@ -105,7 +106,12 @@ enum syntax_element_type
syntax_element_dot_rep = syntax_element_restart_continue + 1,
syntax_element_char_rep = syntax_element_dot_rep + 1,
syntax_element_short_set_rep = syntax_element_char_rep + 1,
syntax_element_long_set_rep = syntax_element_short_set_rep + 1
syntax_element_long_set_rep = syntax_element_short_set_rep + 1,
// a backstep for lookbehind repeats:
syntax_element_backstep = syntax_element_long_set_rep + 1,
// an assertion that a mark was matched:
syntax_element_assert_backref = syntax_element_backstep + 1,
syntax_element_toggle_case = syntax_element_assert_backref + 1
};
#ifdef BOOST_REGEX_DEBUG
@ -123,7 +129,7 @@ execution of the machine.
union offset_type
{
re_syntax_base* p;
std::size_t i;
std::ptrdiff_t i;
};
/*** struct re_syntax_base ********************************************
@ -133,11 +139,10 @@ struct re_syntax_base
{
syntax_element_type type; // what kind of state this is
offset_type next; // next state in the machine
unsigned int can_be_null; // true if we match a NULL string
};
/*** struct re_brace **************************************************
Base class for all states in the machine.
A marked parenthesis.
***********************************************************************/
struct re_brace : public re_syntax_base
{
@ -146,6 +151,23 @@ struct re_brace : public re_syntax_base
int index;
};
/*** struct re_dot **************************************************
Match anything.
***********************************************************************/
enum
{
dont_care = 1,
force_not_newline = 0,
force_newline = 2,
test_not_newline = 2,
test_newline = 3
};
struct re_dot : public re_syntax_base
{
unsigned char mask;
};
/*** struct re_literal ************************************************
A string of literals, following this structure will be an
array of characters: charT[length]
@ -155,6 +177,14 @@ struct re_literal : public re_syntax_base
unsigned int length;
};
/*** struct re_case ************************************************
Indicates whether we are moving to a case insensive block or not
***********************************************************************/
struct re_case : public re_syntax_base
{
bool icase;
};
/*** struct re_set_long ***********************************************
A wide character set of characters, following this structure will be
an array of type charT:
@ -162,10 +192,11 @@ First csingles null-terminated strings
Then 2 * cranges NULL terminated strings
Then cequivalents NULL terminated strings
***********************************************************************/
template <class mask_type>
struct re_set_long : public re_syntax_base
{
unsigned int csingles, cranges, cequivalents;
boost::uint_fast32_t cclasses;
mask_type cclasses;
bool isnot;
bool singleton;
};
@ -175,7 +206,7 @@ A set of narrow-characters, matches any of _map which is none-zero
***********************************************************************/
struct re_set : public re_syntax_base
{
unsigned char _map[256];
unsigned char _map[1 << CHAR_BIT];
};
/*** struct re_jump ***************************************************
@ -183,19 +214,27 @@ Jump to a new location in the machine (not next).
***********************************************************************/
struct re_jump : public re_syntax_base
{
offset_type alt; // location to jump to
unsigned char _map[256]; // which characters can take the jump
offset_type alt; // location to jump to
};
/*** struct re_alt ***************************************************
Jump to a new location in the machine (possibly next).
***********************************************************************/
struct re_alt : public re_jump
{
unsigned char _map[1 << CHAR_BIT]; // which characters can take the jump
unsigned int can_be_null; // true if we match a NULL string
};
/*** struct re_repeat *************************************************
Repeat a section of the machine
***********************************************************************/
struct re_repeat : public re_jump
struct re_repeat : public re_alt
{
unsigned min, max; // min and max allowable repeats
int id; // Unique identifier for this repeat
bool leading; // True if this repeat is at the start of the machine (lets us optimize some searches)
bool greedy; // True if this is a greedy repeat
std::size_t min, max; // min and max allowable repeats
int id; // Unique identifier for this repeat
bool leading; // True if this repeat is at the start of the machine (lets us optimize some searches)
bool greedy; // True if this is a greedy repeat
};
/*** enum re_jump_size_type *******************************************
@ -206,17 +245,22 @@ We provide this so we know how manybytes to insert when constructing the machine
enum re_jump_size_type
{
re_jump_size = (sizeof(re_jump) + padding_mask) & ~(padding_mask),
re_repeater_size = (sizeof(re_repeat) + padding_mask) & ~(padding_mask)
re_repeater_size = (sizeof(re_repeat) + padding_mask) & ~(padding_mask),
re_alt_size = (sizeof(re_alt) + padding_mask) & ~(padding_mask)
};
/*** proc re_is_set_member *********************************************
Forward declaration: we'll need this one later...
***********************************************************************/
template <class iterator, class charT, class traits_type, class Allocator>
template<class charT, class traits>
struct regex_data;
template <class iterator, class charT, class traits_type, class char_classT>
iterator BOOST_REGEX_CALL re_is_set_member(iterator next,
iterator last,
const re_set_long* set_,
const reg_expression<charT, traits_type, Allocator>& e);
const re_set_long<char_classT>* set_,
const regex_data<charT, traits_type>& e, bool icase);
} // namespace re_detail

View File

@ -42,20 +42,29 @@ struct sub_match : public std::pair<BidiIterator, BidiIterator>
sub_match() : std::pair<BidiIterator, BidiIterator>(), matched(false) {}
sub_match(BidiIterator i) : std::pair<BidiIterator, BidiIterator>(i, i), matched(false) {}
#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
&& !BOOST_WORKAROUND(BOOST_MSVC, < 1310)\
&& !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
template <class T, class A>
operator std::basic_string<value_type, T, A> ()const
{
return std::basic_string<value_type, T, A>(this->first, this->second);
}
#else
operator std::basic_string<value_type> ()const
{
return str();
}
#endif
difference_type BOOST_REGEX_CALL length()const
{
difference_type n = boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second);
difference_type n = ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second);
return n;
}
std::basic_string<value_type> str()const
{
std::basic_string<value_type> result;
std::size_t len = boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second);
std::size_t len = ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second);
result.reserve(len);
BidiIterator i = this->first;
while(i != this->second)
@ -71,6 +80,14 @@ struct sub_match : public std::pair<BidiIterator, BidiIterator>
return static_cast<int>(matched) - static_cast<int>(s.matched);
return str().compare(s.str());
}
int compare(const std::basic_string<value_type>& s)const
{
return str().compare(s);
}
int compare(const value_type* p)const
{
return str().compare(p);
}
bool operator==(const sub_match& that)const
{ return compare(that) == 0; }
@ -154,6 +171,13 @@ public:
#endif
};
typedef sub_match<const char*> csub_match;
typedef sub_match<std::string::const_iterator> ssub_match;
#ifndef BOOST_NO_WREGEX
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<std::wstring::const_iterator> wssub_match;
#endif
// comparison to std::basic_string<> part 1:
template <class RandomAccessIterator, class traits, class Allocator>
inline bool operator == (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,

View File

@ -0,0 +1,102 @@
/*
*
* Copyright (c) 2003
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE syntax_type.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares regular expression synatx type enumerator.
*/
#ifndef BOOST_REGEX_SYNTAX_TYPE_HPP
#define BOOST_REGEX_SYNTAX_TYPE_HPP
namespace boost{
namespace regex_constants{
typedef unsigned char syntax_type;
//
// values chosen are binary compatible with previous version:
//
static const syntax_type syntax_char = 0;
static const syntax_type syntax_open_mark = 1;
static const syntax_type syntax_close_mark = 2;
static const syntax_type syntax_dollar = 3;
static const syntax_type syntax_caret = 4;
static const syntax_type syntax_dot = 5;
static const syntax_type syntax_star = 6;
static const syntax_type syntax_plus = 7;
static const syntax_type syntax_question = 8;
static const syntax_type syntax_open_set = 9;
static const syntax_type syntax_close_set = 10;
static const syntax_type syntax_or = 11;
static const syntax_type syntax_escape = 12;
static const syntax_type syntax_dash = 14;
static const syntax_type syntax_open_brace = 15;
static const syntax_type syntax_close_brace = 16;
static const syntax_type syntax_digit = 17;
static const syntax_type syntax_comma = 27;
static const syntax_type syntax_equal = 37;
static const syntax_type syntax_colon = 36;
static const syntax_type syntax_not = 53;
// extensions:
static const syntax_type syntax_hash = 13;
static const syntax_type syntax_newline = 26;
// escapes:
typedef syntax_type escape_syntax_type;
static const escape_syntax_type escape_type_word_assert = 18;
static const escape_syntax_type escape_type_not_word_assert = 19;
static const escape_syntax_type escape_type_control_f = 29;
static const escape_syntax_type escape_type_control_n = 30;
static const escape_syntax_type escape_type_control_r = 31;
static const escape_syntax_type escape_type_control_t = 32;
static const escape_syntax_type escape_type_control_v = 33;
static const escape_syntax_type escape_type_ascii_control = 35;
static const escape_syntax_type escape_type_hex = 34;
static const escape_syntax_type escape_type_unicode = 0; // not used
static const escape_syntax_type escape_type_identity = 0; // not used
static const escape_syntax_type escape_type_backref = syntax_digit;
static const escape_syntax_type escape_type_decimal = syntax_digit; // not used
static const escape_syntax_type escape_type_class = 22;
static const escape_syntax_type escape_type_not_class = 23;
// extensions:
static const escape_syntax_type escape_type_left_word = 20;
static const escape_syntax_type escape_type_right_word = 21;
static const escape_syntax_type escape_type_start_buffer = 24; // for \`
static const escape_syntax_type escape_type_end_buffer = 25; // for \'
static const escape_syntax_type escape_type_control_a = 28; // for \a
static const escape_syntax_type escape_type_e = 38; // for \e
static const escape_syntax_type escape_type_E = 47; // for \Q\E
static const escape_syntax_type escape_type_Q = 48; // for \Q\E
static const escape_syntax_type escape_type_X = 49; // for \X
static const escape_syntax_type escape_type_C = 50; // for \C
static const escape_syntax_type escape_type_Z = 51; // for \Z
static const escape_syntax_type escape_type_G = 52; // for \G
static const escape_syntax_type escape_type_property = 54; // for \p
static const escape_syntax_type escape_type_not_property = 55; // for \P
static const escape_syntax_type escape_type_named_char = 56; // for \N
static const escape_syntax_type syntax_max = 57;
}
}
#endif

View File

@ -0,0 +1,190 @@
/*
*
* Copyright (c) 2003
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE u32regex_iterator.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Provides u32regex_iterator implementation.
*/
#ifndef BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
#define BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
namespace boost{
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
template <class BidirectionalIterator>
class u32regex_iterator_implementation
{
typedef u32regex regex_type;
match_results<BidirectionalIterator> what; // current match
BidirectionalIterator base; // start of sequence
BidirectionalIterator end; // end of sequence
const regex_type re; // the expression
match_flag_type flags; // flags for matching
public:
u32regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
: base(), end(last), re(*p), flags(f){}
bool init(BidirectionalIterator first)
{
base = first;
return u32regex_search(first, end, what, re, flags);
}
bool compare(const u32regex_iterator_implementation& that)
{
if(this == &that) return true;
return (&re.get_data() == &that.re.get_data()) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
}
const match_results<BidirectionalIterator>& get()
{ return what; }
bool next()
{
if(what.prefix().first != what[0].second)
flags |= match_prev_avail;
BidirectionalIterator next_start = what[0].second;
match_flag_type f(flags);
if(!what.length())
f |= regex_constants::match_not_initial_null;
bool result = u32regex_search(next_start, end, what, re, f);
if(result)
what.set_base(base);
return result;
}
private:
u32regex_iterator_implementation& operator=(const u32regex_iterator_implementation&);
};
template <class BidirectionalIterator>
class u32regex_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
std::forward_iterator_tag,
match_results<BidirectionalIterator>,
typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
const match_results<BidirectionalIterator>*,
const match_results<BidirectionalIterator>& >
#endif
{
private:
typedef u32regex_iterator_implementation<BidirectionalIterator> impl;
typedef shared_ptr<impl> pimpl;
public:
typedef u32regex regex_type;
typedef match_results<BidirectionalIterator> value_type;
typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef std::forward_iterator_tag iterator_category;
u32regex_iterator(){}
u32regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
match_flag_type m = match_default)
: pdata(new impl(&re, b, m))
{
if(!pdata->init(a))
{
pdata.reset();
}
}
u32regex_iterator(const u32regex_iterator& that)
: pdata(that.pdata) {}
u32regex_iterator& operator=(const u32regex_iterator& that)
{
pdata = that.pdata;
return *this;
}
bool operator==(const u32regex_iterator& that)const
{
if((pdata.get() == 0) || (that.pdata.get() == 0))
return pdata.get() == that.pdata.get();
return pdata->compare(*(that.pdata.get()));
}
bool operator!=(const u32regex_iterator& that)const
{ return !(*this == that); }
const value_type& operator*()const
{ return pdata->get(); }
const value_type* operator->()const
{ return &(pdata->get()); }
u32regex_iterator& operator++()
{
cow();
if(0 == pdata->next())
{
pdata.reset();
}
return *this;
}
u32regex_iterator operator++(int)
{
u32regex_iterator result(*this);
++(*this);
return result;
}
private:
pimpl pdata;
void cow()
{
// copy-on-write
if(pdata.get() && !pdata.unique())
{
pdata.reset(new impl(*(pdata.get())));
}
}
};
typedef u32regex_iterator<const char*> utf8regex_iterator;
typedef u32regex_iterator<const UChar*> utf16regex_iterator;
typedef u32regex_iterator<const UChar32*> utf32regex_iterator;
inline u32regex_iterator<const char*> make_u32regex_iterator(const char* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_iterator<const char*>(p, p+std::strlen(p), e, m);
}
#ifndef BOOST_NO_WREGEX
inline u32regex_iterator<const wchar_t*> make_u32regex_iterator(const wchar_t* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_iterator<const wchar_t*>(p, p+std::wcslen(p), e, m);
}
#endif
#ifndef U_WCHAR_IS_UTF16
inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UChar* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_iterator<const UChar*>(p, p+u_strlen(p), e, m);
}
#endif
template <class charT, class Traits, class Alloc>
inline u32regex_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator>(p.begin(), p.end(), e, m);
}
inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UnicodeString& s, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
} // namespace boost
#endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP

View File

@ -0,0 +1,365 @@
/*
*
* Copyright (c) 2003
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE u32regex_token_iterator.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Provides u32regex_token_iterator implementation.
*/
#ifndef BOOST_REGEX_V4_U32REGEX_TOKEN_ITERATOR_HPP
#define BOOST_REGEX_V4_U32REGEX_TOKEN_ITERATOR_HPP
#if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
|| BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
|| BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
//
// Borland C++ Builder 6, and Visual C++ 6,
// can't cope with the array template constructor
// so we have a template member that will accept any type as
// argument, and then assert that is really is an array:
//
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_array.hpp>
#endif
namespace boost{
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
#if BOOST_WORKAROUND(BOOST_MSVC, > 1300)
# pragma warning(push)
# pragma warning(disable:4700)
#endif
template <class BidirectionalIterator>
class u32regex_token_iterator_implementation
{
typedef u32regex regex_type;
typedef sub_match<BidirectionalIterator> value_type;
match_results<BidirectionalIterator> what; // current match
BidirectionalIterator end; // end of search area
const regex_type re; // the expression
match_flag_type flags; // match flags
value_type result; // the current string result
int N; // the current sub-expression being enumerated
std::vector<int> subs; // the sub-expressions to enumerate
public:
u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, int sub, match_flag_type f)
: end(last), re(*p), flags(f){ subs.push_back(sub); }
u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const std::vector<int>& v, match_flag_type f)
: end(last), re(*p), flags(f), subs(v){}
#if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
|| BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
|| BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
|| BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))
template <class T>
u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const T& submatches, match_flag_type f)
: end(last), re(*p), flags(f)
{
// assert that T really is an array:
BOOST_STATIC_ASSERT(::boost::is_array<T>::value);
const std::size_t array_size = sizeof(T) / sizeof(submatches[0]);
for(std::size_t i = 0; i < array_size; ++i)
{
subs.push_back(submatches[i]);
}
}
#else
template <std::size_t CN>
u32regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const int (&submatches)[CN], match_flag_type f)
: end(last), re(*p), flags(f)
{
for(std::size_t i = 0; i < CN; ++i)
{
subs.push_back(submatches[i]);
}
}
#endif
bool init(BidirectionalIterator first)
{
N = 0;
if(u32regex_search(first, end, what, re, flags) == true)
{
N = 0;
result = ((subs[N] == -1) ? what.prefix() : what[(int)subs[N]]);
return true;
}
else if((subs[N] == -1) && (first != end))
{
result.first = first;
result.second = end;
result.matched = (first != end);
return true;
}
return false;
}
bool compare(const u32regex_token_iterator_implementation& that)
{
if(this == &that) return true;
return (&re.get_data() == &that.re.get_data())
&& (end == that.end)
&& (flags == that.flags)
&& (N == that.N)
&& (what[0].first == that.what[0].first)
&& (what[0].second == that.what[0].second);
}
const value_type& get()
{ return result; }
bool next()
{
if(N == -1)
return false;
if(N+1 < (int)subs.size())
{
++N;
result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
return true;
}
if(what.prefix().first != what[0].second)
flags |= match_prev_avail;
BidirectionalIterator last_end(what[0].second);
if(u32regex_search(last_end, end, what, re, ((what[0].first == what[0].second) ? flags | regex_constants::match_not_initial_null : flags)))
{
N =0;
result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
return true;
}
else if((last_end != end) && (subs[0] == -1))
{
N =-1;
result.first = last_end;
result.second = end;
result.matched = (last_end != end);
return true;
}
return false;
}
private:
u32regex_token_iterator_implementation& operator=(const u32regex_token_iterator_implementation&);
};
template <class BidirectionalIterator>
class u32regex_token_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
std::forward_iterator_tag,
sub_match<BidirectionalIterator>,
typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
const sub_match<BidirectionalIterator>*,
const sub_match<BidirectionalIterator>& >
#endif
{
private:
typedef u32regex_token_iterator_implementation<BidirectionalIterator> impl;
typedef shared_ptr<impl> pimpl;
public:
typedef u32regex regex_type;
typedef sub_match<BidirectionalIterator> value_type;
typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef std::forward_iterator_tag iterator_category;
u32regex_token_iterator(){}
u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
int submatch = 0, match_flag_type m = match_default)
: pdata(new impl(&re, b, submatch, m))
{
if(!pdata->init(a))
pdata.reset();
}
u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
const std::vector<int>& submatches, match_flag_type m = match_default)
: pdata(new impl(&re, b, submatches, m))
{
if(!pdata->init(a))
pdata.reset();
}
#if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
|| BOOST_WORKAROUND(BOOST_MSVC, < 1300) \
|| BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) \
|| BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))
template <class T>
u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
const T& submatches, match_flag_type m = match_default)
: pdata(new impl(&re, b, submatches, m))
{
if(!pdata->init(a))
pdata.reset();
}
#else
template <std::size_t N>
u32regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
const int (&submatches)[N], match_flag_type m = match_default)
: pdata(new impl(&re, b, submatches, m))
{
if(!pdata->init(a))
pdata.reset();
}
#endif
u32regex_token_iterator(const u32regex_token_iterator& that)
: pdata(that.pdata) {}
u32regex_token_iterator& operator=(const u32regex_token_iterator& that)
{
pdata = that.pdata;
return *this;
}
bool operator==(const u32regex_token_iterator& that)const
{
if((pdata.get() == 0) || (that.pdata.get() == 0))
return pdata.get() == that.pdata.get();
return pdata->compare(*(that.pdata.get()));
}
bool operator!=(const u32regex_token_iterator& that)const
{ return !(*this == that); }
const value_type& operator*()const
{ return pdata->get(); }
const value_type* operator->()const
{ return &(pdata->get()); }
u32regex_token_iterator& operator++()
{
cow();
if(0 == pdata->next())
{
pdata.reset();
}
return *this;
}
u32regex_token_iterator operator++(int)
{
u32regex_token_iterator result(*this);
++(*this);
return result;
}
private:
pimpl pdata;
void cow()
{
// copy-on-write
if(pdata.get() && !pdata.unique())
{
pdata.reset(new impl(*(pdata.get())));
}
}
};
typedef u32regex_token_iterator<const char*> utf8regex_token_iterator;
typedef u32regex_token_iterator<const UChar*> utf16regex_token_iterator;
typedef u32regex_token_iterator<const UChar32*> utf32regex_token_iterator;
// construction from an integral sub_match id:
inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
}
#ifndef BOOST_NO_WREGEX
inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
}
#endif
#ifndef U_WCHAR_IS_UTF16
inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, m);
}
#endif
template <class charT, class Traits, class Alloc>
inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator>(p.begin(), p.end(), e, m);
}
inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UnicodeString& s, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
}
// construction from a reference to an array:
template <std::size_t N>
inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
}
#ifndef BOOST_NO_WREGEX
template <std::size_t N>
inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
}
#endif
#ifndef U_WCHAR_IS_UTF16
template <std::size_t N>
inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, m);
}
#endif
template <class charT, class Traits, class Alloc, std::size_t N>
inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator>(p.begin(), p.end(), e, m);
}
template <std::size_t N>
inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UnicodeString& s, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
}
// construction from a vector of sub_match id's:
inline u32regex_token_iterator<const char*> make_u32regex_token_iterator(const char* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const char*>(p, p+std::strlen(p), e, submatch, m);
}
#ifndef BOOST_NO_WREGEX
inline u32regex_token_iterator<const wchar_t*> make_u32regex_token_iterator(const wchar_t* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const wchar_t*>(p, p+std::wcslen(p), e, submatch, m);
}
#endif
#ifndef U_WCHAR_IS_UTF16
inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UChar* p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const UChar*>(p, p+u_strlen(p), e, m);
}
#endif
template <class charT, class Traits, class Alloc>
inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_token_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator>(p.begin(), p.end(), e, m);
}
inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const UnicodeString& s, const u32regex& e, const std::vector<int>& submatch, regex_constants::match_flag_type m = regex_constants::match_default)
{
return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
}
#if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
# pragma warning(pop)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
} // namespace boost
#endif // BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP

View File

@ -0,0 +1,712 @@
/*
*
* Copyright (c) 2004
* Dr John Maddock
*
* Use, modification and distribution are 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)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE w32_regex_traits.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares regular expression traits class w32_regex_traits.
*/
#ifndef BOOST_W32_REGEX_TRAITS_HPP_INCLUDED
#define BOOST_W32_REGEX_TRAITS_HPP_INCLUDED
#ifndef BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
#include <boost/regex/v4/regex_traits_defaults.hpp>
#endif
#ifdef BOOST_HAS_THREADS
#include <boost/regex/pending/static_mutex.hpp>
#endif
#ifndef BOOST_REGEX_PRIMARY_TRANSFORM
#include <boost/regex/v4/primary_transform.hpp>
#endif
#ifndef BOOST_REGEX_OBJECT_CACHE_HPP
#include <boost/regex/pending/object_cache.hpp>
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4786)
#endif
namespace boost{
//
// forward declaration is needed by some compilers:
//
template <class charT>
class w32_regex_traits;
namespace re_detail{
//
// start by typedeffing the types we'll need:
//
typedef ::boost::uint32_t lcid_type; // placeholder for LCID.
typedef ::boost::shared_ptr<void> cat_type; // placeholder for dll HANDLE.
//
// then add wrappers around the actual Win32 API's (ie implementation hiding):
//
BOOST_REGEX_DECL lcid_type BOOST_REGEX_CALL w32_get_default_locale();
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(char, lcid_type);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(wchar_t, lcid_type);
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(unsigned short ca, lcid_type id);
#endif
#endif
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(char, lcid_type);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(wchar_t, lcid_type);
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(unsigned short ca, lcid_type id);
#endif
#endif
BOOST_REGEX_DECL cat_type BOOST_REGEX_CALL w32_cat_open(const std::string& name);
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type id, int i, const std::string& def);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type id, int i, const std::wstring& def);
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type, int i, const std::basic_string<unsigned short>& def);
#endif
#endif
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type id, const char* p1, const char* p2);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_transform(lcid_type id, const wchar_t* p1, const wchar_t* p2);
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_transform(lcid_type id, const unsigned short* p1, const unsigned short* p2);
#endif
#endif
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_tolower(char c, lcid_type);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_tolower(wchar_t c, lcid_type);
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL w32_tolower(unsigned short c, lcid_type id);
#endif
#endif
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_toupper(char c, lcid_type);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_toupper(wchar_t c, lcid_type);
#endif
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type, boost::uint32_t mask, char c);
#ifndef BOOST_NO_WREGEX
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type, boost::uint32_t mask, wchar_t c);
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type id, boost::uint32_t m, unsigned short c);
#endif
#endif
//
// class w32_regex_traits_base:
// acts as a container for locale and the facets we are using.
//
template <class charT>
struct w32_regex_traits_base
{
w32_regex_traits_base(lcid_type l)
{ imbue(l); }
lcid_type imbue(lcid_type l);
lcid_type m_locale;
};
template <class charT>
inline lcid_type w32_regex_traits_base<charT>::imbue(lcid_type l)
{
lcid_type result(m_locale);
m_locale = l;
return result;
}
//
// class w32_regex_traits_char_layer:
// implements methods that require specialisation for narrow characters:
//
template <class charT>
class w32_regex_traits_char_layer : public w32_regex_traits_base<charT>
{
typedef std::basic_string<charT> string_type;
typedef std::map<charT, regex_constants::syntax_type> map_type;
typedef typename map_type::const_iterator map_iterator_type;
public:
w32_regex_traits_char_layer(const lcid_type l);
regex_constants::syntax_type syntax_type(charT c)const
{
map_iterator_type i = m_char_map.find(c);
return ((i == m_char_map.end()) ? 0 : i->second);
}
regex_constants::escape_syntax_type escape_syntax_type(charT c) const
{
map_iterator_type i = m_char_map.find(c);
if(i == m_char_map.end())
{
if(::boost::re_detail::w32_is_lower(c, this->m_locale)) return regex_constants::escape_type_class;
if(::boost::re_detail::w32_is_upper(c, this->m_locale)) return regex_constants::escape_type_not_class;
return 0;
}
return i->second;
}
charT tolower(charT c)const
{
return ::boost::re_detail::w32_tolower(c, this->m_locale);
}
bool isctype(boost::uint32_t mask, charT c)
{
return ::boost::re_detail::w32_is(this->m_locale, mask, c);
}
private:
string_type get_default_message(regex_constants::syntax_type);
// TODO: use a hash table when available!
map_type m_char_map;
};
template <class charT>
w32_regex_traits_char_layer<charT>::w32_regex_traits_char_layer(::boost::re_detail::lcid_type l)
: w32_regex_traits_base<charT>(l)
{
// we need to start by initialising our syntax map so we know which
// character is used for which purpose:
cat_type cat;
std::string cat_name(w32_regex_traits<charT>::get_catalog_name());
if(cat_name.size())
{
cat = ::boost::re_detail::w32_cat_open(cat_name);
if(!cat)
{
std::string m("Unable to open message catalog: ");
std::runtime_error err(m + cat_name);
boost::re_detail::raise_runtime_error(err);
}
}
//
// if we have a valid catalog then load our messages:
//
if(cat)
{
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
{
string_type mss = ::boost::re_detail::w32_cat_get(cat, m_locale, i, get_default_message(i));
for(typename string_type::size_type j = 0; j < mss.size(); ++j)
{
m_char_map[mss[j]] = i;
}
}
}
else
{
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
{
const char* ptr = get_default_syntax(i);
while(ptr && *ptr)
{
m_char_map[static_cast<charT>(*ptr)] = i;
++ptr;
}
}
}
}
template <class charT>
typename w32_regex_traits_char_layer<charT>::string_type
w32_regex_traits_char_layer<charT>::get_default_message(regex_constants::syntax_type i)
{
const char* ptr = get_default_syntax(i);
string_type result;
while(ptr && *ptr)
{
result.append(1, static_cast<charT>(*ptr));
++ptr;
}
return result;
}
//
// specialised version for narrow characters:
//
template <>
class BOOST_REGEX_DECL w32_regex_traits_char_layer<char> : public w32_regex_traits_base<char>
{
typedef std::string string_type;
public:
w32_regex_traits_char_layer(::boost::re_detail::lcid_type l)
: w32_regex_traits_base<char>(l)
{
init();
}
regex_constants::syntax_type syntax_type(char c)const
{
return m_char_map[static_cast<unsigned char>(c)];
}
regex_constants::escape_syntax_type escape_syntax_type(char c) const
{
return m_char_map[static_cast<unsigned char>(c)];
}
char tolower(char c)const
{
return m_lower_map[static_cast<unsigned char>(c)];
}
bool isctype(boost::uint32_t mask, char c)
{
return m_type_map[static_cast<unsigned char>(c)] & mask;
}
private:
regex_constants::syntax_type m_char_map[1u << CHAR_BIT];
char m_lower_map[1u << CHAR_BIT];
boost::uint16_t m_type_map[1u << CHAR_BIT];
void init();
};
//
// class w32_regex_traits_implementation:
// provides pimpl implementation for w32_regex_traits.
//
template <class charT>
class w32_regex_traits_implementation : public w32_regex_traits_char_layer<charT>
{
public:
typedef typename w32_regex_traits<charT>::char_class_type char_class_type;
BOOST_STATIC_CONSTANT(char_class_type, mask_word = 0x0400); // must be C1_DEFINED << 1
BOOST_STATIC_CONSTANT(char_class_type, mask_unicode = 0x0800); // must be C1_DEFINED << 2
BOOST_STATIC_CONSTANT(char_class_type, mask_base = 0x3ff); // all the masks used by the CT_CTYPE1 group
typedef std::basic_string<charT> string_type;
typedef charT char_type;
w32_regex_traits_implementation(::boost::re_detail::lcid_type l);
std::string error_string(regex_constants::error_type n) const
{
if(!m_error_strings.empty())
{
std::map<int, std::string>::const_iterator p = m_error_strings.find(n);
return (p == m_error_strings.end()) ? std::string(get_default_error_string(n)) : p->second;
}
return get_default_error_string(n);
}
char_class_type lookup_classname(const charT* p1, const charT* p2) const
{
char_class_type result = lookup_classname_imp(p1, p2);
if(result == 0)
{
typedef typename string_type::size_type size_type;
string_type temp(p1, p2);
for(size_type i = 0; i < temp.size(); ++i)
temp[i] = this->tolower(temp[i]);
result = lookup_classname_imp(&*temp.begin(), &*temp.begin() + temp.size());
}
return result;
}
string_type lookup_collatename(const charT* p1, const charT* p2) const;
string_type transform_primary(const charT* p1, const charT* p2) const;
string_type transform(const charT* p1, const charT* p2) const
{
return ::boost::re_detail::w32_transform(this->m_locale, p1, p2);
}
private:
std::map<int, std::string> m_error_strings; // error messages indexed by numberic ID
std::map<string_type, char_class_type> m_custom_class_names; // character class names
std::map<string_type, string_type> m_custom_collate_names; // collating element names
unsigned m_collate_type; // the form of the collation string
charT m_collate_delim; // the collation group delimiter
//
// helpers:
//
char_class_type lookup_classname_imp(const charT* p1, const charT* p2) const;
};
template <class charT>
typename w32_regex_traits_implementation<charT>::string_type
w32_regex_traits_implementation<charT>::transform_primary(const charT* p1, const charT* p2) const
{
string_type result;
//
// What we do here depends upon the format of the sort key returned by
// sort key returned by this->transform:
//
switch(m_collate_type)
{
case sort_C:
case sort_unknown:
// the best we can do is translate to lower case, then get a regular sort key:
{
result.assign(p1, p2);
typedef typename string_type::size_type size_type;
for(size_type i = 0; i < result.size(); ++i)
result[i] = this->tolower(result[i]);
result = this->transform(&*result.begin(), &*result.begin() + result.size());
break;
}
case sort_fixed:
{
// get a regular sort key, and then truncate it:
result.assign(this->transform(p1, p2));
result.erase(this->m_collate_delim);
break;
}
case sort_delim:
// get a regular sort key, and then truncate everything after the delim:
result.assign(this->transform(p1, p2));
std::size_t i;
for(i = 0; i < result.size(); ++i)
{
if(result[i] == m_collate_delim)
break;
}
result.erase(i);
break;
}
return result;
}
template <class charT>
typename w32_regex_traits_implementation<charT>::string_type
w32_regex_traits_implementation<charT>::lookup_collatename(const charT* p1, const charT* p2) const
{
typedef typename std::map<string_type, string_type>::const_iterator iter_type;
if(m_custom_collate_names.size())
{
iter_type pos = m_custom_collate_names.find(string_type(p1, p2));
if(pos != m_custom_collate_names.end())
return pos->second;
}
#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
&& !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
&& !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
std::string name(p1, p2);
#else
std::string name;
const charT* p0 = p1;
while(p0 != p2)
name.append(1, char(*p0++));
#endif
name = lookup_default_collate_name(name);
#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
&& !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
&& !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
if(name.size())
return string_type(name.begin(), name.end());
#else
if(name.size())
{
string_type result;
typedef std::string::const_iterator iter;
iter b = name.begin();
iter e = name.end();
while(b != e)
result.append(1, charT(*b++));
return result;
}
#endif
if(p2 - p1 == 1)
return string_type(1, *p1);
return string_type();
}
template <class charT>
w32_regex_traits_implementation<charT>::w32_regex_traits_implementation(::boost::re_detail::lcid_type l)
: w32_regex_traits_char_layer<charT>(l)
{
cat_type cat;
std::string cat_name(w32_regex_traits<charT>::get_catalog_name());
if(cat_name.size())
{
cat = ::boost::re_detail::w32_cat_open(cat_name);
if(!cat)
{
std::string m("Unable to open message catalog: ");
std::runtime_error err(m + cat_name);
boost::re_detail::raise_runtime_error(err);
}
}
//
// if we have a valid catalog then load our messages:
//
if(cat)
{
//
// Error messages:
//
for(boost::regex_constants::error_type i = static_cast<boost::regex_constants::error_type>(0);
i <= boost::regex_constants::error_unknown;
i = static_cast<boost::regex_constants::error_type>(i + 1))
{
const char* p = get_default_error_string(i);
string_type default_message;
while(*p)
{
default_message.append(1, static_cast<charT>(*p));
++p;
}
string_type s = ::boost::re_detail::w32_cat_get(cat, this->m_locale, i+200, default_message);
std::string result;
for(std::string::size_type j = 0; j < s.size(); ++j)
{
result.append(1, static_cast<char>(s[j]));
}
m_error_strings[i] = result;
}
//
// Custom class names:
//
static const char_class_type masks[] =
{
0x0104u, // C1_ALPHA | C1_DIGIT
0x0100u, // C1_ALPHA
0x0020u, // C1_CNTRL
0x0004u, // C1_DIGIT
(~(0x0020u|0x0008u) & 0x01ffu) | 0x0400u, // not C1_CNTRL or C1_SPACE
0x0002u, // C1_LOWER
(~0x0020u & 0x01ffu) | 0x0400, // not C1_CNTRL
0x0010u, // C1_PUNCT
0x0008u, // C1_SPACE
0x0001u, // C1_UPPER
0x0080u, // C1_XDIGIT
0x0040u, // C1_BLANK
w32_regex_traits_implementation<charT>::mask_word,
w32_regex_traits_implementation<charT>::mask_unicode,
};
static const string_type null_string;
for(unsigned int j = 0; j <= 13; ++j)
{
string_type s(::boost::re_detail::w32_cat_get(cat, this->m_locale, j+300, null_string));
if(s.size())
this->m_custom_class_names[s] = masks[j];
}
}
//
// get the collation format used by m_pcollate:
//
m_collate_type = re_detail::find_sort_syntax(this, &m_collate_delim);
}
template <class charT>
typename w32_regex_traits_implementation<charT>::char_class_type
w32_regex_traits_implementation<charT>::lookup_classname_imp(const charT* p1, const charT* p2) const
{
static const char_class_type masks[] =
{
0,
0x0104u, // C1_ALPHA | C1_DIGIT
0x0100u, // C1_ALPHA
0x0040u, // C1_BLANK
0x0020u, // C1_CNTRL
0x0004u, // C1_DIGIT
0x0004u, // C1_DIGIT
(~(0x0020u|0x0008u|0x0040) & 0x01ffu) | 0x0400u, // not C1_CNTRL or C1_SPACE or C1_BLANK
0x0002u, // C1_LOWER
0x0002u, // C1_LOWER
(~0x0020u & 0x01ffu) | 0x0400, // not C1_CNTRL
0x0010u, // C1_PUNCT
0x0008u, // C1_SPACE
0x0008u, // C1_SPACE
0x0001u, // C1_UPPER
w32_regex_traits_implementation<charT>::mask_unicode,
0x0001u, // C1_UPPER
0x0104u | w32_regex_traits_implementation<charT>::mask_word,
0x0104u | w32_regex_traits_implementation<charT>::mask_word,
0x0080u, // C1_XDIGIT
};
if(m_custom_class_names.size())
{
typedef typename std::map<std::basic_string<charT>, char_class_type>::const_iterator map_iter;
map_iter pos = m_custom_class_names.find(string_type(p1, p2));
if(pos != m_custom_class_names.end())
return pos->second;
}
std::size_t id = 1 + re_detail::get_default_class_id(p1, p2);
assert(id < sizeof(masks) / sizeof(masks[0]));
return masks[id];
}
template <class charT>
boost::shared_ptr<w32_regex_traits_implementation<charT> > create_w32_regex_traits(::boost::re_detail::lcid_type l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
{
// TODO: create a cache for previously constructed objects.
return boost::object_cache< ::boost::re_detail::lcid_type, w32_regex_traits_implementation<charT> >::get(l, 5);
}
} // re_detail
template <class charT>
class w32_regex_traits
{
private:
typedef std::ctype<charT> ctype_type;
public:
typedef charT char_type;
typedef std::size_t size_type;
typedef std::basic_string<char_type> string_type;
typedef ::boost::re_detail::lcid_type locale_type;
typedef boost::uint_least32_t char_class_type;
struct boost_extensions_tag{};
w32_regex_traits()
: m_pimpl(re_detail::create_w32_regex_traits<charT>(::boost::re_detail::w32_get_default_locale()))
{ }
static size_type length(const char_type* p)
{
return std::char_traits<charT>::length(p);
}
regex_constants::syntax_type syntax_type(charT c)const
{
return m_pimpl->syntax_type(c);
}
regex_constants::escape_syntax_type escape_syntax_type(charT c) const
{
return m_pimpl->escape_syntax_type(c);
}
charT translate(charT c) const
{
return c;
}
charT translate_nocase(charT c) const
{
return this->m_pimpl->tolower(c);
}
charT translate(charT c, bool icase) const
{
return icase ? this->m_pimpl->tolower(c) : c;
}
charT tolower(charT c) const
{
return this->m_pimpl->tolower(c);
}
charT toupper(charT c) const
{
return ::boost::re_detail::w32_toupper(c, this->m_pimpl->m_locale);
}
string_type transform(const charT* p1, const charT* p2) const
{
return ::boost::re_detail::w32_transform(this->m_pimpl->m_locale, p1, p2);
}
string_type transform_primary(const charT* p1, const charT* p2) const
{
return m_pimpl->transform_primary(p1, p2);
}
char_class_type lookup_classname(const charT* p1, const charT* p2) const
{
return m_pimpl->lookup_classname(p1, p2);
}
string_type lookup_collatename(const charT* p1, const charT* p2) const
{
return m_pimpl->lookup_collatename(p1, p2);
}
bool isctype(charT c, char_class_type f) const
{
if((f & re_detail::w32_regex_traits_implementation<charT>::mask_base)
&& (this->m_pimpl->isctype(f & re_detail::w32_regex_traits_implementation<charT>::mask_base, c)))
return true;
else if((f & re_detail::w32_regex_traits_implementation<charT>::mask_unicode) && re_detail::is_extended(c))
return true;
else if((f & re_detail::w32_regex_traits_implementation<charT>::mask_word) && (c == '_'))
return true;
return false;
}
int toi(const charT*& p1, const charT* p2, int radix)const
{
return ::boost::re_detail::global_toi(p1, p2, radix, *this);
}
int value(charT c, int radix)const
{
int result = ::boost::re_detail::global_value(c);
return result < radix ? result : -1;
}
locale_type imbue(locale_type l)
{
::boost::re_detail::lcid_type result(getloc());
m_pimpl = re_detail::create_w32_regex_traits<charT>(l);
return result;
}
locale_type getloc()const
{
return m_pimpl->m_locale;
}
std::string error_string(regex_constants::error_type n) const
{
return m_pimpl->error_string(n);
}
//
// extension:
// set the name of the message catalog in use (defaults to "boost_regex").
//
static std::string catalog_name(const std::string& name);
static std::string get_catalog_name();
private:
boost::shared_ptr<re_detail::w32_regex_traits_implementation<charT> > m_pimpl;
//
// catalog name handler:
//
static std::string& get_catalog_name_inst();
#ifdef BOOST_HAS_THREADS
static static_mutex& get_mutex_inst();
#endif
};
template <class charT>
std::string w32_regex_traits<charT>::catalog_name(const std::string& name)
{
#ifdef BOOST_HAS_THREADS
static_mutex::scoped_lock lk(get_mutex_inst());
#endif
std::string result(get_catalog_name_inst());
get_catalog_name_inst() = name;
return result;
}
template <class charT>
std::string& w32_regex_traits<charT>::get_catalog_name_inst()
{
static std::string s_name;
return s_name;
}
template <class charT>
std::string w32_regex_traits<charT>::get_catalog_name()
{
#ifdef BOOST_HAS_THREADS
static_mutex::scoped_lock lk(get_mutex_inst());
#endif
std::string result(get_catalog_name_inst());
return result;
}
#ifdef BOOST_HAS_THREADS
template <class charT>
static_mutex& w32_regex_traits<charT>::get_mutex_inst()
{
static static_mutex s_mutex = BOOST_STATIC_MUTEX_INIT;
return s_mutex;
}
#endif
} // boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#endif

View File

@ -24,11 +24,7 @@
#include <boost/regex/config.hpp>
#endif
#ifdef BOOST_REGEX_V3
#include <boost/regex/v3/regex_fwd.hpp>
#else
#include <boost/regex/v4/regex_fwd.hpp>
#endif
#endif