Suppress external templates with Mingw32 - it seems to cause issues with dll's.

Fix match_results.swap.
Add missing namespace qualifiers to ICU code: fixes #3631.

[SVN r57739]
This commit is contained in:
John Maddock
2009-11-18 09:59:42 +00:00
parent 6e1f3dcceb
commit 97005c2017
8 changed files with 43 additions and 28 deletions

View File

@ -28,7 +28,7 @@
// Find out if *password* meets our password requirements, // Find out if *password* meets our password requirements,
// as defined by the regular expression *requirements*. // as defined by the regular expression *requirements*.
// //
bool is_valid_password(const UnicodeString& password, const UnicodeString& requirements) bool is_valid_password(const U_NAMESPACE_QUALIFIER UnicodeString& password, const U_NAMESPACE_QUALIFIER UnicodeString& requirements)
{ {
return boost::u32regex_match(password, boost::make_u32regex(requirements)); return boost::u32regex_match(password, boost::make_u32regex(requirements));
} }
@ -52,7 +52,7 @@ std::string get_filename(const std::string& path)
} }
} }
UnicodeString extract_greek(const UnicodeString& text) U_NAMESPACE_QUALIFIER UnicodeString extract_greek(const U_NAMESPACE_QUALIFIER UnicodeString& text)
{ {
// searches through some UTF-16 encoded text for a block encoded in Greek, // searches through some UTF-16 encoded text for a block encoded in Greek,
// this expression is imperfect, but the best we can do for now - searching // this expression is imperfect, but the best we can do for now - searching
@ -62,7 +62,7 @@ UnicodeString extract_greek(const UnicodeString& text)
if(boost::u32regex_search(text, what, r)) if(boost::u32regex_search(text, what, r))
{ {
// extract $0 as a UnicodeString: // extract $0 as a UnicodeString:
return UnicodeString(what[0].first, what.length(0)); return U_NAMESPACE_QUALIFIER UnicodeString(what[0].first, what.length(0));
} }
else else
{ {
@ -127,7 +127,7 @@ void enumerate_currencies2(const std::string& text)
const boost::u32regex e = boost::make_u32regex("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"); const boost::u32regex e = boost::make_u32regex("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
const char* human_format = "$1-$2-$3-$4"; const char* human_format = "$1-$2-$3-$4";
UnicodeString human_readable_card_number(const UnicodeString& s) U_NAMESPACE_QUALIFIER UnicodeString human_readable_card_number(const U_NAMESPACE_QUALIFIER UnicodeString& s)
{ {
return boost::u32regex_replace(s, e, human_format); return boost::u32regex_replace(s, e, human_format);
} }
@ -136,8 +136,8 @@ UnicodeString human_readable_card_number(const UnicodeString& s)
int main() int main()
{ {
// password checks using u32regex_match: // password checks using u32regex_match:
UnicodeString pwd = "abcDEF---"; U_NAMESPACE_QUALIFIER UnicodeString pwd = "abcDEF---";
UnicodeString pwd_check = "(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}"; U_NAMESPACE_QUALIFIER UnicodeString pwd_check = "(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}";
bool b = is_valid_password(pwd, pwd_check); bool b = is_valid_password(pwd, pwd_check);
assert(b); assert(b);
pwd = "abcD-"; pwd = "abcD-";
@ -152,8 +152,8 @@ int main()
assert(file == "d.h"); assert(file == "d.h");
// Greek text extraction with u32regex_search: // Greek text extraction with u32regex_search:
UnicodeString text = L"Some where in \x0391\x039D\x0395\x0398\x0391 2004"; U_NAMESPACE_QUALIFIER UnicodeString text = L"Some where in \x0391\x039D\x0395\x0398\x0391 2004";
UnicodeString greek = extract_greek(text); U_NAMESPACE_QUALIFIER UnicodeString greek = extract_greek(text);
assert(greek == L"\x0391\x039D\x0395\x0398\x0391 2004"); assert(greek == L"\x0391\x039D\x0395\x0398\x0391 2004");
// extract currency symbols with associated value, use iterator interface: // extract currency symbols with associated value, use iterator interface:
@ -161,7 +161,7 @@ int main()
enumerate_currencies(text2); enumerate_currencies(text2);
enumerate_currencies2(text2); enumerate_currencies2(text2);
UnicodeString credit_card_number = "1234567887654321"; U_NAMESPACE_QUALIFIER UnicodeString credit_card_number = "1234567887654321";
credit_card_number = human_readable_card_number(credit_card_number); credit_card_number = human_readable_card_number(credit_card_number);
assert(credit_card_number == "1234-5678-8765-4321"); assert(credit_card_number == "1234-5678-8765-4321");
return 0; return 0;

View File

@ -92,6 +92,12 @@
#if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS) #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
# define BOOST_REGEX_NO_EXTERNAL_TEMPLATES # define BOOST_REGEX_NO_EXTERNAL_TEMPLATES
#endif #endif
/*
* Shared regex lib will crash without this, frankly it looks a lot like a gcc bug:
*/
#if defined(__MINGW32__)
# define BOOST_REGEX_NO_EXTERNAL_TEMPLATES
#endif
/* /*
* If there isn't good enough wide character support then there will * If there isn't good enough wide character support then there will

View File

@ -376,7 +376,7 @@ inline u32regex make_u32regex(const std::basic_string<C, T, A>& s, boost::regex_
// //
// Construction from ICU string type: // Construction from ICU string type:
// //
inline u32regex make_u32regex(const UnicodeString& s, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl) inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER 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)); return re_detail::do_make_u32regex(s.getBuffer(), s.getBuffer() + s.length(), opt, static_cast<boost::mpl::int_<2> const*>(0));
} }
@ -498,7 +498,7 @@ inline bool u32regex_match(const std::wstring& s,
return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0)); return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
} }
#endif #endif
inline bool u32regex_match(const UnicodeString& s, inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
match_results<const UChar*>& m, match_results<const UChar*>& m,
const u32regex& e, const u32regex& e,
match_flag_type flags = match_default) match_flag_type flags = match_default)
@ -562,7 +562,7 @@ inline bool u32regex_match(const std::wstring& s,
return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0)); return re_detail::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
} }
#endif #endif
inline bool u32regex_match(const UnicodeString& s, inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s,
const u32regex& e, const u32regex& e,
match_flag_type flags = match_default) match_flag_type flags = match_default)
{ {
@ -683,7 +683,7 @@ inline bool u32regex_search(const std::wstring& s,
return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0)); return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
} }
#endif #endif
inline bool u32regex_search(const UnicodeString& s, inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
match_results<const UChar*>& m, match_results<const UChar*>& m,
const u32regex& e, const u32regex& e,
match_flag_type flags = match_default) match_flag_type flags = match_default)
@ -744,7 +744,7 @@ inline bool u32regex_search(const std::wstring& s,
return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0)); return re_detail::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast<mpl::int_<sizeof(wchar_t)> const*>(0));
} }
#endif #endif
inline bool u32regex_search(const UnicodeString& s, inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s,
const u32regex& e, const u32regex& e,
match_flag_type flags = match_default) match_flag_type flags = match_default)
{ {
@ -921,7 +921,7 @@ inline OutputIterator u32regex_replace(OutputIterator out,
Iterator first, Iterator first,
Iterator last, Iterator last,
const u32regex& e, const u32regex& e,
const UnicodeString& fmt, const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
match_flag_type flags = match_default) match_flag_type flags = match_default)
{ {
return re_detail::extract_output_base return re_detail::extract_output_base
@ -966,9 +966,9 @@ namespace re_detail{
class unicode_string_out_iterator class unicode_string_out_iterator
{ {
UnicodeString* out; U_NAMESPACE_QUALIFIER UnicodeString* out;
public: public:
unicode_string_out_iterator(UnicodeString& s) : out(&s) {} unicode_string_out_iterator(U_NAMESPACE_QUALIFIER UnicodeString& s) : out(&s) {}
unicode_string_out_iterator& operator++() { return *this; } unicode_string_out_iterator& operator++() { return *this; }
unicode_string_out_iterator& operator++(int) { return *this; } unicode_string_out_iterator& operator++(int) { return *this; }
unicode_string_out_iterator& operator*() { return *this; } unicode_string_out_iterator& operator*() { return *this; }
@ -986,23 +986,23 @@ public:
} }
inline UnicodeString u32regex_replace(const UnicodeString& s, inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
const u32regex& e, const u32regex& e,
const UChar* fmt, const UChar* fmt,
match_flag_type flags = match_default) match_flag_type flags = match_default)
{ {
UnicodeString result; U_NAMESPACE_QUALIFIER UnicodeString result;
re_detail::unicode_string_out_iterator i(result); re_detail::unicode_string_out_iterator i(result);
u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags); u32regex_replace(i, s.getBuffer(), s.getBuffer()+s.length(), e, fmt, flags);
return result; return result;
} }
inline UnicodeString u32regex_replace(const UnicodeString& s, inline U_NAMESPACE_QUALIFIER UnicodeString u32regex_replace(const U_NAMESPACE_QUALIFIER UnicodeString& s,
const u32regex& e, const u32regex& e,
const UnicodeString& fmt, const U_NAMESPACE_QUALIFIER UnicodeString& fmt,
match_flag_type flags = match_default) match_flag_type flags = match_default)
{ {
UnicodeString result; U_NAMESPACE_QUALIFIER UnicodeString result;
re_detail::unicode_string_out_iterator i(result); re_detail::unicode_string_out_iterator i(result);
re_detail::do_regex_replace( re_detail::do_regex_replace(
re_detail::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)), re_detail::make_utf32_out(i, static_cast<mpl::int_<2> const*>(0)),

View File

@ -348,6 +348,8 @@ public:
{ {
std::swap(m_subs, that.m_subs); std::swap(m_subs, that.m_subs);
std::swap(m_base, that.m_base); std::swap(m_base, that.m_base);
std::swap(m_named_subs, that.m_named_subs);
std::swap(m_last_closed_paren, that.m_last_closed_paren);
} }
bool operator==(const match_results& that)const bool operator==(const match_results& that)const
{ {

View File

@ -178,7 +178,7 @@ inline u32regex_iterator<typename std::basic_string<charT, Traits, Alloc>::const
typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type; typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
return u32regex_iterator<iter_type>(p.begin(), p.end(), e, m); 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) inline u32regex_iterator<const UChar*> make_u32regex_iterator(const U_NAMESPACE_QUALIFIER 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); return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
} }

View File

@ -294,7 +294,7 @@ inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>:
typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type; typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, m); 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) inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER 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); return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
} }
@ -327,7 +327,7 @@ inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>:
return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, m); return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, m);
} }
template <std::size_t N> 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) inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER 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); return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
} }
@ -356,7 +356,7 @@ inline u32regex_token_iterator<typename std::basic_string<charT, Traits, Alloc>:
typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type; typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
return u32regex_token_iterator<iter_type>(p.begin(), p.end(), e, m); 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) inline u32regex_token_iterator<const UChar*> make_u32regex_token_iterator(const U_NAMESPACE_QUALIFIER 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); return u32regex_token_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, submatch, m);
} }

View File

@ -8,6 +8,13 @@
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
* *
*/ */
//
// This define keep ICU in it's own namespace: helps us to track bugs that would
// otherwise go unnoticed:
//
#define U_USING_ICU_NAMESPACE 0
#include <boost/regex/config.hpp> #include <boost/regex/config.hpp>
#if defined(BOOST_MSVC) #if defined(BOOST_MSVC)
@ -66,7 +73,7 @@ int main()
boost::regex_constants::match_flag_type flgs = boost::regex_constants::match_default; boost::regex_constants::match_flag_type flgs = boost::regex_constants::match_default;
std::string s1; std::string s1;
std::wstring s2; std::wstring s2;
UnicodeString us; U_NAMESPACE_QUALIFIER UnicodeString us;
b = boost::u32regex_match(utf8_arch1(), utf8_arch1(), m1, e1, flgs); b = boost::u32regex_match(utf8_arch1(), utf8_arch1(), m1, e1, flgs);
b = boost::u32regex_match(utf8_arch1(), utf8_arch1(), m1, e1); b = boost::u32regex_match(utf8_arch1(), utf8_arch1(), m1, e1);
b = boost::u32regex_match(utf8_arch2(), utf8_arch2(), m2, e1, flgs); b = boost::u32regex_match(utf8_arch2(), utf8_arch2(), m2, e1, flgs);

View File

@ -564,7 +564,7 @@ void test_icu(const wchar_t&, const test_regex_replace_tag&)
// //
// Now with UnicodeString: // Now with UnicodeString:
// //
UnicodeString expression16u, text16u, format16u, result16u, found16u; U_NAMESPACE_QUALIFIER UnicodeString expression16u, text16u, format16u, result16u, found16u;
if(expression16.size()) if(expression16.size())
expression16u.setTo(&*expression16.begin(), expression16.size()); expression16u.setTo(&*expression16.begin(), expression16.size());
if(text16.size()) if(text16.size())