Ported ICU integration code to VC6/7.

Added some needed std lib #includes.
Reworked gcc separate file template instantiation code.


[SVN r30791]
This commit is contained in:
John Maddock
2005-09-03 11:13:28 +00:00
parent db5748ae7e
commit 90f4367b8d
16 changed files with 392 additions and 57 deletions

View File

@ -40,28 +40,28 @@ 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 U_NAMESPACE_QUALIFIER Locale locale_type;
typedef boost::uint_least32_t char_class_type;
public:
icu_regex_traits_implementation(const ::Locale& l)
icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& l)
: m_locale(l)
{
UErrorCode success = U_ZERO_ERROR;
m_collator.reset( ::Collator::createInstance(l, success));
m_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
if(U_SUCCESS(success) == 0)
init_error();
m_collator->setStrength(::Collator::IDENTICAL);
m_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::IDENTICAL);
success = U_ZERO_ERROR;
m_primary_collator.reset( ::Collator::createInstance(l, success));
m_primary_collator.reset(U_NAMESPACE_QUALIFIER Collator::createInstance(l, success));
if(U_SUCCESS(success) == 0)
init_error();
m_primary_collator->setStrength(::Collator::PRIMARY);
m_primary_collator->setStrength(U_NAMESPACE_QUALIFIER Collator::PRIMARY);
}
::Locale getloc()const
U_NAMESPACE_QUALIFIER Locale getloc()const
{
return m_locale;
}
string_type do_transform(const char_type* p1, const char_type* p2, const ::Collator* pcoll) const;
string_type do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const;
string_type transform(const char_type* p1, const char_type* p2) const
{
return do_transform(p1, p2, m_collator.get());
@ -76,12 +76,12 @@ private:
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
U_NAMESPACE_QUALIFIER Locale m_locale; // The ICU locale that we're using
boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_collator; // The full collation object
boost::scoped_ptr< U_NAMESPACE_QUALIFIER Collator> m_primary_collator; // The primary collation object
};
inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const ::Locale& loc)
inline boost::shared_ptr<icu_regex_traits_implementation> get_icu_regex_traits_implementation(const U_NAMESPACE_QUALIFIER Locale& loc)
{
return boost::shared_ptr<icu_regex_traits_implementation>(new icu_regex_traits_implementation(loc));
}
@ -94,7 +94,7 @@ public:
typedef UChar32 char_type;
typedef std::size_t size_type;
typedef std::vector<char_type> string_type;
typedef ::Locale locale_type;
typedef U_NAMESPACE_QUALIFIER Locale locale_type;
#ifdef BOOST_NO_INT64_T
typedef std::bitset<64> char_class_type;
#else
@ -104,7 +104,7 @@ public:
struct boost_extensions_tag{};
icu_regex_traits()
: m_pimpl(re_detail::get_icu_regex_traits_implementation(::Locale()))
: m_pimpl(re_detail::get_icu_regex_traits_implementation(U_NAMESPACE_QUALIFIER Locale()))
{
}
static size_type length(const char_type* p);
@ -213,6 +213,7 @@ typedef match_results<const ::UChar*> u16match;
//
namespace re_detail{
#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
template <class InputIterator>
inline u32regex do_make_u32regex(InputIterator i,
InputIterator j,
@ -241,7 +242,59 @@ inline u32regex do_make_u32regex(InputIterator i,
{
return u32regex(i, j, opt);
}
#else
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;
typedef std::vector<UChar32> vector_type;
vector_type v;
conv_type a(i), b(j);
while(a != b)
{
v.push_back(*a);
++a;
}
return u32regex(&*v.begin(), v.size(), 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;
typedef std::vector<UChar32> vector_type;
vector_type v;
conv_type a(i), b(j);
while(a != b)
{
v.push_back(*a);
++a;
}
return u32regex(&*v.begin(), v.size(), 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>*)
{
typedef std::vector<UCHAR32> vector_type;
vector_type v;
while(i != j)
{
v.push_back((UCHAR32)(*i));
++a;
}
return u32regex(&*v.begin(), v.size(), opt);
}
#endif
}
//
@ -721,7 +774,14 @@ OutputIterator do_regex_replace(OutputIterator out,
{
// unfortunately we have to copy the format string in order to pass in onward:
std::vector<UChar32> f;
#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
f.assign(fmt.first, fmt.second);
#else
f.clear();
I2 pos = fmt.first;
while(pos != fmt.second)
f.push_back(*pos++);
#endif
regex_iterator<I1, UChar32, icu_regex_traits> i(in.first, in.second, e, flags);
regex_iterator<I1, UChar32, icu_regex_traits> j;
@ -773,7 +833,11 @@ inline OutputIterator u32regex_replace(OutputIterator out,
const charT* fmt,
match_flag_type flags = match_default)
{
return re_detail::extract_output_base(
return re_detail::extract_output_base
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
<OutputIterator>
#endif
(
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)),
@ -791,7 +855,11 @@ inline OutputIterator u32regex_replace(OutputIterator out,
const std::basic_string<charT>& fmt,
match_flag_type flags = match_default)
{
return re_detail::extract_output_base(
return re_detail::extract_output_base
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
<OutputIterator>
#endif
(
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)),
@ -809,7 +877,11 @@ inline OutputIterator u32regex_replace(OutputIterator out,
const UnicodeString& fmt,
match_flag_type flags = match_default)
{
return re_detail::extract_output_base(
return re_detail::extract_output_base
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
<OutputIterator>
#endif
(
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)),

View File

@ -242,10 +242,17 @@ public:
{
return assign(p, p + len, f);
}
private:
basic_regex& do_assign(const charT* p1,
const charT* p2,
flag_type f);
public:
basic_regex& assign(const charT* p1,
const charT* p2,
flag_type f = regex_constants::normal);
flag_type f = regex_constants::normal)
{
return do_assign(p1, p2, f);
}
#if !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__)
template <class ST, class SA>
@ -493,7 +500,7 @@ private:
// (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,
basic_regex<charT, traits>& basic_regex<charT, traits>::do_assign(const charT* p1,
const charT* p2,
flag_type f)
{

View File

@ -40,6 +40,7 @@
#endif
#include <istream>
#include <ios>
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX

View File

@ -57,7 +57,7 @@ template class BOOST_REGEX_DECL basic_regex< BOOST_REGEX_CHAR_T >;
# include BOOST_ABI_SUFFIX
#endif
#elif defined(BOOST_MSVC) || defined(BOOST_INTEL) || (defined(__GNUC__) && (__GNUC__ >= 3))
#elif defined(BOOST_MSVC) || defined(__ICL)
# ifndef BOOST_REGEX_INSTANTIATE
# ifdef __GNUC__
@ -99,6 +99,53 @@ template class BOOST_REGEX_DECL ::boost::re_detail::perl_matcher< std::basic_str
# undef template
# endif
#elif (defined(__GNUC__) && (__GNUC__ >= 3))
# ifndef BOOST_REGEX_INSTANTIATE
# define template __extension__ extern template
# endif
template BOOST_REGEX_DECL basic_regex<BOOST_REGEX_CHAR_T>&
basic_regex<BOOST_REGEX_CHAR_T>::do_assign(
const BOOST_REGEX_CHAR_T* p1,
const BOOST_REGEX_CHAR_T* p2,
flag_type f);
template BOOST_REGEX_DECL basic_regex<BOOST_REGEX_CHAR_T>::locale_type BOOST_REGEX_CALL
basic_regex<BOOST_REGEX_CHAR_T>::imbue(locale_type l);
template BOOST_REGEX_DECL void BOOST_REGEX_CALL
match_results<const BOOST_REGEX_CHAR_T*>::maybe_assign(
const match_results<const BOOST_REGEX_CHAR_T*>& m);
template BOOST_REGEX_DECL void ::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 > >::construct_init(
BOOST_REGEX_CHAR_T const * first, BOOST_REGEX_CHAR_T const * end,
match_results<BOOST_REGEX_CHAR_T const *>& what,
const basic_regex<BOOST_REGEX_CHAR_T>& e,
match_flag_type f);
template BOOST_REGEX_DECL bool ::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 > >::match();
template BOOST_REGEX_DECL bool ::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 > >::find();
#if defined(__GLIBCPP__) || defined(__GLIBCXX__)
// std:basic_string<>::const_iterator instances as well:
template BOOST_REGEX_DECL void BOOST_REGEX_CALL
match_results<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator>::maybe_assign(
const match_results<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator>& m);
template BOOST_REGEX_DECL void ::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 > >::construct_init(
std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator first, std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator end,
match_results<std::basic_string<BOOST_REGEX_CHAR_T>::const_iterator>& what,
const basic_regex<BOOST_REGEX_CHAR_T>& e,
match_flag_type f);
template BOOST_REGEX_DECL bool ::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 > >::match();
template BOOST_REGEX_DECL bool ::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 > >::find();
#endif
# ifdef template
# undef template
# endif
#endif
} // namespace boost

View File

@ -71,6 +71,17 @@ template<>
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>{};
//
// the follwoing are needed for ICU support:
//
template<>
struct regex_iterator_traits<unsigned char*> : pointer_iterator_traits<char>{};
template<>
struct regex_iterator_traits<const unsigned char*> : const_pointer_iterator_traits<char>{};
template<>
struct regex_iterator_traits<int*> : pointer_iterator_traits<int>{};
template<>
struct regex_iterator_traits<const int*> : const_pointer_iterator_traits<int>{};
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
template<>

View File

@ -68,6 +68,7 @@ inline bool can_start(wchar_t c, const unsigned char* map, unsigned char mask)
// which succeeds when it should not.
//
#ifndef _RWSTD_VER
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
template <class C, class T, class A>
inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
{
@ -78,7 +79,9 @@ inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
}
return s.compare(p);
}
#endif
#else
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
template <class C, class T, class A>
inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
{
@ -89,6 +92,7 @@ inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
}
return s.compare(p);
}
#endif
inline int string_compare(const std::string& s, const char* p)
{ return std::strcmp(s.c_str(), p); }
# ifndef BOOST_NO_WREGEX
@ -96,7 +100,6 @@ inline int string_compare(const std::wstring& s, const wchar_t* p)
{ return std::wcscmp(s.c_str(), p); }
#endif
#endif
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1310)
template <class Seq, class C>
inline int string_compare(const Seq& s, const C* p)
{
@ -107,7 +110,6 @@ inline int string_compare(const Seq& s, const C* p)
}
return (i == s.size()) ? -p[i] : s[i] - p[i];
}
#endif
# define STR_COMP(s,p) string_compare(s,p)
template<class charT>
@ -325,13 +327,7 @@ public:
match_flag_type f);
bool match();
bool match_imp();
bool find();
bool find_imp();
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
typedef bool (perl_matcher::*protected_proc_type)();
bool protected_call(protected_proc_type);
#endif
void setf(match_flag_type f)
{ m_match_flags |= f; }
@ -339,6 +335,16 @@ public:
{ m_match_flags &= ~f; }
private:
void construct_init(BidiIterator first, BidiIterator end,
match_results<BidiIterator, Allocator>& what,
const basic_regex<char_type, traits>& e,
match_flag_type f);
bool find_imp();
bool match_imp();
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
typedef bool (perl_matcher::*protected_proc_type)();
bool protected_call(protected_proc_type);
#endif
void estimate_max_state_count(std::random_access_iterator_tag*);
void estimate_max_state_count(void*);
bool match_prefix();

View File

@ -39,6 +39,15 @@ perl_matcher<BidiIterator, Allocator, traits>::perl_matcher(BidiIterator first,
: m_result(what), base(first), last(end),
position(first), re(e), traits_inst(e.get_traits()),
m_independent(false), next_count(&rep_obj), rep_obj(&next_count)
{
construct_init(first, last, what, e, f);
}
template <class BidiIterator, class Allocator, class traits>
void perl_matcher<BidiIterator, Allocator, traits>::construct_init(BidiIterator first, BidiIterator end,
match_results<BidiIterator, Allocator>& what,
const basic_regex<char_type, traits>& e,
match_flag_type f)
{
typedef typename regex_iterator_traits<BidiIterator>::iterator_category category;

View File

@ -26,6 +26,7 @@
#endif
#include <algorithm>
#include <cstddef>
namespace boost{
namespace re_detail{

View File

@ -175,7 +175,8 @@ inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UChar* p, co
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);
typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
return u32regex_iterator<iter_type>(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)
{

View File

@ -61,7 +61,9 @@ public:
: 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)))\
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
// can't reliably get this to work....
#elif (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))
@ -190,7 +192,9 @@ public:
if(!pdata->init(a))
pdata.reset();
}
#if (BOOST_WORKAROUND(__BORLANDC__, >= 0x560) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)))\
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
// can't reliably get this to work....
#elif (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))
@ -284,13 +288,15 @@ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const
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);
typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
return u32regex_token_iterator<iter_type>(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);
}
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
// 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)
@ -314,13 +320,15 @@ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const
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);
typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
return u32regex_token_iterator<iter_type>(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);
}
#endif // BOOST_MSVC < 1300
// 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)
@ -342,7 +350,8 @@ inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const
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);
typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
return u32regex_token_iterator<iter_type>(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)
{