]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/regex/test/collate_info/collate_info.cpp
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)
12 // most of the workarounds and headers we need are already in here:
13 #include <boost/regex.hpp>
14 #include <boost/regex/v4/primary_transform.hpp>
16 #include <boost/detail/lightweight_main.hpp>
21 #pragma warning(disable:1418 981 983 2259)
24 #ifdef BOOST_NO_STDC_NAMESPACE
27 #ifndef BOOST_NO_WREGEX
35 template <class charT
>
43 return static_cast<unsigned char>(c
);
46 template <class charT
>
47 void print_string(const std::basic_string
<charT
>& s
)
49 typedef typename
std::basic_string
<charT
>::size_type size_type
;
50 std::cout
.put(static_cast<unsigned char>('"'));
51 for(size_type i
= 0; i
< s
.size(); ++i
)
53 if((s
[i
] > ' ') && (s
[i
] <= 'z'))
55 std::cout
.put(static_cast<unsigned char>(s
[i
]));
59 std::cout
<< "\\x" << std::hex
<< make_int(s
[i
]);
62 std::cout
.put(static_cast<unsigned char>('"'));
65 void print_c_char(char c
)
68 const char cbuf
[2] = { c
, 0, };
69 std::size_t len
= std::strxfrm(buf
, cbuf
, 50);
70 std:: cout
<< len
<< " ";
74 #ifndef BOOST_NO_WREGEX
75 void print_c_char(wchar_t c
)
78 const wchar_t cbuf
[2] = { c
, 0, };
79 std::size_t len
= std::wcsxfrm(buf
, cbuf
, 50);
80 std:: cout
<< len
<< " ";
85 template <class charT
>
86 void print_c_info(charT
, const char* name
)
88 std::cout
<< "Info for " << name
<< " C API's:" << std::endl
;
89 std::cout
<< " \"a\" : ";
90 print_c_char(charT('a'));
91 std::cout
<< std::endl
;
92 std::cout
<< " \"A\" : ";
93 print_c_char(charT('A'));
94 std::cout
<< std::endl
;
95 std::cout
<< " \"z\" : ";
96 print_c_char(charT('z'));
97 std::cout
<< std::endl
;
98 std::cout
<< " \"Z\" : ";
99 print_c_char(charT('Z'));
100 std::cout
<< std::endl
;
101 std::cout
<< " \";\" : ";
102 print_c_char(charT(';'));
103 std::cout
<< std::endl
;
104 std::cout
<< " \"{\" : ";
105 print_c_char(charT('{'));
106 std::cout
<< std::endl
;
109 template <class charT
>
110 void print_cpp_char(charT c
)
112 #ifndef BOOST_NO_STD_LOCALE
114 const std::collate
<charT
>& col
= BOOST_USE_FACET(std::collate
<charT
>, l
);
115 std::basic_string
<charT
> result
= col
.transform(&c
, &c
+1);
116 std::cout
<< result
.size() << " ";
117 print_string(result
);
118 std::size_t n
= result
.find(charT(0));
119 if(n
!= std::basic_string
<charT
>::npos
)
121 std::cerr
<< "(Error in location of null, found: " << n
<< ")";
126 template <class charT
>
127 void print_cpp_info(charT
, const char* name
)
129 std::cout
<< "Info for " << name
<< " C++ locale API's:" << std::endl
;
130 std::cout
<< " \"a\" : ";
131 print_cpp_char(charT('a'));
132 std::cout
<< std::endl
;
133 std::cout
<< " \"A\" : ";
134 print_cpp_char(charT('A'));
135 std::cout
<< std::endl
;
136 std::cout
<< " \"z\" : ";
137 print_cpp_char(charT('z'));
138 std::cout
<< std::endl
;
139 std::cout
<< " \"Z\" : ";
140 print_cpp_char(charT('Z'));
141 std::cout
<< std::endl
;
142 std::cout
<< " \";\" : ";
143 print_cpp_char(charT(';'));
144 std::cout
<< std::endl
;
145 std::cout
<< " \"{\" : ";
146 print_cpp_char(charT('{'));
147 std::cout
<< std::endl
;
150 template <class traits
>
151 void print_sort_syntax(const traits
& pt
, const char* name
)
153 std::cout
<< "Sort Key Syntax for type " << name
<< ":\n";
154 typedef typename
traits::char_type char_type
;
156 unsigned result
= ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(&pt
, &delim
);
160 case boost::BOOST_REGEX_DETAIL_NS::sort_C
:
161 std::cout
<< "sort_C";
163 case boost::BOOST_REGEX_DETAIL_NS::sort_fixed
:
164 std::cout
<< "sort_fixed" << " " << static_cast<int>(delim
);
166 case boost::BOOST_REGEX_DETAIL_NS::sort_delim
:
168 std::cout
<< "sort_delim" << " ";
169 std::basic_string
<char_type
> s(1, delim
);
173 case boost::BOOST_REGEX_DETAIL_NS::sort_unknown
:
174 std::cout
<< "sort_unknown";
177 std::cout
<< "bad_value";
180 std::cout
<< std::endl
;
182 typedef typename
traits::string_type string_type
;
183 typedef typename
traits::char_type char_type
;
185 char_type c
[5] = { 'a', 'A', ';', '{', '}', };
186 for(int i
= 0; i
< 5; ++i
)
188 string_type
s(1, c
[i
]);
189 string_type sk
= pt
.transform(s
.c_str(), s
.c_str() + s
.size());
190 string_type skp
= pt
.transform_primary(s
.c_str(), s
.c_str() + s
.size());
196 std::cout
<< std::endl
;
200 #ifndef BOOST_NO_STD_LOCALE
201 template <class charT
>
202 void print_ctype_info(charT
, const char* name
)
205 const std::ctype
<charT
>& ct
= BOOST_USE_FACET(std::ctype
<charT
>, l
);
206 typedef typename
std::ctype
<charT
>::mask mask_type
;
207 mask_type m
= static_cast<mask_type
>(std::ctype
<charT
>::lower
| std::ctype
<charT
>::upper
);
208 bool result
= ct
.is(m
, static_cast<charT
>('a')) && ct
.is(m
, static_cast<charT
>('A'));
209 std::cout
<< "Checking std::ctype<" << name
<< ">::is(mask, c):" << std::endl
;
210 #ifdef BOOST_REGEX_BUGGY_CTYPE_FACET
211 std::cout
<< " Boost.Regex believes this facet to be buggy..." << std::endl
;
213 std::cout
<< " Boost.Regex believes this facet to be correct..." << std::endl
;
215 std::cout
<< " Actual behavior, appears to be " << (result
? "correct." : "buggy.") << std::endl
;
216 assert(ct
.is(std::ctype
<charT
>::alnum
, 'a'));
217 assert(ct
.is(std::ctype
<charT
>::alnum
, 'A'));
218 assert(ct
.is(std::ctype
<charT
>::alnum
, '0'));
222 int cpp_main(int /*argc*/, char * /*argv*/[])
224 print_c_info(char(0), "char");
225 #ifndef BOOST_NO_WREGEX
226 print_c_info(wchar_t(0), "wchar_t");
228 print_cpp_info(char(0), "char");
229 #ifndef BOOST_NO_WREGEX
230 print_cpp_info(wchar_t(0), "wchar_t");
233 #if !BOOST_WORKAROUND(BOOST_BORLANDC, < 0x560)
234 boost::c_regex_traits
<char> a
;
235 print_sort_syntax(a
, "boost::c_regex_traits<char>");
236 #ifndef BOOST_NO_WREGEX
237 boost::c_regex_traits
<wchar_t> b
;
238 print_sort_syntax(b
, "boost::c_regex_traits<wchar_t>");
241 #ifndef BOOST_NO_STD_LOCALE
242 boost::cpp_regex_traits
<char> c
;
243 print_sort_syntax(c
, "boost::cpp_regex_traits<char>");
244 #ifndef BOOST_NO_WREGEX
245 boost::cpp_regex_traits
<wchar_t> d
;
246 print_sort_syntax(d
, "boost::cpp_regex_traits<wchar_t>");
248 print_ctype_info(char(0), "char");
249 #ifndef BOOST_NO_WREGEX
250 print_ctype_info(wchar_t(0), "wchar_t");