1 ///////////////////////////////////////////////////////////////////////////////
4 // Copyright 2008 Eric Niebler. Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/xpressive/xpressive.hpp>
10 #include <boost/xpressive/traits/null_regex_traits.hpp>
13 ///////////////////////////////////////////////////////////////////////////////
17 static int const data
[] = {0, 1, 2, 3, 4, 5, 6};
18 null_regex_traits
<int> nul
;
19 basic_regex
<int const *> rex
= imbue(nul
)(1 >> +((set
= 2,3) | 4) >> 5);
20 match_results
<int const *> what
;
22 if(!regex_search(data
, data
+ (sizeof(data
)/sizeof(*data
)), what
, rex
))
24 BOOST_ERROR("regex_search on integral data failed");
28 BOOST_CHECK(*what
[0].first
== 1);
29 BOOST_CHECK(*what
[0].second
== 6);
33 ///////////////////////////////////////////////////////////////////////////////
37 UChar(unsigned int code
= 0)
41 operator unsigned int () const
50 ///////////////////////////////////////////////////////////////////////////////
53 : null_regex_traits
<UChar
>
56 ///////////////////////////////////////////////////////////////////////////////
60 typedef std::vector
<UChar
>::const_iterator uchar_iterator
;
61 typedef basic_regex
<uchar_iterator
> uregex
;
62 typedef match_results
<uchar_iterator
> umatch
;
63 typedef regex_compiler
<uchar_iterator
, UChar_traits
> uregex_compiler
;
65 std::string
pattern_("b.*r"), str_("foobarboo");
66 std::vector
<UChar
> pattern(pattern_
.begin(), pattern_
.end());
67 std::vector
<UChar
> str(str_
.begin(), str_
.end());
70 uregex_compiler
compiler(tr
);
71 uregex urx
= compiler
.compile(pattern
);
74 if(!regex_search(str
, what
, urx
))
76 BOOST_ERROR("regex_search on UChar failed");
80 BOOST_CHECK_EQUAL(3, what
.position());
81 BOOST_CHECK_EQUAL(3, what
.length());
84 // test for range-based regex_replace
85 std::vector
<UChar
> output
= regex_replace(str
, urx
, pattern_
);
86 std::string
output_(output
.begin(), output
.end());
87 std::string
expected("foob.*rboo");
88 BOOST_CHECK_EQUAL(output_
, expected
);
91 ///////////////////////////////////////////////////////////////////////////////
92 // init_unit_test_suite
94 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
96 test_suite
*test
= BOOST_TEST_SUITE("test_non_char");
97 test
->add(BOOST_TEST_CASE(&test_static
));
98 test
->add(BOOST_TEST_CASE(&test_dynamic
));