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: c_regex_traits.cpp
15 * VERSION: see <boost/version.hpp>
16 * DESCRIPTION: Implements out of line c_regex_traits<char> members
20 #define BOOST_REGEX_SOURCE
22 #include <boost/config.hpp>
23 #include <boost/detail/workaround.hpp>
24 #include "internals.hpp"
26 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560)
28 #include <boost/regex/v4/c_regex_traits.hpp>
29 #include <boost/regex/v4/primary_transform.hpp>
30 #include <boost/regex/v4/regex_traits_defaults.hpp>
32 #ifdef BOOST_NO_STDC_NAMESPACE
34 using ::strxfrm
; using ::isspace
;
35 using ::ispunct
; using ::isalpha
;
36 using ::isalnum
; using ::iscntrl
;
37 using ::isprint
; using ::isupper
;
38 using ::islower
; using ::isdigit
;
39 using ::isxdigit
; using ::strtol
;
43 #ifdef BOOST_HAS_ABI_HEADERS
44 # include BOOST_ABI_PREFIX
49 c_regex_traits
<char>::string_type BOOST_REGEX_CALL c_regex_traits
<char>::transform(const char* p1
, const char* p2
)
51 std::string
result(10, ' ');
52 std::size_t s
= result
.size();
54 std::string
src(p1
, p2
);
55 while(s
< (r
= std::strxfrm(&*result
.begin(), src
.c_str(), s
)))
57 result
.append(r
- s
+ 3, ' ');
64 c_regex_traits
<char>::string_type BOOST_REGEX_CALL c_regex_traits
<char>::transform_primary(const char* p1
, const char* p2
)
67 static const int s_collate_type
= ::boost::re_detail::find_sort_syntax(static_cast<c_regex_traits
<char>*>(0), &s_delim
);
70 // What we do here depends upon the format of the sort key returned by
71 // sort key returned by this->transform:
73 switch(s_collate_type
)
75 case ::boost::re_detail::sort_C
:
76 case ::boost::re_detail::sort_unknown
:
77 // the best we can do is translate to lower case, then get a regular sort key:
79 result
.assign(p1
, p2
);
80 for(std::string::size_type i
= 0; i
< result
.size(); ++i
)
81 result
[i
] = static_cast<char>((std::tolower
)(static_cast<unsigned char>(result
[i
])));
82 result
= transform(&*result
.begin(), &*result
.begin() + result
.size());
85 case ::boost::re_detail::sort_fixed
:
87 // get a regular sort key, and then truncate it:
88 result
= transform(p1
, p2
);
89 result
.erase(s_delim
);
92 case ::boost::re_detail::sort_delim
:
93 // get a regular sort key, and then truncate everything after the delim:
94 result
= transform(p1
, p2
);
95 if(result
.size() && (result
[0] == s_delim
))
98 for(i
= 0; i
< result
.size(); ++i
)
100 if(result
[i
] == s_delim
)
107 result
= std::string(1, char(0));
111 c_regex_traits
<char>::char_class_type BOOST_REGEX_CALL c_regex_traits
<char>::lookup_classname(const char* p1
, const char* p2
)
113 static const char_class_type masks
[] =
123 char_class_horizontal
,
134 char_class_alnum
| char_class_word
,
135 char_class_alnum
| char_class_word
,
139 int idx
= ::boost::re_detail::get_default_class_id(p1
, p2
);
142 std::string
s(p1
, p2
);
143 for(std::string::size_type i
= 0; i
< s
.size(); ++i
)
144 s
[i
] = static_cast<char>((std::tolower
)(static_cast<unsigned char>(s
[i
])));
145 idx
= ::boost::re_detail::get_default_class_id(&*s
.begin(), &*s
.begin() + s
.size());
147 BOOST_ASSERT(std::size_t(idx
+1) < sizeof(masks
) / sizeof(masks
[0]));
151 bool BOOST_REGEX_CALL c_regex_traits
<char>::isctype(char c
, char_class_type mask
)
154 ((mask
& char_class_space
) && (std::isspace
)(static_cast<unsigned char>(c
)))
155 || ((mask
& char_class_print
) && (std::isprint
)(static_cast<unsigned char>(c
)))
156 || ((mask
& char_class_cntrl
) && (std::iscntrl
)(static_cast<unsigned char>(c
)))
157 || ((mask
& char_class_upper
) && (std::isupper
)(static_cast<unsigned char>(c
)))
158 || ((mask
& char_class_lower
) && (std::islower
)(static_cast<unsigned char>(c
)))
159 || ((mask
& char_class_alpha
) && (std::isalpha
)(static_cast<unsigned char>(c
)))
160 || ((mask
& char_class_digit
) && (std::isdigit
)(static_cast<unsigned char>(c
)))
161 || ((mask
& char_class_punct
) && (std::ispunct
)(static_cast<unsigned char>(c
)))
162 || ((mask
& char_class_xdigit
) && (std::isxdigit
)(static_cast<unsigned char>(c
)))
163 || ((mask
& char_class_blank
) && (std::isspace
)(static_cast<unsigned char>(c
)) && !::boost::re_detail::is_separator(c
))
164 || ((mask
& char_class_word
) && (c
== '_'))
165 || ((mask
& char_class_vertical
) && (::boost::re_detail::is_separator(c
) || (c
== '\v')))
166 || ((mask
& char_class_horizontal
) && (std::isspace
)(static_cast<unsigned char>(c
)) && !::boost::re_detail::is_separator(c
) && (c
!= '\v'));
169 c_regex_traits
<char>::string_type BOOST_REGEX_CALL c_regex_traits
<char>::lookup_collatename(const char* p1
, const char* p2
)
171 std::string
s(p1
, p2
);
172 s
= ::boost::re_detail::lookup_default_collate_name(s
);
173 if(s
.empty() && (p2
-p1
== 1))
178 int BOOST_REGEX_CALL c_regex_traits
<char>::value(char c
, int radix
)
180 char b
[2] = { c
, '\0', };
182 int result
= std::strtol(b
, &ep
, radix
);
189 #ifdef BOOST_HAS_ABI_HEADERS
190 # include BOOST_ABI_SUFFIX