File indexing completed on 2025-01-18 09:51:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_C_REGEX_TRAITS_HPP_INCLUDED
0020 #define BOOST_C_REGEX_TRAITS_HPP_INCLUDED
0021
0022 #ifndef BOOST_REGEX_CONFIG_HPP
0023 #include <boost/regex/config.hpp>
0024 #endif
0025 #ifndef BOOST_REGEX_WORKAROUND_HPP
0026 #include <boost/regex/v4/regex_workaround.hpp>
0027 #endif
0028
0029 #include <cctype>
0030
0031 #ifdef BOOST_NO_STDC_NAMESPACE
0032 namespace std{
0033 using ::strlen; using ::tolower;
0034 }
0035 #endif
0036
0037 #ifdef BOOST_MSVC
0038 #pragma warning(push)
0039 #pragma warning(disable: 4103 4244)
0040 #endif
0041 #ifdef BOOST_HAS_ABI_HEADERS
0042 # include BOOST_ABI_PREFIX
0043 #endif
0044 #ifdef BOOST_MSVC
0045 #pragma warning(pop)
0046 #endif
0047
0048 namespace boost{
0049
0050 namespace BOOST_REGEX_DETAIL_NS {
0051
0052 enum
0053 {
0054 char_class_space = 1 << 0,
0055 char_class_print = 1 << 1,
0056 char_class_cntrl = 1 << 2,
0057 char_class_upper = 1 << 3,
0058 char_class_lower = 1 << 4,
0059 char_class_alpha = 1 << 5,
0060 char_class_digit = 1 << 6,
0061 char_class_punct = 1 << 7,
0062 char_class_xdigit = 1 << 8,
0063 char_class_alnum = char_class_alpha | char_class_digit,
0064 char_class_graph = char_class_alnum | char_class_punct,
0065 char_class_blank = 1 << 9,
0066 char_class_word = 1 << 10,
0067 char_class_unicode = 1 << 11,
0068 char_class_horizontal = 1 << 12,
0069 char_class_vertical = 1 << 13
0070 };
0071
0072 }
0073
0074 template <class charT>
0075 struct c_regex_traits;
0076
0077 template<>
0078 struct c_regex_traits<char>
0079 {
0080 c_regex_traits(){}
0081 typedef char char_type;
0082 typedef std::size_t size_type;
0083 typedef std::string string_type;
0084 struct locale_type{};
0085 typedef boost::uint32_t char_class_type;
0086
0087 static size_type length(const char_type* p)
0088 {
0089 return (std::strlen)(p);
0090 }
0091
0092 char translate(char c) const
0093 {
0094 return c;
0095 }
0096 char translate_nocase(char c) const
0097 {
0098 return static_cast<char>((std::tolower)(static_cast<unsigned char>(c)));
0099 }
0100
0101 static string_type BOOST_REGEX_CALL transform(const char* p1, const char* p2);
0102 static string_type BOOST_REGEX_CALL transform_primary(const char* p1, const char* p2);
0103
0104 static char_class_type BOOST_REGEX_CALL lookup_classname(const char* p1, const char* p2);
0105 static string_type BOOST_REGEX_CALL lookup_collatename(const char* p1, const char* p2);
0106
0107 static bool BOOST_REGEX_CALL isctype(char, char_class_type);
0108 static int BOOST_REGEX_CALL value(char, int);
0109
0110 locale_type imbue(locale_type l)
0111 { return l; }
0112 locale_type getloc()const
0113 { return locale_type(); }
0114
0115 private:
0116
0117 c_regex_traits(const c_regex_traits&);
0118 c_regex_traits& operator=(const c_regex_traits&);
0119 };
0120
0121 #ifndef BOOST_NO_WREGEX
0122 template<>
0123 struct c_regex_traits<wchar_t>
0124 {
0125 c_regex_traits(){}
0126 typedef wchar_t char_type;
0127 typedef std::size_t size_type;
0128 typedef std::wstring string_type;
0129 struct locale_type{};
0130 typedef boost::uint32_t char_class_type;
0131
0132 static size_type length(const char_type* p)
0133 {
0134 return (std::wcslen)(p);
0135 }
0136
0137 wchar_t translate(wchar_t c) const
0138 {
0139 return c;
0140 }
0141 wchar_t translate_nocase(wchar_t c) const
0142 {
0143 return (std::towlower)(c);
0144 }
0145
0146 static string_type BOOST_REGEX_CALL transform(const wchar_t* p1, const wchar_t* p2);
0147 static string_type BOOST_REGEX_CALL transform_primary(const wchar_t* p1, const wchar_t* p2);
0148
0149 static char_class_type BOOST_REGEX_CALL lookup_classname(const wchar_t* p1, const wchar_t* p2);
0150 static string_type BOOST_REGEX_CALL lookup_collatename(const wchar_t* p1, const wchar_t* p2);
0151
0152 static bool BOOST_REGEX_CALL isctype(wchar_t, char_class_type);
0153 static int BOOST_REGEX_CALL value(wchar_t, int);
0154
0155 locale_type imbue(locale_type l)
0156 { return l; }
0157 locale_type getloc()const
0158 { return locale_type(); }
0159
0160 private:
0161
0162 c_regex_traits(const c_regex_traits&);
0163 c_regex_traits& operator=(const c_regex_traits&);
0164 };
0165
0166 #endif
0167
0168 inline c_regex_traits<char>::string_type BOOST_REGEX_CALL c_regex_traits<char>::transform(const char* p1, const char* p2)
0169 {
0170 std::string result(10, ' ');
0171 std::size_t s = result.size();
0172 std::size_t r;
0173 std::string src(p1, p2);
0174 while (s < (r = std::strxfrm(&*result.begin(), src.c_str(), s)))
0175 {
0176 #if defined(_CPPLIB_VER)
0177
0178
0179
0180
0181
0182 if (r == INT_MAX)
0183 {
0184 result.erase();
0185 result.insert(result.begin(), static_cast<char>(0));
0186 return result;
0187 }
0188 #endif
0189 result.append(r - s + 3, ' ');
0190 s = result.size();
0191 }
0192 result.erase(r);
0193 return result;
0194 }
0195
0196 inline c_regex_traits<char>::string_type BOOST_REGEX_CALL c_regex_traits<char>::transform_primary(const char* p1, const char* p2)
0197 {
0198 static char s_delim;
0199 static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast<c_regex_traits<char>*>(0), &s_delim);
0200 std::string result;
0201
0202
0203
0204
0205 switch (s_collate_type)
0206 {
0207 case ::boost::BOOST_REGEX_DETAIL_NS::sort_C:
0208 case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown:
0209
0210 {
0211 result.assign(p1, p2);
0212 for (std::string::size_type i = 0; i < result.size(); ++i)
0213 result[i] = static_cast<char>((std::tolower)(static_cast<unsigned char>(result[i])));
0214 result = transform(&*result.begin(), &*result.begin() + result.size());
0215 break;
0216 }
0217 case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed:
0218 {
0219
0220 result = transform(p1, p2);
0221 result.erase(s_delim);
0222 break;
0223 }
0224 case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim:
0225
0226 result = transform(p1, p2);
0227 if ((!result.empty()) && (result[0] == s_delim))
0228 break;
0229 std::size_t i;
0230 for (i = 0; i < result.size(); ++i)
0231 {
0232 if (result[i] == s_delim)
0233 break;
0234 }
0235 result.erase(i);
0236 break;
0237 }
0238 if (result.empty())
0239 result = std::string(1, char(0));
0240 return result;
0241 }
0242
0243 inline c_regex_traits<char>::char_class_type BOOST_REGEX_CALL c_regex_traits<char>::lookup_classname(const char* p1, const char* p2)
0244 {
0245 using namespace BOOST_REGEX_DETAIL_NS;
0246 static const char_class_type masks[] =
0247 {
0248 0,
0249 char_class_alnum,
0250 char_class_alpha,
0251 char_class_blank,
0252 char_class_cntrl,
0253 char_class_digit,
0254 char_class_digit,
0255 char_class_graph,
0256 char_class_horizontal,
0257 char_class_lower,
0258 char_class_lower,
0259 char_class_print,
0260 char_class_punct,
0261 char_class_space,
0262 char_class_space,
0263 char_class_upper,
0264 char_class_unicode,
0265 char_class_upper,
0266 char_class_vertical,
0267 char_class_alnum | char_class_word,
0268 char_class_alnum | char_class_word,
0269 char_class_xdigit,
0270 };
0271
0272 int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2);
0273 if (idx < 0)
0274 {
0275 std::string s(p1, p2);
0276 for (std::string::size_type i = 0; i < s.size(); ++i)
0277 s[i] = static_cast<char>((std::tolower)(static_cast<unsigned char>(s[i])));
0278 idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size());
0279 }
0280 BOOST_REGEX_ASSERT(std::size_t(idx) + 1u < sizeof(masks) / sizeof(masks[0]));
0281 return masks[idx + 1];
0282 }
0283
0284 inline bool BOOST_REGEX_CALL c_regex_traits<char>::isctype(char c, char_class_type mask)
0285 {
0286 using namespace BOOST_REGEX_DETAIL_NS;
0287 return
0288 ((mask & char_class_space) && (std::isspace)(static_cast<unsigned char>(c)))
0289 || ((mask & char_class_print) && (std::isprint)(static_cast<unsigned char>(c)))
0290 || ((mask & char_class_cntrl) && (std::iscntrl)(static_cast<unsigned char>(c)))
0291 || ((mask & char_class_upper) && (std::isupper)(static_cast<unsigned char>(c)))
0292 || ((mask & char_class_lower) && (std::islower)(static_cast<unsigned char>(c)))
0293 || ((mask & char_class_alpha) && (std::isalpha)(static_cast<unsigned char>(c)))
0294 || ((mask & char_class_digit) && (std::isdigit)(static_cast<unsigned char>(c)))
0295 || ((mask & char_class_punct) && (std::ispunct)(static_cast<unsigned char>(c)))
0296 || ((mask & char_class_xdigit) && (std::isxdigit)(static_cast<unsigned char>(c)))
0297 || ((mask & char_class_blank) && (std::isspace)(static_cast<unsigned char>(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c))
0298 || ((mask & char_class_word) && (c == '_'))
0299 || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == '\v')))
0300 || ((mask & char_class_horizontal) && (std::isspace)(static_cast<unsigned char>(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != '\v'));
0301 }
0302
0303 inline c_regex_traits<char>::string_type BOOST_REGEX_CALL c_regex_traits<char>::lookup_collatename(const char* p1, const char* p2)
0304 {
0305 std::string s(p1, p2);
0306 s = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(s);
0307 if (s.empty() && (p2 - p1 == 1))
0308 s.append(1, *p1);
0309 return s;
0310 }
0311
0312 inline int BOOST_REGEX_CALL c_regex_traits<char>::value(char c, int radix)
0313 {
0314 char b[2] = { c, '\0', };
0315 char* ep;
0316 int result = std::strtol(b, &ep, radix);
0317 if (ep == b)
0318 return -1;
0319 return result;
0320 }
0321
0322 #ifndef BOOST_NO_WREGEX
0323
0324 inline c_regex_traits<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::transform(const wchar_t* p1, const wchar_t* p2)
0325 {
0326 std::size_t r;
0327 std::size_t s = 10;
0328 std::wstring src(p1, p2);
0329 std::wstring result(s, L' ');
0330 while (s < (r = std::wcsxfrm(&*result.begin(), src.c_str(), s)))
0331 {
0332 #if defined(_CPPLIB_VER)
0333
0334
0335
0336
0337
0338 if (r == INT_MAX)
0339 {
0340 result.erase();
0341 result.insert(result.begin(), static_cast<wchar_t>(0));
0342 return result;
0343 }
0344 #endif
0345 result.append(r - s + 3, L' ');
0346 s = result.size();
0347 }
0348 result.erase(r);
0349 return result;
0350 }
0351
0352 inline 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)
0353 {
0354 static wchar_t s_delim;
0355 static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast<const c_regex_traits<wchar_t>*>(0), &s_delim);
0356 std::wstring result;
0357
0358
0359
0360
0361 switch (s_collate_type)
0362 {
0363 case ::boost::BOOST_REGEX_DETAIL_NS::sort_C:
0364 case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown:
0365
0366 {
0367 result.assign(p1, p2);
0368 for (std::wstring::size_type i = 0; i < result.size(); ++i)
0369 result[i] = (std::towlower)(result[i]);
0370 result = c_regex_traits<wchar_t>::transform(&*result.begin(), &*result.begin() + result.size());
0371 break;
0372 }
0373 case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed:
0374 {
0375
0376 result = c_regex_traits<wchar_t>::transform(&*result.begin(), &*result.begin() + result.size());
0377 result.erase(s_delim);
0378 break;
0379 }
0380 case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim:
0381
0382 result = c_regex_traits<wchar_t>::transform(&*result.begin(), &*result.begin() + result.size());
0383 if ((!result.empty()) && (result[0] == s_delim))
0384 break;
0385 std::size_t i;
0386 for (i = 0; i < result.size(); ++i)
0387 {
0388 if (result[i] == s_delim)
0389 break;
0390 }
0391 result.erase(i);
0392 break;
0393 }
0394 if (result.empty())
0395 result = std::wstring(1, char(0));
0396 return result;
0397 }
0398
0399 inline 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)
0400 {
0401 using namespace BOOST_REGEX_DETAIL_NS;
0402 static const char_class_type masks[] =
0403 {
0404 0,
0405 char_class_alnum,
0406 char_class_alpha,
0407 char_class_blank,
0408 char_class_cntrl,
0409 char_class_digit,
0410 char_class_digit,
0411 char_class_graph,
0412 char_class_horizontal,
0413 char_class_lower,
0414 char_class_lower,
0415 char_class_print,
0416 char_class_punct,
0417 char_class_space,
0418 char_class_space,
0419 char_class_upper,
0420 char_class_unicode,
0421 char_class_upper,
0422 char_class_vertical,
0423 char_class_alnum | char_class_word,
0424 char_class_alnum | char_class_word,
0425 char_class_xdigit,
0426 };
0427
0428 int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2);
0429 if (idx < 0)
0430 {
0431 std::wstring s(p1, p2);
0432 for (std::wstring::size_type i = 0; i < s.size(); ++i)
0433 s[i] = (std::towlower)(s[i]);
0434 idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size());
0435 }
0436 BOOST_REGEX_ASSERT(idx + 1 < static_cast<int>(sizeof(masks) / sizeof(masks[0])));
0437 return masks[idx + 1];
0438 }
0439
0440 inline bool BOOST_REGEX_CALL c_regex_traits<wchar_t>::isctype(wchar_t c, char_class_type mask)
0441 {
0442 using namespace BOOST_REGEX_DETAIL_NS;
0443 return
0444 ((mask & char_class_space) && (std::iswspace)(c))
0445 || ((mask & char_class_print) && (std::iswprint)(c))
0446 || ((mask & char_class_cntrl) && (std::iswcntrl)(c))
0447 || ((mask & char_class_upper) && (std::iswupper)(c))
0448 || ((mask & char_class_lower) && (std::iswlower)(c))
0449 || ((mask & char_class_alpha) && (std::iswalpha)(c))
0450 || ((mask & char_class_digit) && (std::iswdigit)(c))
0451 || ((mask & char_class_punct) && (std::iswpunct)(c))
0452 || ((mask & char_class_xdigit) && (std::iswxdigit)(c))
0453 || ((mask & char_class_blank) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c))
0454 || ((mask & char_class_word) && (c == '_'))
0455 || ((mask & char_class_unicode) && (c & ~static_cast<wchar_t>(0xff)))
0456 || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == L'\v')))
0457 || ((mask & char_class_horizontal) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != L'\v'));
0458 }
0459
0460 inline 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)
0461 {
0462 #ifdef BOOST_MSVC
0463 #pragma warning(push)
0464 #pragma warning(disable: 4244)
0465 #endif
0466 std::string name(p1, p2);
0467 #ifdef BOOST_MSVC
0468 #pragma warning(pop)
0469 #endif
0470 name = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(name);
0471 if (!name.empty())
0472 return string_type(name.begin(), name.end());
0473 if (p2 - p1 == 1)
0474 return string_type(1, *p1);
0475 return string_type();
0476 }
0477
0478 inline int BOOST_REGEX_CALL c_regex_traits<wchar_t>::value(wchar_t c, int radix)
0479 {
0480 #ifdef BOOST_BORLANDC
0481
0482 if ((std::iswxdigit)(c) == 0)
0483 return -1;
0484 #endif
0485 wchar_t b[2] = { c, '\0', };
0486 wchar_t* ep;
0487 int result = std::wcstol(b, &ep, radix);
0488 if (ep == b)
0489 return -1;
0490 return result;
0491 }
0492
0493 #endif
0494
0495 }
0496
0497 #ifdef BOOST_MSVC
0498 #pragma warning(push)
0499 #pragma warning(disable: 4103)
0500 #endif
0501 #ifdef BOOST_HAS_ABI_HEADERS
0502 # include BOOST_ABI_SUFFIX
0503 #endif
0504 #ifdef BOOST_MSVC
0505 #pragma warning(pop)
0506 #endif
0507
0508 #endif
0509
0510
0511