Added support for Perl style \N \P and \p.

Completed first draft of Unicode UCS-4 support.
Broken compiler compatibility fixes.
Added unicode_iterators.


[SVN r26185]
This commit is contained in:
John Maddock
2004-11-11 17:04:17 +00:00
parent f141de61ec
commit d35e5a088e
17 changed files with 1051 additions and 46 deletions
+12
View File
@@ -26,6 +26,7 @@ test_sets.cpp
test_simple_repeats.cpp
test_tricky_cases.cpp
test_icu.cpp
test_unicode.cpp
test_overloads.cpp
test_operators.cpp
;
@@ -120,6 +121,17 @@ test-suite regex
<lib>../../test/build/boost_test_exec_monitor
]
[ run unicode/unicode_iterator_test.cpp ]
[ regex-test static_mutex_test
: <template>test # sources
static_mutex/static_mutex_test.cpp
<dll>../../thread/build/boost_thread
]
[ regex-test object_cache_test
: <template>test # sources
object_cache/object_cache_test.cpp
]
[ run config_info/regex_config_info.cpp <template>test
: : : <test-info>always_show_run_output ]
+1
View File
@@ -53,6 +53,7 @@ int cpp_main(int /*argc*/, char * /*argv*/[])
test_emacs();
test_operators();
test_overloads();
test_unicode();
return error_count;
}
+1
View File
@@ -215,6 +215,7 @@ void test_en_locale();
void test_emacs();
void test_operators();
void test_overloads();
void test_unicode();
//
// template instances:
+17 -13
View File
@@ -19,7 +19,8 @@
//
// We can only build this if we have ICU support:
//
#ifdef TEST_ICU
#include <boost/regex/config.hpp>
#ifdef BOOST_HAS_ICU
#include <boost/regex/icu.hpp>
#include "test.hpp"
@@ -27,7 +28,6 @@
void test_icu(const wchar_t&, const test_regex_search_tag& )
{
typedef boost::u16_to_u32_iterator<std::wstring::const_iterator, ::UChar32> conv_iterator;
boost::u32regex r;
if(*test_locale::c_str())
{
@@ -37,26 +37,28 @@ void test_icu(const wchar_t&, const test_regex_search_tag& )
r.imbue(l);
}
const std::wstring& expression = test_info<wchar_t>::expression();
std::vector< ::UChar32> expression;
expression.assign(test_info<wchar_t>::expression().begin(), test_info<wchar_t>::expression().end());
boost::regex_constants::syntax_option_type syntax_options = test_info<UChar32>::syntax_options();
try{
r.assign(conv_iterator(expression.begin()), conv_iterator(expression.end()), syntax_options);
r.assign(expression.begin(), expression.end(), syntax_options);
if(r.status())
{
BOOST_REGEX_TEST_ERROR("Expression did not compile when it should have done, error code = " << r.status(), UChar32);
}
const std::wstring& search_text = test_info<wchar_t>::search_text();
std::vector< ::UChar32> search_text;
search_text.assign(test_info<wchar_t>::search_text().begin(), test_info<wchar_t>::search_text().end());
boost::regex_constants::match_flag_type opts = test_info<wchar_t>::match_options();
const int* answer_table = test_info<wchar_t>::answer_table();
boost::match_results<conv_iterator> what;
boost::match_results<std::vector< ::UChar32>::const_iterator> what;
if(boost::regex_search(
conv_iterator(search_text.begin()),
conv_iterator(search_text.end()),
const_cast<std::vector< ::UChar32>const&>(search_text).begin(),
const_cast<std::vector< ::UChar32>const&>(search_text).end(),
what,
r,
opts))
{
test_result(what, conv_iterator(search_text.begin()), answer_table);
test_result(what, const_cast<std::vector< ::UChar32>const&>(search_text).begin(), answer_table);
}
else if(answer_table[0] >= 0)
{
@@ -85,7 +87,8 @@ void test_icu(const wchar_t&, const test_regex_search_tag& )
void test_icu(const wchar_t&, const test_invalid_regex_tag&)
{
typedef boost::u16_to_u32_iterator<std::wstring::const_iterator, ::UChar32> conv_iterator;
const std::wstring& expression = test_info<wchar_t>::expression();
std::vector< ::UChar32> expression;
expression.assign(test_info<wchar_t>::expression().begin(), test_info<wchar_t>::expression().end());
boost::regex_constants::syntax_option_type syntax_options = test_info<wchar_t>::syntax_options();
boost::u32regex r;
if(*test_locale::c_str())
@@ -100,7 +103,7 @@ void test_icu(const wchar_t&, const test_invalid_regex_tag&)
//
try
{
if(0 == r.assign(conv_iterator(expression.begin()), conv_iterator(expression.end()), syntax_options | boost::regex_constants::no_except).status())
if(0 == r.assign(expression.begin(), expression.end(), syntax_options | boost::regex_constants::no_except).status())
{
BOOST_REGEX_TEST_ERROR("Expression compiled when it should not have done so.", wchar_t);
}
@@ -114,7 +117,7 @@ void test_icu(const wchar_t&, const test_invalid_regex_tag&)
//
bool have_catch = false;
try{
r.assign(conv_iterator(expression.begin()), conv_iterator(expression.end()), syntax_options);
r.assign(expression.begin(), expression.end(), syntax_options);
#ifdef BOOST_NO_EXCEPTIONS
if(r.status())
have_catch = true;
@@ -148,7 +151,8 @@ void test_icu(const wchar_t&, const test_invalid_regex_tag&)
void test_icu(const wchar_t&, const test_regex_replace_tag&)
{
const std::wstring& expression = test_info<wchar_t>::expression();
std::vector< ::UChar32> expression;
expression.assign(test_info<wchar_t>::expression().begin(), test_info<wchar_t>::expression().end());
boost::regex_constants::syntax_option_type syntax_options = test_info<UChar32>::syntax_options();
boost::u32regex r;
try{
+7
View File
@@ -75,6 +75,8 @@ void test_replace()
TEST_REGEX_REPLACE("(a+)(b+)", perl, " ...aabb,,", match_default|format_perl|format_no_copy, "\\0", "\0");
TEST_REGEX_REPLACE("(a+)(b+)", perl, " ...aabb,,", match_default|format_perl|format_no_copy, "()?:", "()?:");
TEST_REGEX_REPLACE("a+", perl, "...aaa,,", match_default|format_perl|format_no_copy, "\\0101", "A");
TEST_REGEX_REPLACE("(a+)(b+)", perl, " ...aabb,,", match_default|format_perl|format_no_copy, "\\1", "aa");
TEST_REGEX_REPLACE("(a+)(b+)", perl, " ...aabb,,", match_default|format_perl|format_no_copy, "\\2", "bb");
// move to copying unmatched data:
TEST_REGEX_REPLACE("a+", perl, "...aaa,,,", match_default|format_all, "bbb", "...bbb,,,");
@@ -101,5 +103,10 @@ void test_replace()
TEST_REGEX_REPLACE("a+(b+)", perl, "...aaabb,,,", match_default|format_perl|format_no_copy, "(?1abc:def)", "(?1abc:def)");
TEST_REGEX_REPLACE("a+(b+)", perl, "...", match_default|format_perl, "(?1abc:def)", "...");
TEST_REGEX_REPLACE("a+(b+)", perl, "...", match_default|format_perl|format_no_copy, "(?1abc:def)", "");
// probe bug reports and other special cases:
TEST_REGEX_REPLACE("([^\\d]+).*", normal|icase, "tesd 999 test", match_default|format_all, "($1)replace", "tesd replace");
TEST_REGEX_REPLACE("(a)(b)", perl, "ab", match_default|format_all, "$1:$2", "a:b");
TEST_REGEX_REPLACE("(a(c)?)|(b)", perl, "acab", match_default|format_all, "(?1(?2(C:):A):B:)", "C:AB:");
}
+62
View File
@@ -88,6 +88,7 @@ void test_sets()
TEST_REGEX_SEARCH("[[:space:]]+", extended, "a \n\t\rb", match_default, make_array(1, 5, -2, -2));
TEST_REGEX_SEARCH("[[:upper:]]+", extended, "aBCd", match_default, make_array(1, 3, -2, -2));
TEST_REGEX_SEARCH("[[:xdigit:]]+", extended, "p0f3Cx", match_default, make_array(1, 5, -2, -2));
TEST_REGEX_SEARCH("[\\d]+", perl, "a019b", match_default, make_array(1, 4, -2, -2));
//
// escapes are supported in character classes if we have either
@@ -243,5 +244,66 @@ void test_sets2()
TEST_REGEX_SEARCH("[\\s]+", perl, "AB AB", match_default, make_array(2, 5, -2, -2));
TEST_INVALID_REGEX("[\\S]", perl);
TEST_REGEX_SEARCH("\\S+", perl, " abc ", match_default, make_array(2, 5, -2, -2));
// and some Perl style properties:
TEST_REGEX_SEARCH("\\pl+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\Pl+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\pu+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\Pu+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\pd+", perl, "AB012AB", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\PD+", perl, "01abc01", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\ps+", perl, "AB AB", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\PS+", perl, " abc ", match_default, make_array(2, 5, -2, -2));
TEST_REGEX_SEARCH("\\p{alnum}+", perl, "-%@a0X_-", match_default, make_array(3, 6, -2, -2));
TEST_REGEX_SEARCH("\\p{alpha}+", perl, " -%@aX_0-", match_default, make_array(4, 6, -2, -2));
TEST_REGEX_SEARCH("\\p{blank}+", perl, "a \tb", match_default, make_array(1, 4, -2, -2));
TEST_REGEX_SEARCH("\\p{cntrl}+", perl, " a\n\tb", match_default, make_array(2, 4, -2, -2));
TEST_REGEX_SEARCH("\\p{digit}+", perl, "a019b", match_default, make_array(1, 4, -2, -2));
TEST_REGEX_SEARCH("\\p{graph}+", perl, " a%b ", match_default, make_array(1, 4, -2, -2));
TEST_REGEX_SEARCH("\\p{lower}+", perl, "AabC", match_default, make_array(1, 3, -2, -2));
TEST_REGEX_SEARCH("\\p{print}+", perl, "AabC", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("\\p{punct}+", perl, " %-&\t", match_default, make_array(1, 4, -2, -2));
TEST_REGEX_SEARCH("\\p{space}+", perl, "a \n\t\rb", match_default, make_array(1, 5, -2, -2));
TEST_REGEX_SEARCH("\\p{upper}+", perl, "aBCd", match_default, make_array(1, 3, -2, -2));
TEST_REGEX_SEARCH("\\p{xdigit}+", perl, "p0f3Cx", match_default, make_array(1, 5, -2, -2));
TEST_REGEX_SEARCH("\\P{alnum}+", perl, "-%@a", match_default, make_array(0, 3, -2, -2));
TEST_REGEX_SEARCH("\\P{alpha}+", perl, " -%@a", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("\\P{blank}+", perl, "a ", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\P{cntrl}+", perl, " a\n", match_default, make_array(0, 2, -2, -2));
TEST_REGEX_SEARCH("\\P{digit}+", perl, "a0", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\P{graph}+", perl, " a", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\P{lower}+", perl, "Aa", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\P{print}+", perl, "Absc", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\P{punct}+", perl, " %", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\P{space}+", perl, "a ", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\P{upper}+", perl, "aB", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\P{xdigit}+", perl, "pf", match_default, make_array(0, 1, -2, -2));
TEST_INVALID_REGEX("\\p{invalid class}", perl);
TEST_INVALID_REGEX("\\p{upper", perl);
TEST_INVALID_REGEX("\\p{", perl);
TEST_INVALID_REGEX("\\p", perl);
TEST_INVALID_REGEX("\\P{invalid class}", perl);
TEST_INVALID_REGEX("\\P{upper", perl);
TEST_INVALID_REGEX("\\P{", perl);
TEST_INVALID_REGEX("\\P", perl);
// try named characters:
TEST_REGEX_SEARCH("\\N{zero}", perl, "0", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\N{one}", perl, "1", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\N{two}", perl, "2", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\N{three}", perl, "3", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\N{a}", perl, "bac", match_default, make_array(1, 2, -2, -2));
TEST_REGEX_SEARCH("\\N{\xf0}", perl, "b\xf0x", match_default, make_array(1, 2, -2, -2));
TEST_REGEX_SEARCH("\\N{right-curly-bracket}", perl, "}", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("\\N{NUL}", perl, "\0", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH("[\\N{zero}-\\N{nine}]+", perl, " 0123456789 ", match_default, make_array(1, 11, -2, -2));
TEST_INVALID_REGEX("\\N", perl);
TEST_INVALID_REGEX("\\N{", perl);
TEST_INVALID_REGEX("\\N{}", perl);
TEST_INVALID_REGEX("\\N{invalid-name}", perl);
TEST_INVALID_REGEX("\\N{zero", perl);
}
+147
View File
@@ -0,0 +1,147 @@
/*
*
* 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 test_unicode.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Unicode specific tests (requires ICU).
*/
#include <boost/regex/config.hpp>
#ifdef BOOST_HAS_ICU
#include "test.hpp"
#ifdef BOOST_MSVC
#pragma warning(disable:4127)
#endif
#define TEST_REGEX_SEARCH_U(s, f, t, m, a)\
do{\
const wchar_t e[] = { s };\
std::wstring se(e, (sizeof(e) / sizeof(wchar_t)) - 1);\
const wchar_t st[] = { t };\
std::wstring sst(st, (sizeof(st) / sizeof(wchar_t)) - 1);\
test_info<wchar_t>::set_info(__FILE__, __LINE__, se, f, sst, m, a);\
test_icu(wchar_t(0), test_regex_search_tag());\
}while(0)
#define TEST_REGEX_CLASS_U(classname, character)\
TEST_REGEX_SEARCH_U(\
BOOST_JOIN(L, \
BOOST_STRINGIZE(\
BOOST_JOIN([[:, BOOST_JOIN(classname, :]])))), \
perl, \
BOOST_JOIN(L, \
BOOST_STRINGIZE(\
BOOST_JOIN(\x, character))), \
match_default, \
make_array(0, 1, -2, -2))
void test_unicode()
{
using namespace boost::regex_constants;
TEST_REGEX_CLASS_U(L*, 3108);
TEST_REGEX_CLASS_U(Letter, 3108);
TEST_REGEX_CLASS_U(Lu, 2145);
TEST_REGEX_CLASS_U(Uppercase Letter, 2145);
TEST_REGEX_CLASS_U(Ll, 2146);
TEST_REGEX_CLASS_U(Lowercase Letter, 2146);
TEST_REGEX_CLASS_U(Lt, 1FFC);
TEST_REGEX_CLASS_U(Titlecase Letter, 1FFC);
TEST_REGEX_CLASS_U(Lm, 1D61);
TEST_REGEX_CLASS_U(Modifier Letter, 1D61);
TEST_REGEX_CLASS_U(Lo, 1974);
TEST_REGEX_CLASS_U(Other Letter, 1974);
TEST_REGEX_CLASS_U(M*, 20EA);
TEST_REGEX_CLASS_U(Mark, 20EA);
TEST_REGEX_CLASS_U(Mn, 20EA);
TEST_REGEX_CLASS_U(Non-Spacing Mark, 20EA);
TEST_REGEX_CLASS_U(Mc, 1938);
TEST_REGEX_CLASS_U(Spacing Combining Mark, 1938);
TEST_REGEX_CLASS_U(Me, 06DE);
TEST_REGEX_CLASS_U(Enclosing Mark, 06DE);
TEST_REGEX_CLASS_U(N*, 0669);
TEST_REGEX_CLASS_U(Number, 0669);
TEST_REGEX_CLASS_U(Nd, 0669);
TEST_REGEX_CLASS_U(Decimal Digit Number, 0669);
TEST_REGEX_CLASS_U(Nl, 303A);
TEST_REGEX_CLASS_U(Letter Number, 303A);
TEST_REGEX_CLASS_U(No, 2793);
TEST_REGEX_CLASS_U(Other Number, 2793);
TEST_REGEX_CLASS_U(S*, 2144);
TEST_REGEX_CLASS_U(Symbol, 2144);
TEST_REGEX_CLASS_U(Sm, 2144);
TEST_REGEX_CLASS_U(Math Symbol, 2144);
TEST_REGEX_CLASS_U(Sc, 20B1);
TEST_REGEX_CLASS_U(Currency Symbol, 20B1);
TEST_REGEX_CLASS_U(Sk, 1FFE);
TEST_REGEX_CLASS_U(Modifier Symbol, 1FFE);
TEST_REGEX_CLASS_U(So, 19FF);
TEST_REGEX_CLASS_U(Other Symbol, 19FF);
TEST_REGEX_CLASS_U(P*, 005F);
TEST_REGEX_CLASS_U(Punctuation, 005F);
TEST_REGEX_CLASS_U(Pc, 005F);
TEST_REGEX_CLASS_U(Connector Punctuation, 005F);
TEST_REGEX_CLASS_U(Pd, 002D);
TEST_REGEX_CLASS_U(Dash Punctuation, 002D);
TEST_REGEX_CLASS_U(Ps, 0028);
TEST_REGEX_CLASS_U(Open Punctuation, 0028);
TEST_REGEX_CLASS_U(Pe, FF63);
TEST_REGEX_CLASS_U(Close Punctuation, FF63);
TEST_REGEX_CLASS_U(Pi, 2039);
TEST_REGEX_CLASS_U(Initial Punctuation, 2039);
TEST_REGEX_CLASS_U(Pf, 203A);
TEST_REGEX_CLASS_U(Final Punctuation, 203A);
TEST_REGEX_CLASS_U(Po, 2038);
TEST_REGEX_CLASS_U(Other Punctuation, 2038);
TEST_REGEX_CLASS_U(Z*, 202F);
TEST_REGEX_CLASS_U(Separator, 202F);
TEST_REGEX_CLASS_U(Zs, 202F);
TEST_REGEX_CLASS_U(Space Separator, 202F);
TEST_REGEX_CLASS_U(Zl, 2028);
TEST_REGEX_CLASS_U(Line Separator, 2028);
TEST_REGEX_CLASS_U(Zp, 2029);
TEST_REGEX_CLASS_U(Paragraph Separator, 2029);
TEST_REGEX_CLASS_U(C*, 009F);
TEST_REGEX_CLASS_U(Other, 009F);
TEST_REGEX_CLASS_U(Cc, 009F);
TEST_REGEX_CLASS_U(Control, 009F);
TEST_REGEX_CLASS_U(Cf, FFFB);
TEST_REGEX_CLASS_U(Format, FFFB);
TEST_REGEX_CLASS_U(Cs, DC00);
TEST_REGEX_CLASS_U(Surrogate, DC00);
TEST_REGEX_CLASS_U(Co, F8FF);
TEST_REGEX_CLASS_U(Private Use, F8FF);
TEST_REGEX_CLASS_U(Cn, FFFF);
TEST_REGEX_CLASS_U(Not Assigned, FFFF);
TEST_REGEX_CLASS_U(Any, 2038);
TEST_REGEX_CLASS_U(Assigned, 2038);
TEST_REGEX_CLASS_U(ASCII, 7f);
TEST_REGEX_SEARCH_U(L"[[:Assigned:]]", perl, L"\xffff", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH_U(L"[[:ASCII:]]", perl, L"\x80", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH_U(L"\\N{KHMER DIGIT SIX}", perl, L"\x17E6", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH_U(L"\\N{MODIFIER LETTER LOW ACUTE ACCENT}", perl, L"\x02CF", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH_U(L"\\N{SUPERSCRIPT ONE}", perl, L"\x00B9", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH_U(L"[\\N{KHMER DIGIT SIX}]", perl, L"\x17E6", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH_U(L"[\\N{MODIFIER LETTER LOW ACUTE ACCENT}]", perl, L"\x02CF", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH_U(L"[\\N{SUPERSCRIPT ONE}]", perl, L"\x00B9", match_default, make_array(0, 1, -2, -2));
TEST_REGEX_SEARCH_U(L"\\N{CJK UNIFIED IDEOGRAPH-7FED}", perl, L"\x7FED", match_default, make_array(0, 1, -2, -2));
}
#else
void test_unicode(){}
#endif
+99
View File
@@ -36,25 +36,70 @@ void spot_checks()
BOOST_CHECK_EQUAL(*--it, 0xDF02u);
BOOST_CHECK_EQUAL(*--it, 0xD800u);
::boost::uint32_t spot8[] = { 0x004Du, 0x0430u, 0x4E8Cu, 0x10302u, };
typedef boost::u32_to_u8_iterator<const ::boost::uint32_t*> u32to8type;
u32to8type it8(spot8);
BOOST_CHECK_EQUAL(*it8++, 0x4Du);
BOOST_CHECK_EQUAL(*it8++, 0xD0u);
BOOST_CHECK_EQUAL(*it8++, 0xB0u);
BOOST_CHECK_EQUAL(*it8++, 0xE4u);
BOOST_CHECK_EQUAL(*it8++, 0xBAu);
BOOST_CHECK_EQUAL(*it8++, 0x8Cu);
BOOST_CHECK_EQUAL(*it8++, 0xF0u);
BOOST_CHECK_EQUAL(*it8++, 0x90u);
BOOST_CHECK_EQUAL(*it8++, 0x8Cu);
BOOST_CHECK_EQUAL(*it8++, 0x82u);
BOOST_CHECK_EQUAL(*--it8, 0x82u);
BOOST_CHECK_EQUAL(*--it8, 0x8Cu);
BOOST_CHECK_EQUAL(*--it8, 0x90u);
BOOST_CHECK_EQUAL(*--it8, 0xF0u);
BOOST_CHECK_EQUAL(*--it8, 0x8Cu);
BOOST_CHECK_EQUAL(*--it8, 0xBAu);
BOOST_CHECK_EQUAL(*--it8, 0xE4u);
BOOST_CHECK_EQUAL(*--it8, 0xB0u);
BOOST_CHECK_EQUAL(*--it8, 0xD0u);
BOOST_CHECK_EQUAL(*--it8, 0x4Du);
}
void test(const std::vector< ::boost::uint32_t>& v)
{
typedef std::vector< ::boost::uint32_t> vector32_type;
typedef std::vector< ::boost::uint16_t> vector16_type;
typedef std::vector< ::boost::uint8_t> vector8_type;
typedef boost::u32_to_u16_iterator<vector32_type::const_iterator, ::boost::uint16_t> u32to16type;
typedef boost::u16_to_u32_iterator<vector16_type::const_iterator, ::boost::uint32_t> u16to32type;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef std::reverse_iterator<u32to16type> ru32to16type;
typedef std::reverse_iterator<u16to32type> ru16to32type;
#endif
typedef boost::u32_to_u8_iterator<vector32_type::const_iterator, ::boost::uint8_t> u32to8type;
typedef boost::u8_to_u32_iterator<vector8_type::const_iterator, ::boost::uint32_t> u8to32type;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef std::reverse_iterator<u32to8type> ru32to8type;
typedef std::reverse_iterator<u8to32type> ru8to32type;
#endif
vector8_type v8;
vector16_type v16;
vector32_type v32;
vector32_type::const_iterator i, j, k;
//
// begin by testing forward iteration, of 32-16 bit interconversions:
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
v16.assign(u32to16type(v.begin()), u32to16type(v.end()));
#else
v16.clear();
std::copy(u32to16type(v.begin()), u32to16type(v.end()), std::back_inserter(v16));
#endif
BOOST_CHECK_EQUAL(std::distance(u32to16type(v.begin()), u32to16type(v.end())), v16.size());
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
v32.assign(u16to32type(v16.begin()), u16to32type(v16.end()));
#else
v32.clear();
std::copy(u16to32type(v16.begin()), u16to32type(v16.end()), std::back_inserter(v32));
#endif
BOOST_CHECK_EQUAL(std::distance(u16to32type(v16.begin()), u16to32type(v16.end())), v32.size());
BOOST_CHECK_EQUAL(v.size(), v32.size());
i = v.begin();
@@ -68,6 +113,7 @@ void test(const std::vector< ::boost::uint32_t>& v)
//
// test backward iteration, of 32-16 bit interconversions:
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
v16.assign(ru32to16type(u32to16type(v.end())), ru32to16type(u32to16type(v.begin())));
BOOST_CHECK_EQUAL(std::distance(ru32to16type(u32to16type(v.end())), ru32to16type(u32to16type(v.begin()))), v16.size());
std::reverse(v16.begin(), v16.end());
@@ -83,6 +129,53 @@ void test(const std::vector< ::boost::uint32_t>& v)
i,
j,
k);
#endif
//
// Test forward iteration, of 32-8 bit interconversions:
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
v8.assign(u32to8type(v.begin()), u32to8type(v.end()));
#else
v8.clear();
std::copy(u32to8type(v.begin()), u32to8type(v.end()), std::back_inserter(v8));
#endif
BOOST_CHECK_EQUAL(std::distance(u32to8type(v.begin()), u32to8type(v.end())), v8.size());
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
v32.assign(u8to32type(v8.begin()), u8to32type(v8.end()));
#else
v32.clear();
std::copy(u8to32type(v8.begin()), u8to32type(v8.end()), std::back_inserter(v32));
#endif
BOOST_CHECK_EQUAL(std::distance(u8to32type(v8.begin()), u8to32type(v8.end())), v32.size());
BOOST_CHECK_EQUAL(v.size(), v32.size());
i = v.begin();
j = i;
std::advance(j, (std::min)(v.size(), v32.size()));
k = v32.begin();
BOOST_CHECK_EQUAL_COLLECTIONS(
i,
j,
k);
//
// test backward iteration, of 32-8 bit interconversions:
//
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
v8.assign(ru32to8type(u32to8type(v.end())), ru32to8type(u32to8type(v.begin())));
BOOST_CHECK_EQUAL(std::distance(ru32to8type(u32to8type(v.end())), ru32to8type(u32to8type(v.begin()))), v8.size());
std::reverse(v8.begin(), v8.end());
v32.assign(ru8to32type(u8to32type(v8.end())), ru8to32type(u8to32type(v8.begin())));
BOOST_CHECK_EQUAL(std::distance(ru8to32type(u8to32type(v8.end())), ru8to32type(u8to32type(v8.begin()))), v32.size());
BOOST_CHECK_EQUAL(v.size(), v32.size());
std::reverse(v32.begin(), v32.end());
i = v.begin();
j = i;
std::advance(j, (std::min)(v.size(), v32.size()));
k = v32.begin();
BOOST_CHECK_EQUAL_COLLECTIONS(
i,
j,
k);
#endif
}
int test_main( int, char* [] )
@@ -98,6 +191,12 @@ int test_main( int, char* [] )
v.push_back(0xFFFF);
v.push_back(0x10000);
v.push_back(0x10FFFF);
v.push_back(0x80u);
v.push_back(0x80u - 1);
v.push_back(0x800u);
v.push_back(0x800u - 1);
v.push_back(0x10000u);
v.push_back(0x10000u - 1);
test(v);
return 0;
}