1 /*
2  *
3  * Copyright (c) 2003
4  * John Maddock
5  *
6  * Use, modification and distribution are subject to the
7  * Boost Software License, Version 1.0. (See accompanying file
8  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9  *
10  */
11 
12 //
13 // This define keep ICU in it's own namespace: helps us to track bugs that would
14 // otherwise go unnoticed:
15 //
16 #define U_USING_ICU_NAMESPACE 0
17 
18 #include <boost/regex/config.hpp>
19 
20 #if defined(BOOST_MSVC)
21 // this lets us compile at warning level 4 without seeing concept-check related warnings
22 #  pragma warning(disable:4100)
23 #endif
24 #ifdef __BORLANDC__
25 #pragma option -w-8019 -w-8004 -w-8008
26 #endif
27 
28 #ifdef BOOST_HAS_ICU
29 
30 #include <boost/regex/icu.hpp>
31 #include <boost/detail/workaround.hpp>
32 #if !BOOST_WORKAROUND(_MSC_VER, < 1310) && !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__) && !BOOST_WORKAROUND(__GNUC__, < 3)
33 #include <boost/regex/concepts.hpp>
34 #endif
35 
36 template <class I>
check_token_iterator(I i)37 void check_token_iterator(I i)
38 {
39    typedef typename I::value_type value_type;
40    typedef typename value_type::value_type char_type;
41    typedef std::basic_string<char_type> string_type;
42 
43    I j;
44 
45    std::vector<string_type> v;
46 
47    while (i != j)
48    {
49       v.push_back(i->str());
50       ++i;
51    }
52 
53 }
54 
55 template <class I>
check_iterator(I i)56 void check_iterator(I i)
57 {
58    typedef typename I::value_type value_type;
59 
60    std::vector <value_type> v(i, I());
61    (void)v;
62 
63 }
main()64 int main()
65 {
66    // VC6 and VC7 can't cope with the iterator architypes,
67    // don't bother testing as it doesn't work:
68 #if !BOOST_WORKAROUND(_MSC_VER, < 1310) && !defined(BOOST_NO_MEMBER_TEMPLATES) && !defined(__IBMCPP__) && !BOOST_WORKAROUND(__GNUC__, < 3)
69    boost::function_requires<
70       boost::RegexTraitsConcept<
71          boost::icu_regex_traits
72       >
73    >();
74    boost::function_requires<
75       boost::BoostRegexConcept<
76          boost::u32regex
77       >
78    >();
79    //
80    // Now test additional function overloads:
81    //
82    bool b;
83    unsigned long buf[2] = { 0, };
84    const void* pb = buf;
85    typedef boost::bidirectional_iterator_archetype<char> utf8_arch1;
86    typedef boost::bidirectional_iterator_archetype<unsigned char> utf8_arch2;
87    typedef boost::bidirectional_iterator_archetype<UChar> utf16_arch;
88    typedef boost::bidirectional_iterator_archetype<wchar_t> wchar_arch;
89    boost::match_results<utf8_arch1> m1;
90    boost::match_results<utf8_arch2> m2;
91    boost::match_results<utf16_arch> m3;
92    boost::match_results<wchar_arch> m4;
93    boost::match_results<const char*> cm1;
94    boost::match_results<const unsigned char*> cm2;
95    boost::match_results<const UChar*> cm3;
96    boost::match_results<const wchar_t*> cm4;
97    boost::match_results<std::string::const_iterator> sm1;
98    boost::match_results<std::wstring::const_iterator> sm2;
99    boost::u32regex e1;
100    boost::regex_constants::match_flag_type flgs = boost::regex_constants::match_default;
101    std::string s1;
102    std::wstring s2;
103    U_NAMESPACE_QUALIFIER UnicodeString us;
104    b = boost::u32regex_match(utf8_arch1(), utf8_arch1(), m1, e1, flgs);
105    b = boost::u32regex_match(utf8_arch1(), utf8_arch1(), m1, e1);
106    b = boost::u32regex_match(utf8_arch2(), utf8_arch2(), m2, e1, flgs);
107    b = boost::u32regex_match(utf8_arch2(), utf8_arch2(), m2, e1);
108    b = boost::u32regex_match(utf16_arch(), utf16_arch(), m3, e1, flgs);
109    b = boost::u32regex_match(utf16_arch(), utf16_arch(), m3, e1);
110    b = boost::u32regex_match(wchar_arch(), wchar_arch(), m4, e1, flgs);
111    b = boost::u32regex_match(wchar_arch(), wchar_arch(), m4, e1);
112    b = boost::u32regex_match((const char*)(pb), cm1, e1, flgs);
113    b = boost::u32regex_match((const char*)(pb), cm1, e1);
114    b = boost::u32regex_match((const unsigned char*)(pb), cm2, e1, flgs);
115    b = boost::u32regex_match((const unsigned char*)(pb), cm2, e1);
116    b = boost::u32regex_match((const UChar*)(pb), cm3, e1, flgs);
117    b = boost::u32regex_match((const UChar*)(pb), cm3, e1);
118    b = boost::u32regex_match((const wchar_t*)(pb), cm4, e1, flgs);
119    b = boost::u32regex_match((const wchar_t*)(pb), cm4, e1);
120    b = boost::u32regex_match(s1, sm1, e1, flgs);
121    b = boost::u32regex_match(s1, sm1, e1);
122    b = boost::u32regex_match(s2, sm2, e1, flgs);
123    b = boost::u32regex_match(s2, sm2, e1);
124    b = boost::u32regex_match(us, cm3, e1, flgs);
125    b = boost::u32regex_match(us, cm3, e1);
126 
127    b = boost::u32regex_search(utf8_arch1(), utf8_arch1(), m1, e1, flgs);
128    b = boost::u32regex_search(utf8_arch1(), utf8_arch1(), m1, e1);
129    b = boost::u32regex_search(utf8_arch2(), utf8_arch2(), m2, e1, flgs);
130    b = boost::u32regex_search(utf8_arch2(), utf8_arch2(), m2, e1);
131    b = boost::u32regex_search(utf16_arch(), utf16_arch(), m3, e1, flgs);
132    b = boost::u32regex_search(utf16_arch(), utf16_arch(), m3, e1);
133    b = boost::u32regex_search(wchar_arch(), wchar_arch(), m4, e1, flgs);
134    b = boost::u32regex_search(wchar_arch(), wchar_arch(), m4, e1);
135    b = boost::u32regex_search((const char*)(pb), cm1, e1, flgs);
136    b = boost::u32regex_search((const char*)(pb), cm1, e1);
137    b = boost::u32regex_search((const unsigned char*)(pb), cm2, e1, flgs);
138    b = boost::u32regex_search((const unsigned char*)(pb), cm2, e1);
139    b = boost::u32regex_search((const UChar*)(pb), cm3, e1, flgs);
140    b = boost::u32regex_search((const UChar*)(pb), cm3, e1);
141    b = boost::u32regex_search((const wchar_t*)(pb), cm4, e1, flgs);
142    b = boost::u32regex_search((const wchar_t*)(pb), cm4, e1);
143    b = boost::u32regex_search(s1, sm1, e1, flgs);
144    b = boost::u32regex_search(s1, sm1, e1);
145    b = boost::u32regex_search(s2, sm2, e1, flgs);
146    b = boost::u32regex_search(s2, sm2, e1);
147    b = boost::u32regex_search(us, cm3, e1, flgs);
148    b = boost::u32regex_search(us, cm3, e1);
149    boost::output_iterator_archetype<char> out1 = boost::detail::dummy_constructor();
150    out1 = boost::u32regex_replace(out1, utf8_arch1(), utf8_arch1(), e1, (const char*)(pb), flgs);
151    boost::output_iterator_archetype<unsigned char> out2 = boost::detail::dummy_constructor();
152    out2 = boost::u32regex_replace(out2, utf8_arch2(), utf8_arch2(), e1, (const unsigned char*)(pb), flgs);
153    boost::output_iterator_archetype<UChar> out3 = boost::detail::dummy_constructor();
154    out3 = boost::u32regex_replace(out3, utf16_arch(), utf16_arch(), e1, (const UChar*)(pb), flgs);
155    boost::output_iterator_archetype<wchar_t> out4 = boost::detail::dummy_constructor();
156    out4 = boost::u32regex_replace(out4, wchar_arch(), wchar_arch(), e1, (const wchar_t*)(pb), flgs);
157 
158    out1 = boost::u32regex_replace(out1, utf8_arch1(), utf8_arch1(), e1, s1, flgs);
159    out2 = boost::u32regex_replace(out2, utf8_arch2(), utf8_arch2(), e1, s1, flgs);
160    out3 = boost::u32regex_replace(out3, utf16_arch(), utf16_arch(), e1, s1, flgs);
161    out4 = boost::u32regex_replace(out4, wchar_arch(), wchar_arch(), e1, s1, flgs);
162    out1 = boost::u32regex_replace(out1, utf8_arch1(), utf8_arch1(), e1, s2, flgs);
163    out2 = boost::u32regex_replace(out2, utf8_arch2(), utf8_arch2(), e1, s2, flgs);
164    out3 = boost::u32regex_replace(out3, utf16_arch(), utf16_arch(), e1, s2, flgs);
165    out4 = boost::u32regex_replace(out4, wchar_arch(), wchar_arch(), e1, s2, flgs);
166    out1 = boost::u32regex_replace(out1, utf8_arch1(), utf8_arch1(), e1, us, flgs);
167    out2 = boost::u32regex_replace(out2, utf8_arch2(), utf8_arch2(), e1, us, flgs);
168    out3 = boost::u32regex_replace(out3, utf16_arch(), utf16_arch(), e1, us, flgs);
169    out4 = boost::u32regex_replace(out4, wchar_arch(), wchar_arch(), e1, us, flgs);
170    // string overloads:
171    s1 = boost::u32regex_replace(s1, e1, (const char*)(pb), flgs);
172    s2 = boost::u32regex_replace(s2, e1, (const wchar_t*)(pb), flgs);
173    s1 = boost::u32regex_replace(s1, e1, s1, flgs);
174    s2 = boost::u32regex_replace(s2, e1, s2, flgs);
175    s1 = boost::u32regex_replace(s1, e1, (const char*)(pb));
176    s2 = boost::u32regex_replace(s2, e1, (const wchar_t*)(pb));
177    s1 = boost::u32regex_replace(s1, e1, s1);
178    s2 = boost::u32regex_replace(s2, e1, s2);
179 
180    std::vector<int> subs1;
181    int subs2[2] = { 1, 2 };
182 
183    check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, 0, boost::regex_constants::match_default));
184    check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, 0));
185    check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1));
186    check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, 0, boost::regex_constants::match_default));
187    check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, 0));
188    check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1));
189    check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, 0, boost::regex_constants::match_default));
190    check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, 0));
191    check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1));
192    check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, 0, boost::regex_constants::match_default));
193    check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, 0));
194    check_token_iterator(boost::make_u32regex_token_iterator(s1, e1));
195    check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, 0, boost::regex_constants::match_default));
196    check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, 0));
197    check_token_iterator(boost::make_u32regex_token_iterator(s2, e1));
198    check_token_iterator(boost::make_u32regex_token_iterator(us, e1, 0, boost::regex_constants::match_default));
199    check_token_iterator(boost::make_u32regex_token_iterator(us, e1, 0));
200    check_token_iterator(boost::make_u32regex_token_iterator(us, e1));
201 
202    check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs2, boost::regex_constants::match_default));
203    check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs2));
204    check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs2, boost::regex_constants::match_default));
205    check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs2));
206    check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs2, boost::regex_constants::match_default));
207    check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs2));
208    check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs2, boost::regex_constants::match_default));
209    check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs2));
210    check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs2, boost::regex_constants::match_default));
211    check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs2));
212    check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs2, boost::regex_constants::match_default));
213    check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs2));
214 
215    check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs1, boost::regex_constants::match_default));
216    check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs1));
217    check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs1, boost::regex_constants::match_default));
218    check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs1));
219    check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs1, boost::regex_constants::match_default));
220    check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs1));
221    check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs1, boost::regex_constants::match_default));
222    check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs1));
223    check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs1, boost::regex_constants::match_default));
224    check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs1));
225    check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs1, boost::regex_constants::match_default));
226    check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs1));
227 
228    check_iterator(boost::make_u32regex_iterator((const char*)(pb), e1, boost::regex_constants::match_default));
229    check_iterator(boost::make_u32regex_iterator((const char*)(pb), e1));
230    check_iterator(boost::make_u32regex_iterator((const UChar*)(pb), e1, boost::regex_constants::match_default));
231    check_iterator(boost::make_u32regex_iterator((const UChar*)(pb), e1));
232    check_iterator(boost::make_u32regex_iterator((const wchar_t*)(pb), e1, boost::regex_constants::match_default));
233    check_iterator(boost::make_u32regex_iterator((const wchar_t*)(pb), e1));
234    check_iterator(boost::make_u32regex_iterator(s1, e1, boost::regex_constants::match_default));
235    check_iterator(boost::make_u32regex_iterator(s2, e1));
236    check_iterator(boost::make_u32regex_iterator(us, e1));
237 
238 #endif
239    return 0;
240 }
241 
242 #else
243 
main()244 int main()
245 {
246    return 0;
247 }
248 
249 #endif
250