sclang: ServerShmInterface - avoid object duplication in deepCopy
[supercollider.git] / external_libraries / boost / libs / regex / src / c_regex_traits.cpp
blob6701020105a07bba99b71d35c6c41e8acd10cbdf
1 /*
3 * Copyright (c) 2004
4 * John Maddock
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
33 namespace std{
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;
41 #endif
43 #ifdef BOOST_HAS_ABI_HEADERS
44 # include BOOST_ABI_PREFIX
45 #endif
47 namespace boost{
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();
53 std::size_t r;
54 std::string src(p1, p2);
55 while(s < (r = std::strxfrm(&*result.begin(), src.c_str(), s)))
57 result.append(r - s + 3, ' ');
58 s = result.size();
60 result.erase(r);
61 return result;
64 c_regex_traits<char>::string_type BOOST_REGEX_CALL c_regex_traits<char>::transform_primary(const char* p1, const char* p2)
66 static char s_delim;
67 static const int s_collate_type = ::boost::re_detail::find_sort_syntax(static_cast<c_regex_traits<char>*>(0), &s_delim);
68 std::string result;
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());
83 break;
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);
90 break;
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))
96 break;
97 std::size_t i;
98 for(i = 0; i < result.size(); ++i)
100 if(result[i] == s_delim)
101 break;
103 result.erase(i);
104 break;
106 if(result.empty())
107 result = std::string(1, char(0));
108 return result;
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[] =
116 char_class_alnum,
117 char_class_alpha,
118 char_class_blank,
119 char_class_cntrl,
120 char_class_digit,
121 char_class_digit,
122 char_class_graph,
123 char_class_horizontal,
124 char_class_lower,
125 char_class_lower,
126 char_class_print,
127 char_class_punct,
128 char_class_space,
129 char_class_space,
130 char_class_upper,
131 char_class_unicode,
132 char_class_upper,
133 char_class_vertical,
134 char_class_alnum | char_class_word,
135 char_class_alnum | char_class_word,
136 char_class_xdigit,
139 int idx = ::boost::re_detail::get_default_class_id(p1, p2);
140 if(idx < 0)
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]));
148 return masks[idx+1];
151 bool BOOST_REGEX_CALL c_regex_traits<char>::isctype(char c, char_class_type mask)
153 return
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))
174 s.append(1, *p1);
175 return s;
178 int BOOST_REGEX_CALL c_regex_traits<char>::value(char c, int radix)
180 char b[2] = { c, '\0', };
181 char* ep;
182 int result = std::strtol(b, &ep, radix);
183 if(ep == b)
184 return -1;
185 return result;
189 #ifdef BOOST_HAS_ABI_HEADERS
190 # include BOOST_ABI_SUFFIX
191 #endif
193 #endif