600
|
1 |
/*
|
|
2 |
*
|
|
3 |
* Copyright (c) 2004
|
|
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 |
* LOCATION: see http://www.boost.org for most recent version.
|
|
14 |
* FILE w32_regex_traits.hpp
|
|
15 |
* VERSION see <boost/version.hpp>
|
|
16 |
* DESCRIPTION: Declares regular expression traits class w32_regex_traits.
|
|
17 |
*/
|
|
18 |
|
|
19 |
#ifndef BOOST_W32_REGEX_TRAITS_HPP_INCLUDED
|
|
20 |
#define BOOST_W32_REGEX_TRAITS_HPP_INCLUDED
|
|
21 |
|
|
22 |
#ifndef BOOST_RE_PAT_EXCEPT_HPP
|
|
23 |
#include <boost/regex/pattern_except.hpp>
|
|
24 |
#endif
|
|
25 |
#ifndef BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
|
|
26 |
#include <boost/regex/v4/regex_traits_defaults.hpp>
|
|
27 |
#endif
|
|
28 |
#ifdef BOOST_HAS_THREADS
|
|
29 |
#include <boost/regex/pending/static_mutex.hpp>
|
|
30 |
#endif
|
|
31 |
#ifndef BOOST_REGEX_PRIMARY_TRANSFORM
|
|
32 |
#include <boost/regex/v4/primary_transform.hpp>
|
|
33 |
#endif
|
|
34 |
#ifndef BOOST_REGEX_OBJECT_CACHE_HPP
|
|
35 |
#include <boost/regex/pending/object_cache.hpp>
|
|
36 |
#endif
|
|
37 |
|
|
38 |
#ifdef BOOST_MSVC
|
|
39 |
#pragma warning(push)
|
|
40 |
#pragma warning(disable: 4103)
|
|
41 |
#endif
|
|
42 |
#ifdef BOOST_HAS_ABI_HEADERS
|
|
43 |
# include BOOST_ABI_PREFIX
|
|
44 |
#endif
|
|
45 |
#ifdef BOOST_MSVC
|
|
46 |
#pragma warning(pop)
|
|
47 |
#endif
|
|
48 |
|
|
49 |
#ifdef BOOST_MSVC
|
|
50 |
#pragma warning(push)
|
|
51 |
#pragma warning(disable:4786)
|
|
52 |
#pragma warning(disable:4800)
|
|
53 |
#endif
|
|
54 |
|
|
55 |
namespace boost{
|
|
56 |
|
|
57 |
//
|
|
58 |
// forward declaration is needed by some compilers:
|
|
59 |
//
|
|
60 |
template <class charT>
|
|
61 |
class w32_regex_traits;
|
|
62 |
|
|
63 |
namespace re_detail{
|
|
64 |
|
|
65 |
//
|
|
66 |
// start by typedeffing the types we'll need:
|
|
67 |
//
|
|
68 |
typedef ::boost::uint32_t lcid_type; // placeholder for LCID.
|
|
69 |
typedef ::boost::shared_ptr<void> cat_type; // placeholder for dll HANDLE.
|
|
70 |
|
|
71 |
//
|
|
72 |
// then add wrappers around the actual Win32 API's (ie implementation hiding):
|
|
73 |
//
|
|
74 |
BOOST_REGEX_DECL lcid_type BOOST_REGEX_CALL w32_get_default_locale();
|
|
75 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(char, lcid_type);
|
|
76 |
#ifndef BOOST_NO_WREGEX
|
|
77 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(wchar_t, lcid_type);
|
|
78 |
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
79 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_lower(unsigned short ca, lcid_type state_id);
|
|
80 |
#endif
|
|
81 |
#endif
|
|
82 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(char, lcid_type);
|
|
83 |
#ifndef BOOST_NO_WREGEX
|
|
84 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(wchar_t, lcid_type);
|
|
85 |
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
86 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is_upper(unsigned short ca, lcid_type state_id);
|
|
87 |
#endif
|
|
88 |
#endif
|
|
89 |
BOOST_REGEX_DECL cat_type BOOST_REGEX_CALL w32_cat_open(const std::string& name);
|
|
90 |
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type state_id, int i, const std::string& def);
|
|
91 |
#ifndef BOOST_NO_WREGEX
|
|
92 |
BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type state_id, int i, const std::wstring& def);
|
|
93 |
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
94 |
BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_cat_get(const cat_type& cat, lcid_type, int i, const std::basic_string<unsigned short>& def);
|
|
95 |
#endif
|
|
96 |
#endif
|
|
97 |
BOOST_REGEX_DECL std::string BOOST_REGEX_CALL w32_transform(lcid_type state_id, const char* p1, const char* p2);
|
|
98 |
#ifndef BOOST_NO_WREGEX
|
|
99 |
BOOST_REGEX_DECL std::wstring BOOST_REGEX_CALL w32_transform(lcid_type state_id, const wchar_t* p1, const wchar_t* p2);
|
|
100 |
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
101 |
BOOST_REGEX_DECL std::basic_string<unsigned short> BOOST_REGEX_CALL w32_transform(lcid_type state_id, const unsigned short* p1, const unsigned short* p2);
|
|
102 |
#endif
|
|
103 |
#endif
|
|
104 |
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_tolower(char c, lcid_type);
|
|
105 |
#ifndef BOOST_NO_WREGEX
|
|
106 |
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_tolower(wchar_t c, lcid_type);
|
|
107 |
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
108 |
BOOST_REGEX_DECL unsigned short BOOST_REGEX_CALL w32_tolower(unsigned short c, lcid_type state_id);
|
|
109 |
#endif
|
|
110 |
#endif
|
|
111 |
BOOST_REGEX_DECL char BOOST_REGEX_CALL w32_toupper(char c, lcid_type);
|
|
112 |
#ifndef BOOST_NO_WREGEX
|
|
113 |
BOOST_REGEX_DECL wchar_t BOOST_REGEX_CALL w32_toupper(wchar_t c, lcid_type);
|
|
114 |
#endif
|
|
115 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type, boost::uint32_t mask, char c);
|
|
116 |
#ifndef BOOST_NO_WREGEX
|
|
117 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type, boost::uint32_t mask, wchar_t c);
|
|
118 |
#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
|
|
119 |
BOOST_REGEX_DECL bool BOOST_REGEX_CALL w32_is(lcid_type state_id, boost::uint32_t m, unsigned short c);
|
|
120 |
#endif
|
|
121 |
#endif
|
|
122 |
//
|
|
123 |
// class w32_regex_traits_base:
|
|
124 |
// acts as a container for locale and the facets we are using.
|
|
125 |
//
|
|
126 |
template <class charT>
|
|
127 |
struct w32_regex_traits_base
|
|
128 |
{
|
|
129 |
w32_regex_traits_base(lcid_type l)
|
|
130 |
{ imbue(l); }
|
|
131 |
lcid_type imbue(lcid_type l);
|
|
132 |
|
|
133 |
lcid_type m_locale;
|
|
134 |
};
|
|
135 |
|
|
136 |
template <class charT>
|
|
137 |
inline lcid_type w32_regex_traits_base<charT>::imbue(lcid_type l)
|
|
138 |
{
|
|
139 |
lcid_type result(m_locale);
|
|
140 |
m_locale = l;
|
|
141 |
return result;
|
|
142 |
}
|
|
143 |
|
|
144 |
//
|
|
145 |
// class w32_regex_traits_char_layer:
|
|
146 |
// implements methods that require specialisation for narrow characters:
|
|
147 |
//
|
|
148 |
template <class charT>
|
|
149 |
class w32_regex_traits_char_layer : public w32_regex_traits_base<charT>
|
|
150 |
{
|
|
151 |
typedef std::basic_string<charT> string_type;
|
|
152 |
typedef std::map<charT, regex_constants::syntax_type> map_type;
|
|
153 |
typedef typename map_type::const_iterator map_iterator_type;
|
|
154 |
public:
|
|
155 |
w32_regex_traits_char_layer(const lcid_type l);
|
|
156 |
|
|
157 |
regex_constants::syntax_type syntax_type(charT c)const
|
|
158 |
{
|
|
159 |
map_iterator_type i = m_char_map.find(c);
|
|
160 |
return ((i == m_char_map.end()) ? 0 : i->second);
|
|
161 |
}
|
|
162 |
regex_constants::escape_syntax_type escape_syntax_type(charT c) const
|
|
163 |
{
|
|
164 |
map_iterator_type i = m_char_map.find(c);
|
|
165 |
if(i == m_char_map.end())
|
|
166 |
{
|
|
167 |
if(::boost::re_detail::w32_is_lower(c, this->m_locale)) return regex_constants::escape_type_class;
|
|
168 |
if(::boost::re_detail::w32_is_upper(c, this->m_locale)) return regex_constants::escape_type_not_class;
|
|
169 |
return 0;
|
|
170 |
}
|
|
171 |
return i->second;
|
|
172 |
}
|
|
173 |
charT tolower(charT c)const
|
|
174 |
{
|
|
175 |
return ::boost::re_detail::w32_tolower(c, this->m_locale);
|
|
176 |
}
|
|
177 |
bool isctype(boost::uint32_t mask, charT c)const
|
|
178 |
{
|
|
179 |
return ::boost::re_detail::w32_is(this->m_locale, mask, c);
|
|
180 |
}
|
|
181 |
|
|
182 |
private:
|
|
183 |
string_type get_default_message(regex_constants::syntax_type);
|
|
184 |
// TODO: use a hash table when available!
|
|
185 |
map_type m_char_map;
|
|
186 |
};
|
|
187 |
|
|
188 |
template <class charT>
|
|
189 |
w32_regex_traits_char_layer<charT>::w32_regex_traits_char_layer(::boost::re_detail::lcid_type l)
|
|
190 |
: w32_regex_traits_base<charT>(l)
|
|
191 |
{
|
|
192 |
// we need to start by initialising our syntax map so we know which
|
|
193 |
// character is used for which purpose:
|
|
194 |
cat_type cat;
|
|
195 |
std::string cat_name(w32_regex_traits<charT>::get_catalog_name());
|
|
196 |
if(cat_name.size())
|
|
197 |
{
|
|
198 |
cat = ::boost::re_detail::w32_cat_open(cat_name);
|
|
199 |
if(!cat)
|
|
200 |
{
|
|
201 |
std::string m("Unable to open message catalog: ");
|
|
202 |
std::runtime_error err(m + cat_name);
|
|
203 |
boost::re_detail::raise_runtime_error(err);
|
|
204 |
}
|
|
205 |
}
|
|
206 |
//
|
|
207 |
// if we have a valid catalog then load our messages:
|
|
208 |
//
|
|
209 |
if(cat)
|
|
210 |
{
|
|
211 |
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
|
|
212 |
{
|
|
213 |
string_type mss = ::boost::re_detail::w32_cat_get(cat, this->m_locale, i, get_default_message(i));
|
|
214 |
for(typename string_type::size_type j = 0; j < mss.size(); ++j)
|
|
215 |
{
|
|
216 |
this->m_char_map[mss[j]] = i;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
else
|
|
221 |
{
|
|
222 |
for(regex_constants::syntax_type i = 1; i < regex_constants::syntax_max; ++i)
|
|
223 |
{
|
|
224 |
const char* ptr = get_default_syntax(i);
|
|
225 |
while(ptr && *ptr)
|
|
226 |
{
|
|
227 |
this->m_char_map[static_cast<charT>(*ptr)] = i;
|
|
228 |
++ptr;
|
|
229 |
}
|
|
230 |
}
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
template <class charT>
|
|
235 |
typename w32_regex_traits_char_layer<charT>::string_type
|
|
236 |
w32_regex_traits_char_layer<charT>::get_default_message(regex_constants::syntax_type i)
|
|
237 |
{
|
|
238 |
const char* ptr = get_default_syntax(i);
|
|
239 |
string_type result;
|
|
240 |
while(ptr && *ptr)
|
|
241 |
{
|
|
242 |
result.append(1, static_cast<charT>(*ptr));
|
|
243 |
++ptr;
|
|
244 |
}
|
|
245 |
return result;
|
|
246 |
}
|
|
247 |
|
|
248 |
//
|
|
249 |
// specialised version for narrow characters:
|
|
250 |
//
|
|
251 |
template <>
|
|
252 |
class BOOST_REGEX_DECL w32_regex_traits_char_layer<char> : public w32_regex_traits_base<char>
|
|
253 |
{
|
|
254 |
typedef std::string string_type;
|
|
255 |
public:
|
|
256 |
w32_regex_traits_char_layer(::boost::re_detail::lcid_type l)
|
|
257 |
: w32_regex_traits_base<char>(l)
|
|
258 |
{
|
|
259 |
init();
|
|
260 |
}
|
|
261 |
|
|
262 |
regex_constants::syntax_type syntax_type(char c)const
|
|
263 |
{
|
|
264 |
return m_char_map[static_cast<unsigned char>(c)];
|
|
265 |
}
|
|
266 |
regex_constants::escape_syntax_type escape_syntax_type(char c) const
|
|
267 |
{
|
|
268 |
return m_char_map[static_cast<unsigned char>(c)];
|
|
269 |
}
|
|
270 |
char tolower(char c)const
|
|
271 |
{
|
|
272 |
return m_lower_map[static_cast<unsigned char>(c)];
|
|
273 |
}
|
|
274 |
bool isctype(boost::uint32_t mask, char c)const
|
|
275 |
{
|
|
276 |
return m_type_map[static_cast<unsigned char>(c)] & mask;
|
|
277 |
}
|
|
278 |
|
|
279 |
private:
|
|
280 |
regex_constants::syntax_type m_char_map[1u << CHAR_BIT];
|
|
281 |
char m_lower_map[1u << CHAR_BIT];
|
|
282 |
boost::uint16_t m_type_map[1u << CHAR_BIT];
|
|
283 |
void init();
|
|
284 |
};
|
|
285 |
|
|
286 |
//
|
|
287 |
// class w32_regex_traits_implementation:
|
|
288 |
// provides pimpl implementation for w32_regex_traits.
|
|
289 |
//
|
|
290 |
template <class charT>
|
|
291 |
class w32_regex_traits_implementation : public w32_regex_traits_char_layer<charT>
|
|
292 |
{
|
|
293 |
public:
|
|
294 |
typedef typename w32_regex_traits<charT>::char_class_type char_class_type;
|
|
295 |
BOOST_STATIC_CONSTANT(char_class_type, mask_word = 0x0400); // must be C1_DEFINED << 1
|
|
296 |
BOOST_STATIC_CONSTANT(char_class_type, mask_unicode = 0x0800); // must be C1_DEFINED << 2
|
|
297 |
BOOST_STATIC_CONSTANT(char_class_type, mask_base = 0x3ff); // all the masks used by the CT_CTYPE1 group
|
|
298 |
|
|
299 |
typedef std::basic_string<charT> string_type;
|
|
300 |
typedef charT char_type;
|
|
301 |
w32_regex_traits_implementation(::boost::re_detail::lcid_type l);
|
|
302 |
std::string error_string(regex_constants::error_type n) const
|
|
303 |
{
|
|
304 |
if(!m_error_strings.empty())
|
|
305 |
{
|
|
306 |
std::map<int, std::string>::const_iterator p = m_error_strings.find(n);
|
|
307 |
return (p == m_error_strings.end()) ? std::string(get_default_error_string(n)) : p->second;
|
|
308 |
}
|
|
309 |
return get_default_error_string(n);
|
|
310 |
}
|
|
311 |
char_class_type lookup_classname(const charT* p1, const charT* p2) const
|
|
312 |
{
|
|
313 |
char_class_type result = lookup_classname_imp(p1, p2);
|
|
314 |
if(result == 0)
|
|
315 |
{
|
|
316 |
typedef typename string_type::size_type size_type;
|
|
317 |
string_type temp(p1, p2);
|
|
318 |
for(size_type i = 0; i < temp.size(); ++i)
|
|
319 |
temp[i] = this->tolower(temp[i]);
|
|
320 |
result = lookup_classname_imp(&*temp.begin(), &*temp.begin() + temp.size());
|
|
321 |
}
|
|
322 |
return result;
|
|
323 |
}
|
|
324 |
string_type lookup_collatename(const charT* p1, const charT* p2) const;
|
|
325 |
string_type transform_primary(const charT* p1, const charT* p2) const;
|
|
326 |
string_type transform(const charT* p1, const charT* p2) const
|
|
327 |
{
|
|
328 |
return ::boost::re_detail::w32_transform(this->m_locale, p1, p2);
|
|
329 |
}
|
|
330 |
private:
|
|
331 |
std::map<int, std::string> m_error_strings; // error messages indexed by numberic ID
|
|
332 |
std::map<string_type, char_class_type> m_custom_class_names; // character class names
|
|
333 |
std::map<string_type, string_type> m_custom_collate_names; // collating element names
|
|
334 |
unsigned m_collate_type; // the form of the collation string
|
|
335 |
charT m_collate_delim; // the collation group delimiter
|
|
336 |
//
|
|
337 |
// helpers:
|
|
338 |
//
|
|
339 |
char_class_type lookup_classname_imp(const charT* p1, const charT* p2) const;
|
|
340 |
};
|
|
341 |
|
|
342 |
template <class charT>
|
|
343 |
typename w32_regex_traits_implementation<charT>::string_type
|
|
344 |
w32_regex_traits_implementation<charT>::transform_primary(const charT* p1, const charT* p2) const
|
|
345 |
{
|
|
346 |
string_type result;
|
|
347 |
//
|
|
348 |
// What we do here depends upon the format of the sort key returned by
|
|
349 |
// sort key returned by this->transform:
|
|
350 |
//
|
|
351 |
switch(m_collate_type)
|
|
352 |
{
|
|
353 |
case sort_C:
|
|
354 |
case sort_unknown:
|
|
355 |
// the best we can do is translate to lower case, then get a regular sort key:
|
|
356 |
{
|
|
357 |
result.assign(p1, p2);
|
|
358 |
typedef typename string_type::size_type size_type;
|
|
359 |
for(size_type i = 0; i < result.size(); ++i)
|
|
360 |
result[i] = this->tolower(result[i]);
|
|
361 |
result = this->transform(&*result.begin(), &*result.begin() + result.size());
|
|
362 |
break;
|
|
363 |
}
|
|
364 |
case sort_fixed:
|
|
365 |
{
|
|
366 |
// get a regular sort key, and then truncate it:
|
|
367 |
result.assign(this->transform(p1, p2));
|
|
368 |
result.erase(this->m_collate_delim);
|
|
369 |
break;
|
|
370 |
}
|
|
371 |
case sort_delim:
|
|
372 |
// get a regular sort key, and then truncate everything after the delim:
|
|
373 |
result.assign(this->transform(p1, p2));
|
|
374 |
std::size_t i;
|
|
375 |
for(i = 0; i < result.size(); ++i)
|
|
376 |
{
|
|
377 |
if(result[i] == m_collate_delim)
|
|
378 |
break;
|
|
379 |
}
|
|
380 |
result.erase(i);
|
|
381 |
break;
|
|
382 |
}
|
|
383 |
if(result.empty())
|
|
384 |
result = string_type(1, charT(0));
|
|
385 |
return result;
|
|
386 |
}
|
|
387 |
|
|
388 |
template <class charT>
|
|
389 |
typename w32_regex_traits_implementation<charT>::string_type
|
|
390 |
w32_regex_traits_implementation<charT>::lookup_collatename(const charT* p1, const charT* p2) const
|
|
391 |
{
|
|
392 |
typedef typename std::map<string_type, string_type>::const_iterator iter_type;
|
|
393 |
if(m_custom_collate_names.size())
|
|
394 |
{
|
|
395 |
iter_type pos = m_custom_collate_names.find(string_type(p1, p2));
|
|
396 |
if(pos != m_custom_collate_names.end())
|
|
397 |
return pos->second;
|
|
398 |
}
|
|
399 |
#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
|
|
400 |
&& !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
|
|
401 |
&& !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
|
|
402 |
std::string name(p1, p2);
|
|
403 |
#else
|
|
404 |
std::string name;
|
|
405 |
const charT* p0 = p1;
|
|
406 |
while(p0 != p2)
|
|
407 |
name.append(1, char(*p0++));
|
|
408 |
#endif
|
|
409 |
name = lookup_default_collate_name(name);
|
|
410 |
#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
|
|
411 |
&& !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
|
|
412 |
&& !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
|
|
413 |
if(name.size())
|
|
414 |
return string_type(name.begin(), name.end());
|
|
415 |
#else
|
|
416 |
if(name.size())
|
|
417 |
{
|
|
418 |
string_type result;
|
|
419 |
typedef std::string::const_iterator iter;
|
|
420 |
iter b = name.begin();
|
|
421 |
iter e = name.end();
|
|
422 |
while(b != e)
|
|
423 |
result.append(1, charT(*b++));
|
|
424 |
return result;
|
|
425 |
}
|
|
426 |
#endif
|
|
427 |
if(p2 - p1 == 1)
|
|
428 |
return string_type(1, *p1);
|
|
429 |
return string_type();
|
|
430 |
}
|
|
431 |
|
|
432 |
template <class charT>
|
|
433 |
w32_regex_traits_implementation<charT>::w32_regex_traits_implementation(::boost::re_detail::lcid_type l)
|
|
434 |
: w32_regex_traits_char_layer<charT>(l)
|
|
435 |
{
|
|
436 |
cat_type cat;
|
|
437 |
std::string cat_name(w32_regex_traits<charT>::get_catalog_name());
|
|
438 |
if(cat_name.size())
|
|
439 |
{
|
|
440 |
cat = ::boost::re_detail::w32_cat_open(cat_name);
|
|
441 |
if(!cat)
|
|
442 |
{
|
|
443 |
std::string m("Unable to open message catalog: ");
|
|
444 |
std::runtime_error err(m + cat_name);
|
|
445 |
boost::re_detail::raise_runtime_error(err);
|
|
446 |
}
|
|
447 |
}
|
|
448 |
//
|
|
449 |
// if we have a valid catalog then load our messages:
|
|
450 |
//
|
|
451 |
if(cat)
|
|
452 |
{
|
|
453 |
//
|
|
454 |
// Error messages:
|
|
455 |
//
|
|
456 |
for(boost::regex_constants::error_type i = static_cast<boost::regex_constants::error_type>(0);
|
|
457 |
i <= boost::regex_constants::error_unknown;
|
|
458 |
i = static_cast<boost::regex_constants::error_type>(i + 1))
|
|
459 |
{
|
|
460 |
const char* p = get_default_error_string(i);
|
|
461 |
string_type default_message;
|
|
462 |
while(*p)
|
|
463 |
{
|
|
464 |
default_message.append(1, static_cast<charT>(*p));
|
|
465 |
++p;
|
|
466 |
}
|
|
467 |
string_type s = ::boost::re_detail::w32_cat_get(cat, this->m_locale, i+200, default_message);
|
|
468 |
std::string result;
|
|
469 |
for(std::string::size_type j = 0; j < s.size(); ++j)
|
|
470 |
{
|
|
471 |
result.append(1, static_cast<char>(s[j]));
|
|
472 |
}
|
|
473 |
m_error_strings[i] = result;
|
|
474 |
}
|
|
475 |
//
|
|
476 |
// Custom class names:
|
|
477 |
//
|
|
478 |
static const char_class_type masks[14] =
|
|
479 |
{
|
|
480 |
0x0104u, // C1_ALPHA | C1_DIGIT
|
|
481 |
0x0100u, // C1_ALPHA
|
|
482 |
0x0020u, // C1_CNTRL
|
|
483 |
0x0004u, // C1_DIGIT
|
|
484 |
(~(0x0020u|0x0008u) & 0x01ffu) | 0x0400u, // not C1_CNTRL or C1_SPACE
|
|
485 |
0x0002u, // C1_LOWER
|
|
486 |
(~0x0020u & 0x01ffu) | 0x0400, // not C1_CNTRL
|
|
487 |
0x0010u, // C1_PUNCT
|
|
488 |
0x0008u, // C1_SPACE
|
|
489 |
0x0001u, // C1_UPPER
|
|
490 |
0x0080u, // C1_XDIGIT
|
|
491 |
0x0040u, // C1_BLANK
|
|
492 |
w32_regex_traits_implementation<charT>::mask_word,
|
|
493 |
w32_regex_traits_implementation<charT>::mask_unicode,
|
|
494 |
};
|
|
495 |
static const string_type null_string;
|
|
496 |
for(unsigned int j = 0; j <= 13; ++j)
|
|
497 |
{
|
|
498 |
string_type s(::boost::re_detail::w32_cat_get(cat, this->m_locale, j+300, null_string));
|
|
499 |
if(s.size())
|
|
500 |
this->m_custom_class_names[s] = masks[j];
|
|
501 |
}
|
|
502 |
}
|
|
503 |
//
|
|
504 |
// get the collation format used by m_pcollate:
|
|
505 |
//
|
|
506 |
m_collate_type = re_detail::find_sort_syntax(this, &m_collate_delim);
|
|
507 |
}
|
|
508 |
|
|
509 |
template <class charT>
|
|
510 |
typename w32_regex_traits_implementation<charT>::char_class_type
|
|
511 |
w32_regex_traits_implementation<charT>::lookup_classname_imp(const charT* p1, const charT* p2) const
|
|
512 |
{
|
|
513 |
static const char_class_type masks[20] =
|
|
514 |
{
|
|
515 |
0,
|
|
516 |
0x0104u, // C1_ALPHA | C1_DIGIT
|
|
517 |
0x0100u, // C1_ALPHA
|
|
518 |
0x0040u, // C1_BLANK
|
|
519 |
0x0020u, // C1_CNTRL
|
|
520 |
0x0004u, // C1_DIGIT
|
|
521 |
0x0004u, // C1_DIGIT
|
|
522 |
(~(0x0020u|0x0008u|0x0040) & 0x01ffu) | 0x0400u, // not C1_CNTRL or C1_SPACE or C1_BLANK
|
|
523 |
0x0002u, // C1_LOWER
|
|
524 |
0x0002u, // C1_LOWER
|
|
525 |
(~0x0020u & 0x01ffu) | 0x0400, // not C1_CNTRL
|
|
526 |
0x0010u, // C1_PUNCT
|
|
527 |
0x0008u, // C1_SPACE
|
|
528 |
0x0008u, // C1_SPACE
|
|
529 |
0x0001u, // C1_UPPER
|
|
530 |
w32_regex_traits_implementation<charT>::mask_unicode,
|
|
531 |
0x0001u, // C1_UPPER
|
|
532 |
0x0104u | w32_regex_traits_implementation<charT>::mask_word,
|
|
533 |
0x0104u | w32_regex_traits_implementation<charT>::mask_word,
|
|
534 |
0x0080u, // C1_XDIGIT
|
|
535 |
};
|
|
536 |
if(m_custom_class_names.size())
|
|
537 |
{
|
|
538 |
typedef typename std::map<std::basic_string<charT>, char_class_type>::const_iterator map_iter;
|
|
539 |
map_iter pos = m_custom_class_names.find(string_type(p1, p2));
|
|
540 |
if(pos != m_custom_class_names.end())
|
|
541 |
return pos->second;
|
|
542 |
}
|
|
543 |
std::size_t state_id = 1 + re_detail::get_default_class_id(p1, p2);
|
|
544 |
if(state_id < sizeof(masks) / sizeof(masks[0]))
|
|
545 |
return masks[state_id];
|
|
546 |
return masks[0];
|
|
547 |
}
|
|
548 |
|
|
549 |
|
|
550 |
template <class charT>
|
|
551 |
boost::shared_ptr<const w32_regex_traits_implementation<charT> > create_w32_regex_traits(::boost::re_detail::lcid_type l BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(charT))
|
|
552 |
{
|
|
553 |
// TODO: create a cache for previously constructed objects.
|
|
554 |
return boost::object_cache< ::boost::re_detail::lcid_type, w32_regex_traits_implementation<charT> >::get(l, 5);
|
|
555 |
}
|
|
556 |
|
|
557 |
} // re_detail
|
|
558 |
|
|
559 |
template <class charT>
|
|
560 |
class w32_regex_traits
|
|
561 |
{
|
|
562 |
public:
|
|
563 |
typedef charT char_type;
|
|
564 |
typedef std::size_t size_type;
|
|
565 |
typedef std::basic_string<char_type> string_type;
|
|
566 |
typedef ::boost::re_detail::lcid_type locale_type;
|
|
567 |
typedef boost::uint_least32_t char_class_type;
|
|
568 |
|
|
569 |
struct boost_extensions_tag{};
|
|
570 |
|
|
571 |
w32_regex_traits()
|
|
572 |
: m_pimpl(re_detail::create_w32_regex_traits<charT>(::boost::re_detail::w32_get_default_locale()))
|
|
573 |
{ }
|
|
574 |
static size_type length(const char_type* p)
|
|
575 |
{
|
|
576 |
return std::char_traits<charT>::length(p);
|
|
577 |
}
|
|
578 |
regex_constants::syntax_type syntax_type(charT c)const
|
|
579 |
{
|
|
580 |
return m_pimpl->syntax_type(c);
|
|
581 |
}
|
|
582 |
regex_constants::escape_syntax_type escape_syntax_type(charT c) const
|
|
583 |
{
|
|
584 |
return m_pimpl->escape_syntax_type(c);
|
|
585 |
}
|
|
586 |
charT translate(charT c) const
|
|
587 |
{
|
|
588 |
return c;
|
|
589 |
}
|
|
590 |
charT translate_nocase(charT c) const
|
|
591 |
{
|
|
592 |
return this->m_pimpl->tolower(c);
|
|
593 |
}
|
|
594 |
charT translate(charT c, bool icase) const
|
|
595 |
{
|
|
596 |
return icase ? this->m_pimpl->tolower(c) : c;
|
|
597 |
}
|
|
598 |
charT tolower(charT c) const
|
|
599 |
{
|
|
600 |
return this->m_pimpl->tolower(c);
|
|
601 |
}
|
|
602 |
charT toupper(charT c) const
|
|
603 |
{
|
|
604 |
return ::boost::re_detail::w32_toupper(c, this->m_pimpl->m_locale);
|
|
605 |
}
|
|
606 |
string_type transform(const charT* p1, const charT* p2) const
|
|
607 |
{
|
|
608 |
return ::boost::re_detail::w32_transform(this->m_pimpl->m_locale, p1, p2);
|
|
609 |
}
|
|
610 |
string_type transform_primary(const charT* p1, const charT* p2) const
|
|
611 |
{
|
|
612 |
return m_pimpl->transform_primary(p1, p2);
|
|
613 |
}
|
|
614 |
char_class_type lookup_classname(const charT* p1, const charT* p2) const
|
|
615 |
{
|
|
616 |
return m_pimpl->lookup_classname(p1, p2);
|
|
617 |
}
|
|
618 |
string_type lookup_collatename(const charT* p1, const charT* p2) const
|
|
619 |
{
|
|
620 |
return m_pimpl->lookup_collatename(p1, p2);
|
|
621 |
}
|
|
622 |
bool isctype(charT c, char_class_type f) const
|
|
623 |
{
|
|
624 |
if((f & re_detail::w32_regex_traits_implementation<charT>::mask_base)
|
|
625 |
&& (this->m_pimpl->isctype(f & re_detail::w32_regex_traits_implementation<charT>::mask_base, c)))
|
|
626 |
return true;
|
|
627 |
else if((f & re_detail::w32_regex_traits_implementation<charT>::mask_unicode) && re_detail::is_extended(c))
|
|
628 |
return true;
|
|
629 |
else if((f & re_detail::w32_regex_traits_implementation<charT>::mask_word) && (c == '_'))
|
|
630 |
return true;
|
|
631 |
return false;
|
|
632 |
}
|
|
633 |
int toi(const charT*& p1, const charT* p2, int radix)const
|
|
634 |
{
|
|
635 |
return ::boost::re_detail::global_toi(p1, p2, radix, *this);
|
|
636 |
}
|
|
637 |
int value(charT c, int radix)const
|
|
638 |
{
|
|
639 |
int result = ::boost::re_detail::global_value(c);
|
|
640 |
return result < radix ? result : -1;
|
|
641 |
}
|
|
642 |
locale_type imbue(locale_type l)
|
|
643 |
{
|
|
644 |
::boost::re_detail::lcid_type result(getloc());
|
|
645 |
m_pimpl = re_detail::create_w32_regex_traits<charT>(l);
|
|
646 |
return result;
|
|
647 |
}
|
|
648 |
locale_type getloc()const
|
|
649 |
{
|
|
650 |
return m_pimpl->m_locale;
|
|
651 |
}
|
|
652 |
std::string error_string(regex_constants::error_type n) const
|
|
653 |
{
|
|
654 |
return m_pimpl->error_string(n);
|
|
655 |
}
|
|
656 |
|
|
657 |
//
|
|
658 |
// extension:
|
|
659 |
// set the name of the message catalog in use (defaults to "boost_regex").
|
|
660 |
//
|
|
661 |
static std::string catalog_name(const std::string& name);
|
|
662 |
static std::string get_catalog_name();
|
|
663 |
|
|
664 |
private:
|
|
665 |
boost::shared_ptr<const re_detail::w32_regex_traits_implementation<charT> > m_pimpl;
|
|
666 |
//
|
|
667 |
// catalog name handler:
|
|
668 |
//
|
|
669 |
static std::string& get_catalog_name_inst();
|
|
670 |
|
|
671 |
#ifdef BOOST_HAS_THREADS
|
|
672 |
static static_mutex& get_mutex_inst();
|
|
673 |
#endif
|
|
674 |
};
|
|
675 |
|
|
676 |
template <class charT>
|
|
677 |
std::string w32_regex_traits<charT>::catalog_name(const std::string& name)
|
|
678 |
{
|
|
679 |
#ifdef BOOST_HAS_THREADS
|
|
680 |
static_mutex::scoped_lock lk(get_mutex_inst());
|
|
681 |
#endif
|
|
682 |
std::string result(get_catalog_name_inst());
|
|
683 |
get_catalog_name_inst() = name;
|
|
684 |
return result;
|
|
685 |
}
|
|
686 |
|
|
687 |
template <class charT>
|
|
688 |
std::string& w32_regex_traits<charT>::get_catalog_name_inst()
|
|
689 |
{
|
|
690 |
static std::string s_name;
|
|
691 |
return s_name;
|
|
692 |
}
|
|
693 |
|
|
694 |
template <class charT>
|
|
695 |
std::string w32_regex_traits<charT>::get_catalog_name()
|
|
696 |
{
|
|
697 |
#ifdef BOOST_HAS_THREADS
|
|
698 |
static_mutex::scoped_lock lk(get_mutex_inst());
|
|
699 |
#endif
|
|
700 |
std::string result(get_catalog_name_inst());
|
|
701 |
return result;
|
|
702 |
}
|
|
703 |
|
|
704 |
#ifdef BOOST_HAS_THREADS
|
|
705 |
template <class charT>
|
|
706 |
static_mutex& w32_regex_traits<charT>::get_mutex_inst()
|
|
707 |
{
|
|
708 |
static static_mutex s_mutex = BOOST_STATIC_MUTEX_INIT;
|
|
709 |
return s_mutex;
|
|
710 |
}
|
|
711 |
#endif
|
|
712 |
|
|
713 |
|
|
714 |
} // boost
|
|
715 |
|
|
716 |
#ifdef BOOST_MSVC
|
|
717 |
#pragma warning(pop)
|
|
718 |
#endif
|
|
719 |
|
|
720 |
#ifdef BOOST_MSVC
|
|
721 |
#pragma warning(push)
|
|
722 |
#pragma warning(disable: 4103)
|
|
723 |
#endif
|
|
724 |
#ifdef BOOST_HAS_ABI_HEADERS
|
|
725 |
# include BOOST_ABI_SUFFIX
|
|
726 |
#endif
|
|
727 |
#ifdef BOOST_MSVC
|
|
728 |
#pragma warning(pop)
|
|
729 |
#endif
|
|
730 |
|
|
731 |
#endif
|