icu_concept_check.cpp 13 KB

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