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)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE: wc_regex_traits.cpp
15 * VERSION: see <boost/version.hpp>
16 * DESCRIPTION: Implements out of line members for c_regex_traits<wchar_t>
20 #define BOOST_REGEX_SOURCE
22 #include <boost/detail/workaround.hpp>
25 #include "internals.hpp"
27 #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) && defined(_NATIVE_WCHAR_T_DEFINED) \
28 && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) || defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER))\
29 && BOOST_WORKAROUND(BOOST_MSVC, <1600)
31 // This is a horrible workaround, but without declaring these symbols extern we get
32 // duplicate symbol errors when linking if the application is built without
36 # define BOOST_REGEX_STDLIB_DECL _CRTIMP2_PURE
38 # define BOOST_REGEX_STDLIB_DECL _CRTIMP2
43 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
44 template class BOOST_REGEX_STDLIB_DECL allocator
<unsigned short>;
45 template class BOOST_REGEX_STDLIB_DECL _String_val
<unsigned short, allocator
<unsigned short> >;
46 template class BOOST_REGEX_STDLIB_DECL basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >;
49 #if BOOST_WORKAROUND(BOOST_MSVC, > 1300) && BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400))
50 template<> BOOST_REGEX_STDLIB_DECL
std::size_t __cdecl char_traits
<unsigned short>::length(unsigned short const*);
53 template BOOST_REGEX_STDLIB_DECL
bool __cdecl
operator==(
54 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&,
55 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&);
56 template BOOST_REGEX_STDLIB_DECL
bool __cdecl
operator==(
57 const unsigned short *,
58 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&);
59 template BOOST_REGEX_STDLIB_DECL
bool __cdecl
operator==(
60 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&,
61 const unsigned short *);
62 template BOOST_REGEX_STDLIB_DECL
bool __cdecl
operator<(
63 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&,
64 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&);
65 template BOOST_REGEX_STDLIB_DECL
bool __cdecl
operator>(
66 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&,
67 const basic_string
<unsigned short, char_traits
<unsigned short>, allocator
<unsigned short> >&);
71 #include <boost/regex/config.hpp>
72 #include <boost/detail/workaround.hpp>
74 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560)
76 #include <boost/regex/v4/c_regex_traits.hpp>
77 #ifndef BOOST_NO_WREGEX
78 #include <boost/regex/v4/primary_transform.hpp>
79 #include <boost/regex/v4/regex_traits_defaults.hpp>
81 #if defined(BOOST_NO_STDC_NAMESPACE)
89 c_regex_traits
<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits
<wchar_t>::transform(const wchar_t* p1
, const wchar_t* p2
)
93 std::wstring
src(p1
, p2
);
94 std::wstring
result(s
, L
' ');
95 while(s
< (r
= std::wcsxfrm(&*result
.begin(), src
.c_str(), s
)))
97 result
.append(r
- s
+ 3, L
' ');
104 c_regex_traits
<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits
<wchar_t>::transform_primary(const wchar_t* p1
, const wchar_t* p2
)
106 static wchar_t s_delim
;
107 static const int s_collate_type
= ::boost::re_detail::find_sort_syntax(static_cast<const c_regex_traits
<wchar_t>*>(0), &s_delim
);
110 // What we do here depends upon the format of the sort key returned by
111 // sort key returned by this->transform:
113 switch(s_collate_type
)
115 case ::boost::re_detail::sort_C
:
116 case ::boost::re_detail::sort_unknown
:
117 // the best we can do is translate to lower case, then get a regular sort key:
119 result
.assign(p1
, p2
);
120 for(std::wstring::size_type i
= 0; i
< result
.size(); ++i
)
121 result
[i
] = (std::towlower
)(result
[i
]);
122 result
= c_regex_traits
<wchar_t>::transform(&*result
.begin(), &*result
.begin() + result
.size());
125 case ::boost::re_detail::sort_fixed
:
127 // get a regular sort key, and then truncate it:
128 result
= c_regex_traits
<wchar_t>::transform(&*result
.begin(), &*result
.begin() + result
.size());
129 result
.erase(s_delim
);
132 case ::boost::re_detail::sort_delim
:
133 // get a regular sort key, and then truncate everything after the delim:
134 result
= c_regex_traits
<wchar_t>::transform(&*result
.begin(), &*result
.begin() + result
.size());
135 if(result
.size() && (result
[0] == s_delim
))
138 for(i
= 0; i
< result
.size(); ++i
)
140 if(result
[i
] == s_delim
)
147 result
= std::wstring(1, char(0));
151 c_regex_traits
<wchar_t>::char_class_type BOOST_REGEX_CALL c_regex_traits
<wchar_t>::lookup_classname(const wchar_t* p1
, const wchar_t* p2
)
153 static const char_class_type masks
[] =
163 char_class_horizontal
,
174 char_class_alnum
| char_class_word
,
175 char_class_alnum
| char_class_word
,
179 int idx
= ::boost::re_detail::get_default_class_id(p1
, p2
);
182 std::wstring
s(p1
, p2
);
183 for(std::wstring::size_type i
= 0; i
< s
.size(); ++i
)
184 s
[i
] = (std::towlower
)(s
[i
]);
185 idx
= ::boost::re_detail::get_default_class_id(&*s
.begin(), &*s
.begin() + s
.size());
187 BOOST_ASSERT(idx
+1 < static_cast<int>(sizeof(masks
) / sizeof(masks
[0])));
191 bool BOOST_REGEX_CALL c_regex_traits
<wchar_t>::isctype(wchar_t c
, char_class_type mask
)
194 ((mask
& char_class_space
) && (std::iswspace
)(c
))
195 || ((mask
& char_class_print
) && (std::iswprint
)(c
))
196 || ((mask
& char_class_cntrl
) && (std::iswcntrl
)(c
))
197 || ((mask
& char_class_upper
) && (std::iswupper
)(c
))
198 || ((mask
& char_class_lower
) && (std::iswlower
)(c
))
199 || ((mask
& char_class_alpha
) && (std::iswalpha
)(c
))
200 || ((mask
& char_class_digit
) && (std::iswdigit
)(c
))
201 || ((mask
& char_class_punct
) && (std::iswpunct
)(c
))
202 || ((mask
& char_class_xdigit
) && (std::iswxdigit
)(c
))
203 || ((mask
& char_class_blank
) && (std::iswspace
)(c
) && !::boost::re_detail::is_separator(c
))
204 || ((mask
& char_class_word
) && (c
== '_'))
205 || ((mask
& char_class_unicode
) && (c
& ~static_cast<wchar_t>(0xff)))
206 || ((mask
& char_class_vertical
) && (::boost::re_detail::is_separator(c
) || (c
== L
'\v')))
207 || ((mask
& char_class_horizontal
) && (std::iswspace
)(c
) && !::boost::re_detail::is_separator(c
) && (c
!= L
'\v'));
210 c_regex_traits
<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits
<wchar_t>::lookup_collatename(const wchar_t* p1
, const wchar_t* p2
)
212 #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
213 && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
214 && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
215 std::string
name(p1
, p2
);
218 const wchar_t* p0
= p1
;
220 name
.append(1, char(*p0
++));
222 name
= ::boost::re_detail::lookup_default_collate_name(name
);
223 #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\
224 && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\
225 && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551)
227 return string_type(name
.begin(), name
.end());
232 typedef std::string::const_iterator iter
;
233 iter b
= name
.begin();
236 result
.append(1, wchar_t(*b
++));
241 return string_type(1, *p1
);
242 return string_type();
245 int BOOST_REGEX_CALL c_regex_traits
<wchar_t>::value(wchar_t c
, int radix
)
248 // workaround for broken wcstol:
249 if((std::iswxdigit
)(c
) == 0)
252 wchar_t b
[2] = { c
, '\0', };
254 int result
= std::wcstol(b
, &ep
, radix
);
260 #ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T
261 c_regex_traits
<unsigned short>::string_type BOOST_REGEX_CALL c_regex_traits
<unsigned short>::transform(const unsigned short* p1
, const unsigned short* p2
)
263 std::wstring result
= c_regex_traits
<wchar_t>::transform((const wchar_t*)p1
, (const wchar_t*)p2
);
264 return string_type(result
.begin(), result
.end());
267 c_regex_traits
<unsigned short>::string_type BOOST_REGEX_CALL c_regex_traits
<unsigned short>::transform_primary(const unsigned short* p1
, const unsigned short* p2
)
269 std::wstring result
= c_regex_traits
<wchar_t>::transform_primary((const wchar_t*)p1
, (const wchar_t*)p2
);
270 return string_type(result
.begin(), result
.end());
273 c_regex_traits
<unsigned short>::char_class_type BOOST_REGEX_CALL c_regex_traits
<unsigned short>::lookup_classname(const unsigned short* p1
, const unsigned short* p2
)
275 return c_regex_traits
<wchar_t>::lookup_classname((const wchar_t*)p1
, (const wchar_t*)p2
);
278 c_regex_traits
<unsigned short>::string_type BOOST_REGEX_CALL c_regex_traits
<unsigned short>::lookup_collatename(const unsigned short* p1
, const unsigned short* p2
)
280 std::wstring result
= c_regex_traits
<wchar_t>::lookup_collatename((const wchar_t*)p1
, (const wchar_t*)p2
);
281 return string_type(result
.begin(), result
.end());
284 bool BOOST_REGEX_CALL c_regex_traits
<unsigned short>::isctype(unsigned short c
, char_class_type m
)
286 return c_regex_traits
<wchar_t>::isctype(c
, m
);
289 int BOOST_REGEX_CALL c_regex_traits
<unsigned short>::value(unsigned short c
, int radix
)
291 return c_regex_traits
<wchar_t>::value(c
, radix
);
298 #endif // BOOST_NO_WREGEX
300 #endif // __BORLANDC__