From 27d2853615bf25a4ad28cd012c027e8e64c39ecb Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 26 Nov 2020 20:05:38 +0000 Subject: [PATCH] Make c_regex_traits all inline. Fix some C++20 issues. --- build/Jamfile.v2 | 12 +- include/boost/regex/v4/c_regex_traits.hpp | 384 ++++++++- include/boost/regex/v5/c_regex_traits.hpp | 382 ++++++++- include/boost/regex/v5/regex_traits.hpp | 4 +- src/c_regex_traits.cpp | 205 ----- src/fileiter.cpp | 933 ---------------------- src/instances.cpp | 32 - src/usinstances.cpp | 81 -- src/wc_regex_traits.cpp | 313 -------- src/winstances.cpp | 35 - test/Jamfile.v2 | 33 - test/captures/Jamfile.v2 | 9 +- test/noeh_test/Jamfile.v2 | 7 - test/regress/test_deprecated.cpp | 11 +- test/test_consolidated.cpp | 7 - 15 files changed, 695 insertions(+), 1753 deletions(-) delete mode 100644 src/c_regex_traits.cpp delete mode 100644 src/fileiter.cpp delete mode 100644 src/instances.cpp delete mode 100644 src/usinstances.cpp delete mode 100644 src/wc_regex_traits.cpp delete mode 100644 src/winstances.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index a5f62610..99407f06 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -122,9 +122,7 @@ explicit has_icu ; alias icu_options : : : : [ check-target-builds has_icu : $(ICU_OPTS) : ] ; SOURCES = - c_regex_traits.cpp cpp_regex_traits.cpp - fileiter.cpp icu.cpp posix_api.cpp regex.cpp @@ -133,9 +131,8 @@ SOURCES = regex_traits_defaults.cpp static_mutex.cpp w32_regex_traits.cpp - wc_regex_traits.cpp wide_posix_api.cpp - +; lib boost_regex : ../src/$(SOURCES) icu_options : @@ -145,10 +142,3 @@ lib boost_regex : ../src/$(SOURCES) icu_options boost-install boost_regex ; - - - - - - - diff --git a/include/boost/regex/v4/c_regex_traits.hpp b/include/boost/regex/v4/c_regex_traits.hpp index d99b0f34..8015188a 100644 --- a/include/boost/regex/v4/c_regex_traits.hpp +++ b/include/boost/regex/v4/c_regex_traits.hpp @@ -23,7 +23,7 @@ #include #endif #ifndef BOOST_REGEX_WORKAROUND_HPP -#include +#include #endif #include @@ -36,7 +36,7 @@ namespace std{ #ifdef BOOST_MSVC #pragma warning(push) -#pragma warning(disable: 4103) +#pragma warning(disable: 4103 4244) #endif #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -47,6 +47,30 @@ namespace std{ namespace boost{ + namespace BOOST_REGEX_DETAIL_NS { + + enum + { + char_class_space = 1 << 0, + char_class_print = 1 << 1, + char_class_cntrl = 1 << 2, + char_class_upper = 1 << 3, + char_class_lower = 1 << 4, + char_class_alpha = 1 << 5, + char_class_digit = 1 << 6, + char_class_punct = 1 << 7, + char_class_xdigit = 1 << 8, + char_class_alnum = char_class_alpha | char_class_digit, + char_class_graph = char_class_alnum | char_class_punct, + char_class_blank = 1 << 9, + char_class_word = 1 << 10, + char_class_unicode = 1 << 11, + char_class_horizontal = 1 << 12, + char_class_vertical = 1 << 13 + }; + + } + template struct c_regex_traits; @@ -139,59 +163,335 @@ private: c_regex_traits& operator=(const c_regex_traits&); }; -#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T -// -// Provide an unsigned short version as well, so the user can link to this -// no matter whether they build with /Zc:wchar_t or not (MSVC specific). -// -template<> -struct BOOST_REGEX_DECL c_regex_traits +#endif // BOOST_NO_WREGEX + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform(const char* p1, const char* p2) { - c_regex_traits(){} - typedef unsigned short char_type; - typedef std::size_t size_type; - typedef std::basic_string string_type; - struct locale_type{}; - typedef boost::uint32_t char_class_type; - - static size_type length(const char_type* p) - { - return (std::wcslen)((const wchar_t*)p); + std::string result(10, ' '); + std::size_t s = result.size(); + std::size_t r; + std::string src(p1, p2); + while (s < (r = std::strxfrm(&*result.begin(), src.c_str(), s))) + { +#if defined(_CPPLIB_VER) + // + // A bug in VC11 and 12 causes the program to hang if we pass a null-string + // to std::strxfrm, but only for certain locales :-( + // Probably effects Intel and Clang or any compiler using the VC std library (Dinkumware). + // + if (r == INT_MAX) + { + result.erase(); + result.insert(result.begin(), static_cast(0)); + return result; + } +#endif + result.append(r - s + 3, ' '); + s = result.size(); } + result.erase(r); + return result; +} - unsigned short translate(unsigned short c) const - { - return c; +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform_primary(const char* p1, const char* p2) +{ + static char s_delim; + static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast*>(0), &s_delim); + std::string result; + // + // What we do here depends upon the format of the sort key returned by + // sort key returned by this->transform: + // + switch (s_collate_type) + { + case ::boost::BOOST_REGEX_DETAIL_NS::sort_C: + case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown: + // the best we can do is translate to lower case, then get a regular sort key: + { + result.assign(p1, p2); + for (std::string::size_type i = 0; i < result.size(); ++i) + result[i] = static_cast((std::tolower)(static_cast(result[i]))); + result = transform(&*result.begin(), &*result.begin() + result.size()); + break; } - unsigned short translate_nocase(unsigned short c) const - { - return (std::towlower)((wchar_t)c); + case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed: + { + // get a regular sort key, and then truncate it: + result = transform(p1, p2); + result.erase(s_delim); + break; } + case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim: + // get a regular sort key, and then truncate everything after the delim: + result = transform(p1, p2); + if ((!result.empty()) && (result[0] == s_delim)) + break; + std::size_t i; + for (i = 0; i < result.size(); ++i) + { + if (result[i] == s_delim) + break; + } + result.erase(i); + break; + } + if (result.empty()) + result = std::string(1, char(0)); + return result; +} - static string_type BOOST_REGEX_CALL transform(const unsigned short* p1, const unsigned short* p2); - static string_type BOOST_REGEX_CALL transform_primary(const unsigned short* p1, const unsigned short* p2); +inline c_regex_traits::char_class_type BOOST_REGEX_CALL c_regex_traits::lookup_classname(const char* p1, const char* p2) +{ + using namespace BOOST_REGEX_DETAIL_NS; + static const char_class_type masks[] = + { + 0, + char_class_alnum, + char_class_alpha, + char_class_blank, + char_class_cntrl, + char_class_digit, + char_class_digit, + char_class_graph, + char_class_horizontal, + char_class_lower, + char_class_lower, + char_class_print, + char_class_punct, + char_class_space, + char_class_space, + char_class_upper, + char_class_unicode, + char_class_upper, + char_class_vertical, + char_class_alnum | char_class_word, + char_class_alnum | char_class_word, + char_class_xdigit, + }; - static char_class_type BOOST_REGEX_CALL lookup_classname(const unsigned short* p1, const unsigned short* p2); - static string_type BOOST_REGEX_CALL lookup_collatename(const unsigned short* p1, const unsigned short* p2); + int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2); + if (idx < 0) + { + std::string s(p1, p2); + for (std::string::size_type i = 0; i < s.size(); ++i) + s[i] = static_cast((std::tolower)(static_cast(s[i]))); + idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size()); + } + BOOST_ASSERT(std::size_t(idx) + 1u < sizeof(masks) / sizeof(masks[0])); + return masks[idx + 1]; +} - static bool BOOST_REGEX_CALL isctype(unsigned short, char_class_type); - static int BOOST_REGEX_CALL value(unsigned short, int); +inline bool BOOST_REGEX_CALL c_regex_traits::isctype(char c, char_class_type mask) +{ + using namespace BOOST_REGEX_DETAIL_NS; + return + ((mask & char_class_space) && (std::isspace)(static_cast(c))) + || ((mask & char_class_print) && (std::isprint)(static_cast(c))) + || ((mask & char_class_cntrl) && (std::iscntrl)(static_cast(c))) + || ((mask & char_class_upper) && (std::isupper)(static_cast(c))) + || ((mask & char_class_lower) && (std::islower)(static_cast(c))) + || ((mask & char_class_alpha) && (std::isalpha)(static_cast(c))) + || ((mask & char_class_digit) && (std::isdigit)(static_cast(c))) + || ((mask & char_class_punct) && (std::ispunct)(static_cast(c))) + || ((mask & char_class_xdigit) && (std::isxdigit)(static_cast(c))) + || ((mask & char_class_blank) && (std::isspace)(static_cast(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c)) + || ((mask & char_class_word) && (c == '_')) + || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == '\v'))) + || ((mask & char_class_horizontal) && (std::isspace)(static_cast(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != '\v')); +} - locale_type imbue(locale_type l) - { return l; } - locale_type getloc()const - { return locale_type(); } +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::lookup_collatename(const char* p1, const char* p2) +{ + std::string s(p1, p2); + s = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(s); + if (s.empty() && (p2 - p1 == 1)) + s.append(1, *p1); + return s; +} -private: - // this type is not copyable: - c_regex_traits(const c_regex_traits&); - c_regex_traits& operator=(const c_regex_traits&); -}; +inline int BOOST_REGEX_CALL c_regex_traits::value(char c, int radix) +{ + char b[2] = { c, '\0', }; + char* ep; + int result = std::strtol(b, &ep, radix); + if (ep == b) + return -1; + return result; +} + +#ifndef BOOST_NO_WREGEX + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform(const wchar_t* p1, const wchar_t* p2) +{ + std::size_t r; + std::size_t s = 10; + std::wstring src(p1, p2); + std::wstring result(s, L' '); + while (s < (r = std::wcsxfrm(&*result.begin(), src.c_str(), s))) + { +#if defined(_CPPLIB_VER) + // + // A bug in VC11 and 12 causes the program to hang if we pass a null-string + // to std::strxfrm, but only for certain locales :-( + // Probably effects Intel and Clang or any compiler using the VC std library (Dinkumware). + // + if (r == INT_MAX) + { + result.erase(); + result.insert(result.begin(), static_cast(0)); + return result; + } +#endif + result.append(r - s + 3, L' '); + s = result.size(); + } + result.erase(r); + return result; +} + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform_primary(const wchar_t* p1, const wchar_t* p2) +{ + static wchar_t s_delim; + static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast*>(0), &s_delim); + std::wstring result; + // + // What we do here depends upon the format of the sort key returned by + // sort key returned by this->transform: + // + switch (s_collate_type) + { + case ::boost::BOOST_REGEX_DETAIL_NS::sort_C: + case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown: + // the best we can do is translate to lower case, then get a regular sort key: + { + result.assign(p1, p2); + for (std::wstring::size_type i = 0; i < result.size(); ++i) + result[i] = (std::towlower)(result[i]); + result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); + break; + } + case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed: + { + // get a regular sort key, and then truncate it: + result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); + result.erase(s_delim); + break; + } + case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim: + // get a regular sort key, and then truncate everything after the delim: + result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); + if ((!result.empty()) && (result[0] == s_delim)) + break; + std::size_t i; + for (i = 0; i < result.size(); ++i) + { + if (result[i] == s_delim) + break; + } + result.erase(i); + break; + } + if (result.empty()) + result = std::wstring(1, char(0)); + return result; +} + +inline c_regex_traits::char_class_type BOOST_REGEX_CALL c_regex_traits::lookup_classname(const wchar_t* p1, const wchar_t* p2) +{ + using namespace BOOST_REGEX_DETAIL_NS; + static const char_class_type masks[] = + { + 0, + char_class_alnum, + char_class_alpha, + char_class_blank, + char_class_cntrl, + char_class_digit, + char_class_digit, + char_class_graph, + char_class_horizontal, + char_class_lower, + char_class_lower, + char_class_print, + char_class_punct, + char_class_space, + char_class_space, + char_class_upper, + char_class_unicode, + char_class_upper, + char_class_vertical, + char_class_alnum | char_class_word, + char_class_alnum | char_class_word, + char_class_xdigit, + }; + + int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2); + if (idx < 0) + { + std::wstring s(p1, p2); + for (std::wstring::size_type i = 0; i < s.size(); ++i) + s[i] = (std::towlower)(s[i]); + idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size()); + } + BOOST_ASSERT(idx + 1 < static_cast(sizeof(masks) / sizeof(masks[0]))); + return masks[idx + 1]; +} + +inline bool BOOST_REGEX_CALL c_regex_traits::isctype(wchar_t c, char_class_type mask) +{ + using namespace BOOST_REGEX_DETAIL_NS; + return + ((mask & char_class_space) && (std::iswspace)(c)) + || ((mask & char_class_print) && (std::iswprint)(c)) + || ((mask & char_class_cntrl) && (std::iswcntrl)(c)) + || ((mask & char_class_upper) && (std::iswupper)(c)) + || ((mask & char_class_lower) && (std::iswlower)(c)) + || ((mask & char_class_alpha) && (std::iswalpha)(c)) + || ((mask & char_class_digit) && (std::iswdigit)(c)) + || ((mask & char_class_punct) && (std::iswpunct)(c)) + || ((mask & char_class_xdigit) && (std::iswxdigit)(c)) + || ((mask & char_class_blank) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c)) + || ((mask & char_class_word) && (c == '_')) + || ((mask & char_class_unicode) && (c & ~static_cast(0xff))) + || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == L'\v'))) + || ((mask & char_class_horizontal) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != L'\v')); +} + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::lookup_collatename(const wchar_t* p1, const wchar_t* p2) +{ +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable: 4244) +#endif + std::string name(p1, p2); +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + name = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(name); + if (!name.empty()) + return string_type(name.begin(), name.end()); + if (p2 - p1 == 1) + return string_type(1, *p1); + return string_type(); +} + +inline int BOOST_REGEX_CALL c_regex_traits::value(wchar_t c, int radix) +{ +#ifdef BOOST_BORLANDC + // workaround for broken wcstol: + if ((std::iswxdigit)(c) == 0) + return -1; +#endif + wchar_t b[2] = { c, '\0', }; + wchar_t* ep; + int result = std::wcstol(b, &ep, radix); + if (ep == b) + return -1; + return result; +} #endif -#endif // BOOST_NO_WREGEX - } #ifdef BOOST_MSVC diff --git a/include/boost/regex/v5/c_regex_traits.hpp b/include/boost/regex/v5/c_regex_traits.hpp index 07d8e32e..8015188a 100644 --- a/include/boost/regex/v5/c_regex_traits.hpp +++ b/include/boost/regex/v5/c_regex_traits.hpp @@ -36,7 +36,7 @@ namespace std{ #ifdef BOOST_MSVC #pragma warning(push) -#pragma warning(disable: 4103) +#pragma warning(disable: 4103 4244) #endif #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_PREFIX @@ -47,6 +47,30 @@ namespace std{ namespace boost{ + namespace BOOST_REGEX_DETAIL_NS { + + enum + { + char_class_space = 1 << 0, + char_class_print = 1 << 1, + char_class_cntrl = 1 << 2, + char_class_upper = 1 << 3, + char_class_lower = 1 << 4, + char_class_alpha = 1 << 5, + char_class_digit = 1 << 6, + char_class_punct = 1 << 7, + char_class_xdigit = 1 << 8, + char_class_alnum = char_class_alpha | char_class_digit, + char_class_graph = char_class_alnum | char_class_punct, + char_class_blank = 1 << 9, + char_class_word = 1 << 10, + char_class_unicode = 1 << 11, + char_class_horizontal = 1 << 12, + char_class_vertical = 1 << 13 + }; + + } + template struct c_regex_traits; @@ -139,59 +163,335 @@ private: c_regex_traits& operator=(const c_regex_traits&); }; -#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T -// -// Provide an unsigned short version as well, so the user can link to this -// no matter whether they build with /Zc:wchar_t or not (MSVC specific). -// -template<> -struct BOOST_REGEX_DECL c_regex_traits +#endif // BOOST_NO_WREGEX + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform(const char* p1, const char* p2) { - c_regex_traits(){} - typedef unsigned short char_type; - typedef std::size_t size_type; - typedef std::basic_string string_type; - struct locale_type{}; - typedef boost::uint32_t char_class_type; - - static size_type length(const char_type* p) - { - return (std::wcslen)((const wchar_t*)p); + std::string result(10, ' '); + std::size_t s = result.size(); + std::size_t r; + std::string src(p1, p2); + while (s < (r = std::strxfrm(&*result.begin(), src.c_str(), s))) + { +#if defined(_CPPLIB_VER) + // + // A bug in VC11 and 12 causes the program to hang if we pass a null-string + // to std::strxfrm, but only for certain locales :-( + // Probably effects Intel and Clang or any compiler using the VC std library (Dinkumware). + // + if (r == INT_MAX) + { + result.erase(); + result.insert(result.begin(), static_cast(0)); + return result; + } +#endif + result.append(r - s + 3, ' '); + s = result.size(); } + result.erase(r); + return result; +} - unsigned short translate(unsigned short c) const - { - return c; +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform_primary(const char* p1, const char* p2) +{ + static char s_delim; + static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast*>(0), &s_delim); + std::string result; + // + // What we do here depends upon the format of the sort key returned by + // sort key returned by this->transform: + // + switch (s_collate_type) + { + case ::boost::BOOST_REGEX_DETAIL_NS::sort_C: + case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown: + // the best we can do is translate to lower case, then get a regular sort key: + { + result.assign(p1, p2); + for (std::string::size_type i = 0; i < result.size(); ++i) + result[i] = static_cast((std::tolower)(static_cast(result[i]))); + result = transform(&*result.begin(), &*result.begin() + result.size()); + break; } - unsigned short translate_nocase(unsigned short c) const - { - return (std::towlower)((wchar_t)c); + case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed: + { + // get a regular sort key, and then truncate it: + result = transform(p1, p2); + result.erase(s_delim); + break; } + case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim: + // get a regular sort key, and then truncate everything after the delim: + result = transform(p1, p2); + if ((!result.empty()) && (result[0] == s_delim)) + break; + std::size_t i; + for (i = 0; i < result.size(); ++i) + { + if (result[i] == s_delim) + break; + } + result.erase(i); + break; + } + if (result.empty()) + result = std::string(1, char(0)); + return result; +} - static string_type BOOST_REGEX_CALL transform(const unsigned short* p1, const unsigned short* p2); - static string_type BOOST_REGEX_CALL transform_primary(const unsigned short* p1, const unsigned short* p2); +inline c_regex_traits::char_class_type BOOST_REGEX_CALL c_regex_traits::lookup_classname(const char* p1, const char* p2) +{ + using namespace BOOST_REGEX_DETAIL_NS; + static const char_class_type masks[] = + { + 0, + char_class_alnum, + char_class_alpha, + char_class_blank, + char_class_cntrl, + char_class_digit, + char_class_digit, + char_class_graph, + char_class_horizontal, + char_class_lower, + char_class_lower, + char_class_print, + char_class_punct, + char_class_space, + char_class_space, + char_class_upper, + char_class_unicode, + char_class_upper, + char_class_vertical, + char_class_alnum | char_class_word, + char_class_alnum | char_class_word, + char_class_xdigit, + }; - static char_class_type BOOST_REGEX_CALL lookup_classname(const unsigned short* p1, const unsigned short* p2); - static string_type BOOST_REGEX_CALL lookup_collatename(const unsigned short* p1, const unsigned short* p2); + int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2); + if (idx < 0) + { + std::string s(p1, p2); + for (std::string::size_type i = 0; i < s.size(); ++i) + s[i] = static_cast((std::tolower)(static_cast(s[i]))); + idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size()); + } + BOOST_ASSERT(std::size_t(idx) + 1u < sizeof(masks) / sizeof(masks[0])); + return masks[idx + 1]; +} - static bool BOOST_REGEX_CALL isctype(unsigned short, char_class_type); - static int BOOST_REGEX_CALL value(unsigned short, int); +inline bool BOOST_REGEX_CALL c_regex_traits::isctype(char c, char_class_type mask) +{ + using namespace BOOST_REGEX_DETAIL_NS; + return + ((mask & char_class_space) && (std::isspace)(static_cast(c))) + || ((mask & char_class_print) && (std::isprint)(static_cast(c))) + || ((mask & char_class_cntrl) && (std::iscntrl)(static_cast(c))) + || ((mask & char_class_upper) && (std::isupper)(static_cast(c))) + || ((mask & char_class_lower) && (std::islower)(static_cast(c))) + || ((mask & char_class_alpha) && (std::isalpha)(static_cast(c))) + || ((mask & char_class_digit) && (std::isdigit)(static_cast(c))) + || ((mask & char_class_punct) && (std::ispunct)(static_cast(c))) + || ((mask & char_class_xdigit) && (std::isxdigit)(static_cast(c))) + || ((mask & char_class_blank) && (std::isspace)(static_cast(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c)) + || ((mask & char_class_word) && (c == '_')) + || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == '\v'))) + || ((mask & char_class_horizontal) && (std::isspace)(static_cast(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != '\v')); +} - locale_type imbue(locale_type l) - { return l; } - locale_type getloc()const - { return locale_type(); } +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::lookup_collatename(const char* p1, const char* p2) +{ + std::string s(p1, p2); + s = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(s); + if (s.empty() && (p2 - p1 == 1)) + s.append(1, *p1); + return s; +} -private: - // this type is not copyable: - c_regex_traits(const c_regex_traits&); - c_regex_traits& operator=(const c_regex_traits&); -}; +inline int BOOST_REGEX_CALL c_regex_traits::value(char c, int radix) +{ + char b[2] = { c, '\0', }; + char* ep; + int result = std::strtol(b, &ep, radix); + if (ep == b) + return -1; + return result; +} + +#ifndef BOOST_NO_WREGEX + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform(const wchar_t* p1, const wchar_t* p2) +{ + std::size_t r; + std::size_t s = 10; + std::wstring src(p1, p2); + std::wstring result(s, L' '); + while (s < (r = std::wcsxfrm(&*result.begin(), src.c_str(), s))) + { +#if defined(_CPPLIB_VER) + // + // A bug in VC11 and 12 causes the program to hang if we pass a null-string + // to std::strxfrm, but only for certain locales :-( + // Probably effects Intel and Clang or any compiler using the VC std library (Dinkumware). + // + if (r == INT_MAX) + { + result.erase(); + result.insert(result.begin(), static_cast(0)); + return result; + } +#endif + result.append(r - s + 3, L' '); + s = result.size(); + } + result.erase(r); + return result; +} + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform_primary(const wchar_t* p1, const wchar_t* p2) +{ + static wchar_t s_delim; + static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast*>(0), &s_delim); + std::wstring result; + // + // What we do here depends upon the format of the sort key returned by + // sort key returned by this->transform: + // + switch (s_collate_type) + { + case ::boost::BOOST_REGEX_DETAIL_NS::sort_C: + case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown: + // the best we can do is translate to lower case, then get a regular sort key: + { + result.assign(p1, p2); + for (std::wstring::size_type i = 0; i < result.size(); ++i) + result[i] = (std::towlower)(result[i]); + result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); + break; + } + case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed: + { + // get a regular sort key, and then truncate it: + result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); + result.erase(s_delim); + break; + } + case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim: + // get a regular sort key, and then truncate everything after the delim: + result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); + if ((!result.empty()) && (result[0] == s_delim)) + break; + std::size_t i; + for (i = 0; i < result.size(); ++i) + { + if (result[i] == s_delim) + break; + } + result.erase(i); + break; + } + if (result.empty()) + result = std::wstring(1, char(0)); + return result; +} + +inline c_regex_traits::char_class_type BOOST_REGEX_CALL c_regex_traits::lookup_classname(const wchar_t* p1, const wchar_t* p2) +{ + using namespace BOOST_REGEX_DETAIL_NS; + static const char_class_type masks[] = + { + 0, + char_class_alnum, + char_class_alpha, + char_class_blank, + char_class_cntrl, + char_class_digit, + char_class_digit, + char_class_graph, + char_class_horizontal, + char_class_lower, + char_class_lower, + char_class_print, + char_class_punct, + char_class_space, + char_class_space, + char_class_upper, + char_class_unicode, + char_class_upper, + char_class_vertical, + char_class_alnum | char_class_word, + char_class_alnum | char_class_word, + char_class_xdigit, + }; + + int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2); + if (idx < 0) + { + std::wstring s(p1, p2); + for (std::wstring::size_type i = 0; i < s.size(); ++i) + s[i] = (std::towlower)(s[i]); + idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size()); + } + BOOST_ASSERT(idx + 1 < static_cast(sizeof(masks) / sizeof(masks[0]))); + return masks[idx + 1]; +} + +inline bool BOOST_REGEX_CALL c_regex_traits::isctype(wchar_t c, char_class_type mask) +{ + using namespace BOOST_REGEX_DETAIL_NS; + return + ((mask & char_class_space) && (std::iswspace)(c)) + || ((mask & char_class_print) && (std::iswprint)(c)) + || ((mask & char_class_cntrl) && (std::iswcntrl)(c)) + || ((mask & char_class_upper) && (std::iswupper)(c)) + || ((mask & char_class_lower) && (std::iswlower)(c)) + || ((mask & char_class_alpha) && (std::iswalpha)(c)) + || ((mask & char_class_digit) && (std::iswdigit)(c)) + || ((mask & char_class_punct) && (std::iswpunct)(c)) + || ((mask & char_class_xdigit) && (std::iswxdigit)(c)) + || ((mask & char_class_blank) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c)) + || ((mask & char_class_word) && (c == '_')) + || ((mask & char_class_unicode) && (c & ~static_cast(0xff))) + || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == L'\v'))) + || ((mask & char_class_horizontal) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != L'\v')); +} + +inline c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::lookup_collatename(const wchar_t* p1, const wchar_t* p2) +{ +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable: 4244) +#endif + std::string name(p1, p2); +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + name = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(name); + if (!name.empty()) + return string_type(name.begin(), name.end()); + if (p2 - p1 == 1) + return string_type(1, *p1); + return string_type(); +} + +inline int BOOST_REGEX_CALL c_regex_traits::value(wchar_t c, int radix) +{ +#ifdef BOOST_BORLANDC + // workaround for broken wcstol: + if ((std::iswxdigit)(c) == 0) + return -1; +#endif + wchar_t b[2] = { c, '\0', }; + wchar_t* ep; + int result = std::wcstol(b, &ep, radix); + if (ep == b) + return -1; + return result; +} #endif -#endif // BOOST_NO_WREGEX - } #ifdef BOOST_MSVC diff --git a/include/boost/regex/v5/regex_traits.hpp b/include/boost/regex/v5/regex_traits.hpp index 0c03d77b..8cfb46aa 100644 --- a/include/boost/regex/v5/regex_traits.hpp +++ b/include/boost/regex/v5/regex_traits.hpp @@ -103,11 +103,11 @@ struct default_wrapper : public BaseT } ::boost::regex_constants::syntax_type syntax_type(char_type c)const { - return ((c & 0x7f) == c) ? get_default_syntax_type(static_cast(c)) : ::boost::regex_constants::syntax_char; + return (char_type(c & 0x7f) == c) ? get_default_syntax_type(static_cast(c)) : ::boost::regex_constants::syntax_char; } ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c)const { - return ((c & 0x7f) == c) ? get_default_escape_syntax_type(static_cast(c)) : ::boost::regex_constants::escape_type_identity; + return (char_type(c & 0x7f) == c) ? get_default_escape_syntax_type(static_cast(c)) : ::boost::regex_constants::escape_type_identity; } boost::intmax_t toi(const char_type*& p1, const char_type* p2, int radix)const { diff --git a/src/c_regex_traits.cpp b/src/c_regex_traits.cpp deleted file mode 100644 index 5d70b20b..00000000 --- a/src/c_regex_traits.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * - * Copyright (c) 2004 - * John Maddock - * - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0. (See accompanying file - * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE: c_regex_traits.cpp - * VERSION: see - * DESCRIPTION: Implements out of line c_regex_traits members - */ - -#define BOOST_REGEX_SOURCE - -#include -#include -#include "internals.hpp" - -#if !BOOST_WORKAROUND(BOOST_BORLANDC, < 0x560) - -#include -#include -#include - -#ifdef BOOST_NO_STDC_NAMESPACE -namespace std{ - using ::strxfrm; using ::isspace; - using ::ispunct; using ::isalpha; - using ::isalnum; using ::iscntrl; - using ::isprint; using ::isupper; - using ::islower; using ::isdigit; - using ::isxdigit; using ::strtol; -} -#endif - -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_PREFIX -#endif - -namespace boost{ - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform(const char* p1, const char* p2) -{ - std::string result(10, ' '); - std::size_t s = result.size(); - std::size_t r; - std::string src(p1, p2); - while(s < (r = std::strxfrm(&*result.begin(), src.c_str(), s))) - { -#if defined(_CPPLIB_VER) - // - // A bug in VC11 and 12 causes the program to hang if we pass a null-string - // to std::strxfrm, but only for certain locales :-( - // Probably effects Intel and Clang or any compiler using the VC std library (Dinkumware). - // - if(r == INT_MAX) - { - result.erase(); - result.insert(result.begin(), static_cast(0)); - return result; - } -#endif - result.append(r - s + 3, ' '); - s = result.size(); - } - result.erase(r); - return result; -} - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform_primary(const char* p1, const char* p2) -{ - static char s_delim; - static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast*>(0), &s_delim); - std::string result; - // - // What we do here depends upon the format of the sort key returned by - // sort key returned by this->transform: - // - switch(s_collate_type) - { - case ::boost::BOOST_REGEX_DETAIL_NS::sort_C: - case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown: - // the best we can do is translate to lower case, then get a regular sort key: - { - result.assign(p1, p2); - for(std::string::size_type i = 0; i < result.size(); ++i) - result[i] = static_cast((std::tolower)(static_cast(result[i]))); - result = transform(&*result.begin(), &*result.begin() + result.size()); - break; - } - case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed: - { - // get a regular sort key, and then truncate it: - result = transform(p1, p2); - result.erase(s_delim); - break; - } - case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim: - // get a regular sort key, and then truncate everything after the delim: - result = transform(p1, p2); - if((!result.empty()) && (result[0] == s_delim)) - break; - std::size_t i; - for(i = 0; i < result.size(); ++i) - { - if(result[i] == s_delim) - break; - } - result.erase(i); - break; - } - if(result.empty()) - result = std::string(1, char(0)); - return result; -} - -c_regex_traits::char_class_type BOOST_REGEX_CALL c_regex_traits::lookup_classname(const char* p1, const char* p2) -{ - static const char_class_type masks[] = - { - 0, - char_class_alnum, - char_class_alpha, - char_class_blank, - char_class_cntrl, - char_class_digit, - char_class_digit, - char_class_graph, - char_class_horizontal, - char_class_lower, - char_class_lower, - char_class_print, - char_class_punct, - char_class_space, - char_class_space, - char_class_upper, - char_class_unicode, - char_class_upper, - char_class_vertical, - char_class_alnum | char_class_word, - char_class_alnum | char_class_word, - char_class_xdigit, - }; - - int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2); - if(idx < 0) - { - std::string s(p1, p2); - for(std::string::size_type i = 0; i < s.size(); ++i) - s[i] = static_cast((std::tolower)(static_cast(s[i]))); - idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size()); - } - BOOST_ASSERT(std::size_t(idx) + 1u < sizeof(masks) / sizeof(masks[0])); - return masks[idx+1]; -} - -bool BOOST_REGEX_CALL c_regex_traits::isctype(char c, char_class_type mask) -{ - return - ((mask & char_class_space) && (std::isspace)(static_cast(c))) - || ((mask & char_class_print) && (std::isprint)(static_cast(c))) - || ((mask & char_class_cntrl) && (std::iscntrl)(static_cast(c))) - || ((mask & char_class_upper) && (std::isupper)(static_cast(c))) - || ((mask & char_class_lower) && (std::islower)(static_cast(c))) - || ((mask & char_class_alpha) && (std::isalpha)(static_cast(c))) - || ((mask & char_class_digit) && (std::isdigit)(static_cast(c))) - || ((mask & char_class_punct) && (std::ispunct)(static_cast(c))) - || ((mask & char_class_xdigit) && (std::isxdigit)(static_cast(c))) - || ((mask & char_class_blank) && (std::isspace)(static_cast(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c)) - || ((mask & char_class_word) && (c == '_')) - || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == '\v'))) - || ((mask & char_class_horizontal) && (std::isspace)(static_cast(c)) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != '\v')); -} - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::lookup_collatename(const char* p1, const char* p2) -{ - std::string s(p1, p2); - s = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(s); - if(s.empty() && (p2-p1 == 1)) - s.append(1, *p1); - return s; -} - -int BOOST_REGEX_CALL c_regex_traits::value(char c, int radix) -{ - char b[2] = { c, '\0', }; - char* ep; - int result = std::strtol(b, &ep, radix); - if(ep == b) - return -1; - return result; -} - -} -#ifdef BOOST_HAS_ABI_HEADERS -# include BOOST_ABI_SUFFIX -#endif - -#endif diff --git a/src/fileiter.cpp b/src/fileiter.cpp deleted file mode 100644 index 0c027ec1..00000000 --- a/src/fileiter.cpp +++ /dev/null @@ -1,933 +0,0 @@ -/* - * - * Copyright (c) 1998-2002 - * John Maddock - * - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0. (See accompanying file - * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE: fileiter.cpp - * VERSION: see - * DESCRIPTION: Implements file io primitives + directory searching for class boost::RegEx. - */ - - -#define BOOST_REGEX_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#if defined(BOOST_NO_STDC_NAMESPACE) -namespace std{ - using ::sprintf; - using ::fseek; - using ::fread; - using ::ftell; - using ::fopen; - using ::fclose; - using ::FILE; - using ::strcpy; - using ::strcpy; - using ::strcat; - using ::strcmp; - using ::strlen; -} -#endif - - -#ifndef BOOST_REGEX_NO_FILEITER - -#if defined(__CYGWIN__) || defined(__CYGWIN32__) -#include -#endif - -#ifdef BOOST_MSVC -# pragma warning(disable: 4800) -#endif - -namespace boost{ - namespace BOOST_REGEX_DETAIL_NS{ -// start with the operating system specific stuff: - -#if (defined(BOOST_BORLANDC) || defined(BOOST_REGEX_FI_WIN32_DIR) || defined(BOOST_MSVC)) && !defined(BOOST_RE_NO_WIN32) - -// platform is DOS or Windows -// directories are separated with '\\' -// and names are insensitive of case - -BOOST_REGEX_DECL const char* _fi_sep = "\\"; -const char* _fi_sep_alt = "/"; -#define BOOST_REGEX_FI_TRANSLATE(c) std::tolower(c) - -#else - -// platform is not DOS or Windows -// directories are separated with '/' -// and names are sensitive of case - -BOOST_REGEX_DECL const char* _fi_sep = "/"; -const char* _fi_sep_alt = _fi_sep; -#define BOOST_REGEX_FI_TRANSLATE(c) c - -#endif - -#ifdef BOOST_REGEX_FI_WIN32_MAP - -void mapfile::open(const char* file) -{ -#if defined(BOOST_NO_ANSI_APIS) - int filename_size = strlen(file); - LPWSTR wide_file = (LPWSTR)_alloca( (filename_size + 1) * sizeof(WCHAR) ); - if(::MultiByteToWideChar(CP_ACP, 0, file, filename_size, wide_file, filename_size + 1) == 0) - hfile = INVALID_HANDLE_VALUE; - else - hfile = CreateFileW(wide_file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); -#elif defined(__CYGWIN__)||defined(__CYGWIN32__) - char win32file[ MAX_PATH ]; - cygwin_conv_to_win32_path( file, win32file ); - hfile = CreateFileA(win32file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); -#else - hfile = CreateFileA(file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); -#endif - if(hfile != INVALID_HANDLE_VALUE) - { - hmap = CreateFileMapping(hfile, 0, PAGE_READONLY, 0, 0, 0); - if((hmap == INVALID_HANDLE_VALUE) || (hmap == NULL)) - { - CloseHandle(hfile); - hmap = 0; - hfile = 0; - std::runtime_error err("Unable to create file mapping."); - boost::BOOST_REGEX_DETAIL_NS::raise_runtime_error(err); - } - else - { - _first = static_cast(MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0)); - if (_first == 0) - { - CloseHandle(hmap); - CloseHandle(hfile); - hmap = 0; - hfile = 0; - std::runtime_error err("Unable to create file mapping."); - boost::BOOST_REGEX_DETAIL_NS::raise_runtime_error(err); - } - else - _last = _first + GetFileSize(hfile, 0); - } - } - else - { - hfile = 0; -#ifndef BOOST_NO_EXCEPTIONS - throw std::runtime_error("Unable to open file."); -#else - BOOST_REGEX_NOEH_ASSERT(hfile != INVALID_HANDLE_VALUE); -#endif - } -} - -void mapfile::close() -{ - if(hfile != INVALID_HANDLE_VALUE) - { - UnmapViewOfFile((void*)_first); - CloseHandle(hmap); - CloseHandle(hfile); - hmap = hfile = 0; - _first = _last = 0; - } -} - -#elif !defined(BOOST_RE_NO_STL) - -mapfile_iterator& mapfile_iterator::operator = (const mapfile_iterator& i) -{ - if(file && node) - file->unlock(node); - file = i.file; - node = i.node; - offset = i.offset; - if(file) - file->lock(node); - return *this; -} - -mapfile_iterator& mapfile_iterator::operator++ () -{ - if((++offset == mapfile::buf_size) && file) - { - ++node; - offset = 0; - file->lock(node); - file->unlock(node-1); - } - return *this; -} - -mapfile_iterator mapfile_iterator::operator++ (int) -{ - mapfile_iterator temp(*this); - if((++offset == mapfile::buf_size) && file) - { - ++node; - offset = 0; - file->lock(node); - file->unlock(node-1); - } - return temp; -} - -mapfile_iterator& mapfile_iterator::operator-- () -{ - if((offset == 0) && file) - { - --node; - offset = mapfile::buf_size - 1; - file->lock(node); - file->unlock(node + 1); - } - else - --offset; - return *this; -} - -mapfile_iterator mapfile_iterator::operator-- (int) -{ - mapfile_iterator temp(*this); - if((offset == 0) && file) - { - --node; - offset = mapfile::buf_size - 1; - file->lock(node); - file->unlock(node + 1); - } - else - --offset; - return temp; -} - -mapfile_iterator operator + (const mapfile_iterator& i, long off) -{ - mapfile_iterator temp(i); - temp += off; - return temp; -} - -mapfile_iterator operator - (const mapfile_iterator& i, long off) -{ - mapfile_iterator temp(i); - temp -= off; - return temp; -} - -mapfile::iterator mapfile::begin()const -{ - return mapfile_iterator(this, 0); -} - -mapfile::iterator mapfile::end()const -{ - return mapfile_iterator(this, _size); -} - -void mapfile::lock(pointer* node)const -{ - BOOST_ASSERT(node >= _first); - BOOST_ASSERT(node <= _last); - if(node < _last) - { - if(*node == 0) - { - if(condemed.empty()) - { - *node = new char[sizeof(int) + buf_size]; - *(reinterpret_cast(*node)) = 1; - } - else - { - pointer* p = condemed.front(); - condemed.pop_front(); - *node = *p; - *p = 0; - *(reinterpret_cast(*node)) = 1; - } - - std::size_t read_size = 0; - int read_pos = std::fseek(hfile, (node - _first) * buf_size, SEEK_SET); - - if(0 == read_pos && node == _last - 1) - read_size = std::fread(*node + sizeof(int), _size % buf_size, 1, hfile); - else - read_size = std::fread(*node + sizeof(int), buf_size, 1, hfile); - if((read_size == 0) || (std::ferror(hfile))) - { -#ifndef BOOST_NO_EXCEPTIONS - unlock(node); - throw std::runtime_error("Unable to read file."); -#else - BOOST_REGEX_NOEH_ASSERT((0 == std::ferror(hfile)) && (read_size != 0)); -#endif - } - } - else - { - if(*reinterpret_cast(*node) == 0) - { - *reinterpret_cast(*node) = 1; - condemed.remove(node); - } - else - ++(*reinterpret_cast(*node)); - } - } -} - -void mapfile::unlock(pointer* node)const -{ - BOOST_ASSERT(node >= _first); - BOOST_ASSERT(node <= _last); - if(node < _last) - { - if(--(*reinterpret_cast(*node)) == 0) - { - condemed.push_back(node); - } - } -} - -long int get_file_length(std::FILE* hfile) -{ - long int result; - std::fseek(hfile, 0, SEEK_END); - result = std::ftell(hfile); - std::fseek(hfile, 0, SEEK_SET); - return result; -} - - -void mapfile::open(const char* file) -{ - hfile = std::fopen(file, "rb"); -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - if(hfile != 0) - { - _size = get_file_length(hfile); - long cnodes = (_size + buf_size - 1) / buf_size; - - // check that number of nodes is not too high: - if(cnodes > (long)((INT_MAX) / sizeof(pointer*))) - { - std::fclose(hfile); - hfile = 0; - _size = 0; - return; - } - - _first = new pointer[(int)cnodes]; - _last = _first + cnodes; - std::memset(_first, 0, cnodes*sizeof(pointer)); - } - else - { - std::runtime_error err("Unable to open file."); - } -#ifndef BOOST_NO_EXCEPTIONS - }catch(...) - { close(); throw; } -#endif -} - -void mapfile::close() -{ - if(hfile != 0) - { - pointer* p = _first; - while(p != _last) - { - if(*p) - delete[] *p; - ++p; - } - delete[] _first; - _size = 0; - _first = _last = 0; - std::fclose(hfile); - hfile = 0; - condemed.erase(condemed.begin(), condemed.end()); - } -} - - -#endif - -inline _fi_find_handle find_first_file(const char* wild, _fi_find_data& data) -{ -#ifdef BOOST_NO_ANSI_APIS - std::size_t wild_size = std::strlen(wild); - LPWSTR wide_wild = (LPWSTR)_alloca( (wild_size + 1) * sizeof(WCHAR) ); - if (::MultiByteToWideChar(CP_ACP, 0, wild, wild_size, wide_wild, wild_size + 1) == 0) - return _fi_invalid_handle; - - return FindFirstFileW(wide_wild, &data); -#else - return FindFirstFileA(wild, &data); -#endif -} - -inline bool find_next_file(_fi_find_handle hf, _fi_find_data& data) -{ -#ifdef BOOST_NO_ANSI_APIS - return FindNextFileW(hf, &data); -#else - return FindNextFileA(hf, &data); -#endif -} - -inline void copy_find_file_result_with_overflow_check(const _fi_find_data& data, char* path, size_t max_size) -{ -#ifdef BOOST_NO_ANSI_APIS - if (::WideCharToMultiByte(CP_ACP, 0, data.cFileName, -1, path, max_size, NULL, NULL) == 0) - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(1); -#else - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(path, max_size, data.cFileName)); -#endif -} - -inline bool is_not_current_or_parent_path_string(const _fi_find_data& data) -{ -#ifdef BOOST_NO_ANSI_APIS - return (std::wcscmp(data.cFileName, L".") && std::wcscmp(data.cFileName, L"..")); -#else - return (std::strcmp(data.cFileName, ".") && std::strcmp(data.cFileName, "..")); -#endif -} - - -file_iterator::file_iterator() -{ - _root = _path = 0; - ref = 0; -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - _root = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_root) - _path = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_path) - ptr = _path; - *_path = 0; - *_root = 0; - ref = new file_iterator_ref(); - BOOST_REGEX_NOEH_ASSERT(ref) - ref->hf = _fi_invalid_handle; - ref->count = 1; -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - delete[] _root; - delete[] _path; - delete ref; - throw; - } -#endif -} - -file_iterator::file_iterator(const char* wild) -{ - _root = _path = 0; - ref = 0; -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - _root = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_root) - _path = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_path) - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_root, MAX_PATH, wild)); - ptr = _root; - while(*ptr)++ptr; - while((ptr > _root) && (*ptr != *_fi_sep) && (*ptr != *_fi_sep_alt))--ptr; - if((ptr == _root) && ( (*ptr== *_fi_sep) || (*ptr==*_fi_sep_alt) ) ) - { - _root[1]='\0'; - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, _root)); - } - else - { - *ptr = 0; - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, _root)); - if(*_path == 0) - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, ".")); - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcat_s(_path, MAX_PATH, _fi_sep)); - } - ptr = _path + std::strlen(_path); - - ref = new file_iterator_ref(); - BOOST_REGEX_NOEH_ASSERT(ref) - ref->hf = find_first_file(wild, ref->_data); - ref->count = 1; - - if(ref->hf == _fi_invalid_handle) - { - *_path = 0; - ptr = _path; - } - else - { - copy_find_file_result_with_overflow_check(ref->_data, ptr, (MAX_PATH - (ptr - _path))); - if(ref->_data.dwFileAttributes & _fi_dir) - next(); - } -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - delete[] _root; - delete[] _path; - delete ref; - throw; - } -#endif -} - -file_iterator::file_iterator(const file_iterator& other) -{ - _root = _path = 0; - ref = 0; -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - _root = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_root) - _path = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_path) - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_root, MAX_PATH, other._root)); - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, other._path)); - ptr = _path + (other.ptr - other._path); - ref = other.ref; -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - delete[] _root; - delete[] _path; - throw; - } -#endif - ++(ref->count); -} - -file_iterator& file_iterator::operator=(const file_iterator& other) -{ - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_root, MAX_PATH, other._root)); - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, other._path)); - ptr = _path + (other.ptr - other._path); - if(--(ref->count) == 0) - { - if(ref->hf != _fi_invalid_handle) - FindClose(ref->hf); - delete ref; - } - ref = other.ref; - ++(ref->count); - return *this; -} - - -file_iterator::~file_iterator() -{ - delete[] _root; - delete[] _path; - if(--(ref->count) == 0) - { - if(ref->hf != _fi_invalid_handle) - FindClose(ref->hf); - delete ref; - } -} - -file_iterator file_iterator::operator++(int) -{ - file_iterator temp(*this); - next(); - return temp; -} - - -void file_iterator::next() -{ - if(ref->hf != _fi_invalid_handle) - { - bool cont = true; - while(cont) - { - cont = find_next_file(ref->hf, ref->_data); - if(cont && ((ref->_data.dwFileAttributes & _fi_dir) == 0)) - break; - } - if(!cont) - { - // end of sequence - FindClose(ref->hf); - ref->hf = _fi_invalid_handle; - *_path = 0; - ptr = _path; - } - else - copy_find_file_result_with_overflow_check(ref->_data, ptr, MAX_PATH - (ptr - _path)); - } -} - - - -directory_iterator::directory_iterator() -{ - _root = _path = 0; - ref = 0; -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - _root = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_root) - _path = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_path) - ptr = _path; - *_path = 0; - *_root = 0; - ref = new file_iterator_ref(); - BOOST_REGEX_NOEH_ASSERT(ref) - ref->hf = _fi_invalid_handle; - ref->count = 1; -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - delete[] _root; - delete[] _path; - delete ref; - throw; - } -#endif -} - -directory_iterator::directory_iterator(const char* wild) -{ - _root = _path = 0; - ref = 0; -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - _root = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_root) - _path = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_path) - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_root, MAX_PATH, wild)); - ptr = _root; - while(*ptr)++ptr; - while((ptr > _root) && (*ptr != *_fi_sep) && (*ptr != *_fi_sep_alt))--ptr; - - if((ptr == _root) && ( (*ptr== *_fi_sep) || (*ptr==*_fi_sep_alt) ) ) - { - _root[1]='\0'; - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, _root)); - } - else - { - *ptr = 0; - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, _root)); - if(*_path == 0) - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, ".")); - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcat_s(_path, MAX_PATH, _fi_sep)); - } - ptr = _path + std::strlen(_path); - - ref = new file_iterator_ref(); - BOOST_REGEX_NOEH_ASSERT(ref) - ref->count = 1; - ref->hf = find_first_file(wild, ref->_data); - if(ref->hf == _fi_invalid_handle) - { - *_path = 0; - ptr = _path; - } - else - { - copy_find_file_result_with_overflow_check(ref->_data, ptr, MAX_PATH - (ptr - _path)); - if(((ref->_data.dwFileAttributes & _fi_dir) == 0) || (std::strcmp(ptr, ".") == 0) || (std::strcmp(ptr, "..") == 0)) - next(); - } -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - delete[] _root; - delete[] _path; - delete ref; - throw; - } -#endif -} - -directory_iterator::~directory_iterator() -{ - delete[] _root; - delete[] _path; - if(--(ref->count) == 0) - { - if(ref->hf != _fi_invalid_handle) - FindClose(ref->hf); - delete ref; - } -} - -directory_iterator::directory_iterator(const directory_iterator& other) -{ - _root = _path = 0; - ref = 0; -#ifndef BOOST_NO_EXCEPTIONS - try{ -#endif - _root = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_root) - _path = new char[MAX_PATH]; - BOOST_REGEX_NOEH_ASSERT(_path) - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_root, MAX_PATH, other._root)); - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, other._path)); - ptr = _path + (other.ptr - other._path); - ref = other.ref; -#ifndef BOOST_NO_EXCEPTIONS - } - catch(...) - { - delete[] _root; - delete[] _path; - throw; - } -#endif - ++(ref->count); -} - -directory_iterator& directory_iterator::operator=(const directory_iterator& other) -{ - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_root, MAX_PATH, other._root)); - BOOST_REGEX_DETAIL_NS::overflow_error_if_not_zero(BOOST_REGEX_DETAIL_NS::strcpy_s(_path, MAX_PATH, other._path)); - ptr = _path + (other.ptr - other._path); - if(--(ref->count) == 0) - { - if(ref->hf != _fi_invalid_handle) - FindClose(ref->hf); - delete ref; - } - ref = other.ref; - ++(ref->count); - return *this; -} - -directory_iterator directory_iterator::operator++(int) -{ - directory_iterator temp(*this); - next(); - return temp; -} - -void directory_iterator::next() -{ - if(ref->hf != _fi_invalid_handle) - { - bool cont = true; - while(cont) - { - cont = find_next_file(ref->hf, ref->_data); - if(cont && (ref->_data.dwFileAttributes & _fi_dir)) - { - if(is_not_current_or_parent_path_string(ref->_data)) - break; - } - } - if(!cont) - { - // end of sequence - FindClose(ref->hf); - ref->hf = _fi_invalid_handle; - *_path = 0; - ptr = _path; - } - else - copy_find_file_result_with_overflow_check(ref->_data, ptr, MAX_PATH - (ptr - _path)); - } -} - - -#ifdef BOOST_REGEX_FI_POSIX_DIR - -struct _fi_priv_data -{ - char root[MAX_PATH]; - char* mask; - DIR* d; - _fi_priv_data(const char* p); -}; - -_fi_priv_data::_fi_priv_data(const char* p) -{ - std::strcpy(root, p); - mask = root; - while(*mask) ++mask; - while((mask > root) && (*mask != *_fi_sep) && (*mask != *_fi_sep_alt)) --mask; - if(mask == root && ((*mask== *_fi_sep) || (*mask == *_fi_sep_alt)) ) - { - root[1] = '\0'; - std::strcpy(root+2, p+1); - mask = root+2; - } - else if(mask == root) - { - root[0] = '.'; - root[1] = '\0'; - std::strcpy(root+2, p); - mask = root+2; - } - else - { - *mask = 0; - ++mask; - } -} - -bool iswild(const char* mask, const char* name) -{ - while(*mask && *name) - { - switch(*mask) - { - case '?': - ++name; - ++mask; - continue; - case '*': - ++mask; - if(*mask == 0) - return true; - while(*name) - { - if(iswild(mask, name)) - return true; - ++name; - } - return false; - case '.': - if(0 == *name) - { - ++mask; - continue; - } - // fall through - default: - if(BOOST_REGEX_FI_TRANSLATE(*mask) != BOOST_REGEX_FI_TRANSLATE(*name)) - return false; - ++mask; - ++name; - continue; - } - } - if(*mask != *name) - return false; - return true; -} - -unsigned _fi_attributes(const char* root, const char* name) -{ - char buf[MAX_PATH]; - // verify that we can not overflow: - if(std::strlen(root) + std::strlen(_fi_sep) + std::strlen(name) >= MAX_PATH) - return 0; - int r; - if( ( (root[0] == *_fi_sep) || (root[0] == *_fi_sep_alt) ) && (root[1] == '\0') ) - r = (std::sprintf)(buf, "%s%s", root, name); - else - r = (std::sprintf)(buf, "%s%s%s", root, _fi_sep, name); - if(r < 0) - return 0; // sprintf failed - DIR* d = opendir(buf); - if(d) - { - closedir(d); - return _fi_dir; - } - return 0; -} - -_fi_find_handle _fi_FindFirstFile(const char* lpFileName, _fi_find_data* lpFindFileData) -{ - _fi_find_handle dat = new _fi_priv_data(lpFileName); - - DIR* h = opendir(dat->root); - dat->d = h; - if(h != 0) - { - if(_fi_FindNextFile(dat, lpFindFileData)) - return dat; - closedir(h); - } - delete dat; - return 0; -} - -bool _fi_FindNextFile(_fi_find_handle dat, _fi_find_data* lpFindFileData) -{ - dirent* d; - do - { - d = readdir(dat->d); - } while(d && !iswild(dat->mask, d->d_name)); - - if(d) - { - std::strcpy(lpFindFileData->cFileName, d->d_name); - lpFindFileData->dwFileAttributes = _fi_attributes(dat->root, d->d_name); - return true; - } - return false; -} - -bool _fi_FindClose(_fi_find_handle dat) -{ - closedir(dat->d); - delete dat; - return true; -} - -#endif - -} // namespace BOOST_REGEX_DETAIL_NS -} // namspace boost - -#endif // BOOST_REGEX_NO_FILEITER - - - - - - - - - - - - diff --git a/src/instances.cpp b/src/instances.cpp deleted file mode 100644 index 88502b19..00000000 --- a/src/instances.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Copyright (c) 1998-2002 - * John Maddock - * - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0. (See accompanying file - * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE: instances.cpp - * VERSION: see - * DESCRIPTION: regex narrow character template instances. - */ - -#define BOOST_REGEX_SOURCE - -#include - -#if !defined(BOOST_REGEX_NO_EXTERNAL_TEMPLATES) -#define BOOST_REGEX_NARROW_INSTANTIATE - -#ifdef BOOST_BORLANDC -#pragma hrdstop -#endif - -#include - -#endif diff --git a/src/usinstances.cpp b/src/usinstances.cpp deleted file mode 100644 index 44ebd28d..00000000 --- a/src/usinstances.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * - * Copyright (c) 1998-2002 - * John Maddock - * - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0. (See accompanying file - * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE: winstances.cpp - * VERSION: see - * DESCRIPTION: regex unsigned short template instances (MSVC only). - */ - -#define BOOST_REGEX_SOURCE -#ifdef _MSC_VER -#pragma warning(disable:4506) // 'no definition for inline function' -#endif - -#include -#include -#include - -#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) && defined(_NATIVE_WCHAR_T_DEFINED) \ - && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) || defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER))\ - && BOOST_WORKAROUND(BOOST_MSVC, <1600) -// -// This is a horrible workaround, but without declaring these symbols extern we get -// duplicate symbol errors when linking if the application is built without -// /Zc:wchar_t -// -#ifdef _CRTIMP2_PURE -# define BOOST_REGEX_STDLIB_DECL _CRTIMP2_PURE -#else -# define BOOST_REGEX_STDLIB_DECL _CRTIMP2 -#endif - -namespace std{ - -#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) -template class BOOST_REGEX_STDLIB_DECL allocator; -template class BOOST_REGEX_STDLIB_DECL _String_val >; -template class BOOST_REGEX_STDLIB_DECL basic_string, allocator >; -#endif - -#if BOOST_WORKAROUND(BOOST_MSVC, > 1300) && BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) -template<> BOOST_REGEX_STDLIB_DECL std::size_t __cdecl char_traits::length(unsigned short const*); -#endif - -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==( - const basic_string, allocator >&, - const basic_string, allocator >&); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==( - const unsigned short *, - const basic_string, allocator >&); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==( - const basic_string, allocator >&, - const unsigned short *); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator<( - const basic_string, allocator >&, - const basic_string, allocator >&); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator>( - const basic_string, allocator >&, - const basic_string, allocator >&); -} -#endif - -#include - -#if !defined(BOOST_NO_WREGEX) && defined(BOOST_REGEX_HAS_OTHER_WCHAR_T) && !defined(BOOST_REGEX_NO_EXTERNAL_TEMPLATES) -#define BOOST_REGEX_US_INSTANTIATE - -#include - -#endif - - diff --git a/src/wc_regex_traits.cpp b/src/wc_regex_traits.cpp deleted file mode 100644 index bbdb5739..00000000 --- a/src/wc_regex_traits.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/* - * - * Copyright (c) 2004 - * John Maddock - * - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0. (See accompanying file - * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE: wc_regex_traits.cpp - * VERSION: see - * DESCRIPTION: Implements out of line members for c_regex_traits - */ - - -#define BOOST_REGEX_SOURCE - -#include -#include -#include -#include "internals.hpp" - -#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE) && defined(_NATIVE_WCHAR_T_DEFINED) \ - && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) || defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER))\ - && BOOST_WORKAROUND(BOOST_MSVC, <1600) -// -// This is a horrible workaround, but without declaring these symbols extern we get -// duplicate symbol errors when linking if the application is built without -// /Zc:wchar_t -// -#ifdef _CRTIMP2_PURE -# define BOOST_REGEX_STDLIB_DECL _CRTIMP2_PURE -#else -# define BOOST_REGEX_STDLIB_DECL _CRTIMP2 -#endif - -namespace std{ - -#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) -template class BOOST_REGEX_STDLIB_DECL allocator; -template class BOOST_REGEX_STDLIB_DECL _String_val >; -template class BOOST_REGEX_STDLIB_DECL basic_string, allocator >; -#endif - -#if BOOST_WORKAROUND(BOOST_MSVC, > 1300) && BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) -template<> BOOST_REGEX_STDLIB_DECL std::size_t __cdecl char_traits::length(unsigned short const*); -#endif - -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==( - const basic_string, allocator >&, - const basic_string, allocator >&); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==( - const unsigned short *, - const basic_string, allocator >&); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator==( - const basic_string, allocator >&, - const unsigned short *); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator<( - const basic_string, allocator >&, - const basic_string, allocator >&); -template BOOST_REGEX_STDLIB_DECL bool __cdecl operator>( - const basic_string, allocator >&, - const basic_string, allocator >&); -} -#endif - -#include -#include - -#if !BOOST_WORKAROUND(BOOST_BORLANDC, < 0x560) - -#include -#ifndef BOOST_NO_WREGEX -#include -#include - -#if defined(BOOST_NO_STDC_NAMESPACE) -namespace std{ - using ::wcstol; -} -#endif - -namespace boost{ - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform(const wchar_t* p1, const wchar_t* p2) -{ - std::size_t r; - std::size_t s = 10; - std::wstring src(p1, p2); - std::wstring result(s, L' '); - while(s < (r = std::wcsxfrm(&*result.begin(), src.c_str(), s))) - { -#if defined(_CPPLIB_VER) - // - // A bug in VC11 and 12 causes the program to hang if we pass a null-string - // to std::strxfrm, but only for certain locales :-( - // Probably effects Intel and Clang or any compiler using the VC std library (Dinkumware). - // - if(r == INT_MAX) - { - result.erase(); - result.insert(result.begin(), static_cast(0)); - return result; - } -#endif - result.append(r - s + 3, L' '); - s = result.size(); - } - result.erase(r); - return result; -} - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform_primary(const wchar_t* p1, const wchar_t* p2) -{ - static wchar_t s_delim; - static const int s_collate_type = ::boost::BOOST_REGEX_DETAIL_NS::find_sort_syntax(static_cast*>(0), &s_delim); - std::wstring result; - // - // What we do here depends upon the format of the sort key returned by - // sort key returned by this->transform: - // - switch(s_collate_type) - { - case ::boost::BOOST_REGEX_DETAIL_NS::sort_C: - case ::boost::BOOST_REGEX_DETAIL_NS::sort_unknown: - // the best we can do is translate to lower case, then get a regular sort key: - { - result.assign(p1, p2); - for(std::wstring::size_type i = 0; i < result.size(); ++i) - result[i] = (std::towlower)(result[i]); - result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); - break; - } - case ::boost::BOOST_REGEX_DETAIL_NS::sort_fixed: - { - // get a regular sort key, and then truncate it: - result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); - result.erase(s_delim); - break; - } - case ::boost::BOOST_REGEX_DETAIL_NS::sort_delim: - // get a regular sort key, and then truncate everything after the delim: - result = c_regex_traits::transform(&*result.begin(), &*result.begin() + result.size()); - if((!result.empty()) && (result[0] == s_delim)) - break; - std::size_t i; - for(i = 0; i < result.size(); ++i) - { - if(result[i] == s_delim) - break; - } - result.erase(i); - break; - } - if(result.empty()) - result = std::wstring(1, char(0)); - return result; -} - -c_regex_traits::char_class_type BOOST_REGEX_CALL c_regex_traits::lookup_classname(const wchar_t* p1, const wchar_t* p2) -{ - static const char_class_type masks[] = - { - 0, - char_class_alnum, - char_class_alpha, - char_class_blank, - char_class_cntrl, - char_class_digit, - char_class_digit, - char_class_graph, - char_class_horizontal, - char_class_lower, - char_class_lower, - char_class_print, - char_class_punct, - char_class_space, - char_class_space, - char_class_upper, - char_class_unicode, - char_class_upper, - char_class_vertical, - char_class_alnum | char_class_word, - char_class_alnum | char_class_word, - char_class_xdigit, - }; - - int idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(p1, p2); - if(idx < 0) - { - std::wstring s(p1, p2); - for(std::wstring::size_type i = 0; i < s.size(); ++i) - s[i] = (std::towlower)(s[i]); - idx = ::boost::BOOST_REGEX_DETAIL_NS::get_default_class_id(&*s.begin(), &*s.begin() + s.size()); - } - BOOST_ASSERT(idx+1 < static_cast(sizeof(masks) / sizeof(masks[0]))); - return masks[idx+1]; -} - -bool BOOST_REGEX_CALL c_regex_traits::isctype(wchar_t c, char_class_type mask) -{ - return - ((mask & char_class_space) && (std::iswspace)(c)) - || ((mask & char_class_print) && (std::iswprint)(c)) - || ((mask & char_class_cntrl) && (std::iswcntrl)(c)) - || ((mask & char_class_upper) && (std::iswupper)(c)) - || ((mask & char_class_lower) && (std::iswlower)(c)) - || ((mask & char_class_alpha) && (std::iswalpha)(c)) - || ((mask & char_class_digit) && (std::iswdigit)(c)) - || ((mask & char_class_punct) && (std::iswpunct)(c)) - || ((mask & char_class_xdigit) && (std::iswxdigit)(c)) - || ((mask & char_class_blank) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c)) - || ((mask & char_class_word) && (c == '_')) - || ((mask & char_class_unicode) && (c & ~static_cast(0xff))) - || ((mask & char_class_vertical) && (::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) || (c == L'\v'))) - || ((mask & char_class_horizontal) && (std::iswspace)(c) && !::boost::BOOST_REGEX_DETAIL_NS::is_separator(c) && (c != L'\v')); -} - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::lookup_collatename(const wchar_t* p1, const wchar_t* p2) -{ -#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\ - && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\ - && !BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x0551) - std::string name(p1, p2); -#else - std::string name; - const wchar_t* p0 = p1; - while(p0 != p2) - name.append(1, char(*p0++)); -#endif - name = ::boost::BOOST_REGEX_DETAIL_NS::lookup_default_collate_name(name); -#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\ - && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\ - && !BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x0551) - if(!name.empty()) - return string_type(name.begin(), name.end()); -#else - if(name.size()) - { - string_type result; - typedef std::string::const_iterator iter; - iter b = name.begin(); - iter e = name.end(); - while(b != e) - result.append(1, wchar_t(*b++)); - return result; - } -#endif - if(p2 - p1 == 1) - return string_type(1, *p1); - return string_type(); -} - -int BOOST_REGEX_CALL c_regex_traits::value(wchar_t c, int radix) -{ -#ifdef BOOST_BORLANDC - // workaround for broken wcstol: - if((std::iswxdigit)(c) == 0) - return -1; -#endif - wchar_t b[2] = { c, '\0', }; - wchar_t* ep; - int result = std::wcstol(b, &ep, radix); - if(ep == b) - return -1; - return result; -} - -#ifdef BOOST_REGEX_HAS_OTHER_WCHAR_T -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform(const unsigned short* p1, const unsigned short* p2) -{ - std::wstring result = c_regex_traits::transform((const wchar_t*)p1, (const wchar_t*)p2); - return string_type(result.begin(), result.end()); -} - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::transform_primary(const unsigned short* p1, const unsigned short* p2) -{ - std::wstring result = c_regex_traits::transform_primary((const wchar_t*)p1, (const wchar_t*)p2); - return string_type(result.begin(), result.end()); -} - -c_regex_traits::char_class_type BOOST_REGEX_CALL c_regex_traits::lookup_classname(const unsigned short* p1, const unsigned short* p2) -{ - return c_regex_traits::lookup_classname((const wchar_t*)p1, (const wchar_t*)p2); -} - -c_regex_traits::string_type BOOST_REGEX_CALL c_regex_traits::lookup_collatename(const unsigned short* p1, const unsigned short* p2) -{ - std::wstring result = c_regex_traits::lookup_collatename((const wchar_t*)p1, (const wchar_t*)p2); - return string_type(result.begin(), result.end()); -} - -bool BOOST_REGEX_CALL c_regex_traits::isctype(unsigned short c, char_class_type m) -{ - return c_regex_traits::isctype(c, m); -} - -int BOOST_REGEX_CALL c_regex_traits::value(unsigned short c, int radix) -{ - return c_regex_traits::value(c, radix); -} - -#endif - -} - -#endif // BOOST_NO_WREGEX - -#endif // BOOST_BORLANDC diff --git a/src/winstances.cpp b/src/winstances.cpp deleted file mode 100644 index beaf0ea5..00000000 --- a/src/winstances.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Copyright (c) 1998-2002 - * John Maddock - * - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0. (See accompanying file - * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - * - */ - - /* - * LOCATION: see http://www.boost.org for most recent version. - * FILE: winstances.cpp - * VERSION: see - * DESCRIPTION: regex wide character template instances. - */ - -#define BOOST_REGEX_SOURCE - -#include - -#if !defined(BOOST_NO_WREGEX) && !defined(BOOST_REGEX_NO_EXTERNAL_TEMPLATES) -#define BOOST_REGEX_WIDE_INSTANTIATE - -#ifdef BOOST_BORLANDC -#pragma hrdstop -#endif - -#include - -#endif - - - diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 49ed730b..b0f7c729 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -60,31 +60,6 @@ test_overloads.cpp test_operators.cpp ; -lib boost_regex_recursive : - ../src/c_regex_traits.cpp - ../src/cpp_regex_traits.cpp - ../src/cregex.cpp - ../src/fileiter.cpp - ../src/icu.cpp - ../src/instances.cpp - ../src/posix_api.cpp - ../src/regex.cpp - ../src/regex_debug.cpp - ../src/regex_raw_buffer.cpp - ../src/regex_traits_defaults.cpp - ../src/static_mutex.cpp - ../src/w32_regex_traits.cpp - ../src/wc_regex_traits.cpp - ../src/wide_posix_api.cpp - ../src/winstances.cpp - ../src/usinstances.cpp - ../build//icu_options - : - BOOST_REGEX_RECURSIVE=1 - shared:BOOST_REGEX_DYN_LINK=1 - : - ; - local regress-sources = regress/$(R_SOURCE) ; test-suite regex @@ -169,14 +144,6 @@ test-suite regex captures_test ] -[ run regress/$(R_SOURCE) .//boost_regex_recursive - ../build//icu_options - : # command line - : # input files - : # requirements - BOOST_REGEX_RECURSIVE=1 - : regex_regress_recursive ] - [ run regress/$(R_SOURCE) ./noeh_test//boost_regex_noeh ../build//icu_options : # command line diff --git a/test/captures/Jamfile.v2 b/test/captures/Jamfile.v2 index f3ee8905..4c8da6a4 100644 --- a/test/captures/Jamfile.v2 +++ b/test/captures/Jamfile.v2 @@ -8,12 +8,8 @@ project ; EX_SOURCES = - c_regex_traits.cpp cpp_regex_traits.cpp - cregex.cpp - fileiter.cpp icu.cpp - instances.cpp posix_api.cpp regex.cpp regex_debug.cpp @@ -21,10 +17,7 @@ EX_SOURCES = regex_traits_defaults.cpp static_mutex.cpp w32_regex_traits.cpp - wc_regex_traits.cpp - wide_posix_api.cpp - winstances.cpp - usinstances.cpp ; + wide_posix_api.cpp ; lib boost_regex_extra : $(EX_SOURCES) ../../build//icu_options : diff --git a/test/noeh_test/Jamfile.v2 b/test/noeh_test/Jamfile.v2 index dcaa84b9..ac45f190 100644 --- a/test/noeh_test/Jamfile.v2 +++ b/test/noeh_test/Jamfile.v2 @@ -24,12 +24,8 @@ project lib boost_regex_noeh : - ../../src/c_regex_traits.cpp ../../src/cpp_regex_traits.cpp - ../../src/cregex.cpp - ../../src/fileiter.cpp ../../src/icu.cpp - ../../src/instances.cpp ../../src/posix_api.cpp ../../src/regex.cpp ../../src/regex_debug.cpp @@ -37,10 +33,7 @@ lib boost_regex_noeh : ../../src/regex_traits_defaults.cpp ../../src/static_mutex.cpp ../../src/w32_regex_traits.cpp - ../../src/wc_regex_traits.cpp ../../src/wide_posix_api.cpp - ../../src/winstances.cpp - ../../src/usinstances.cpp ../../build//icu_options : static diff --git a/test/regress/test_deprecated.cpp b/test/regress/test_deprecated.cpp index 08702c0a..6a04a3ec 100644 --- a/test/regress/test_deprecated.cpp +++ b/test/regress/test_deprecated.cpp @@ -133,6 +133,11 @@ void test_deprecated(const char&, const test_regex_search_tag&) } +std::string to_narrow_string(std::wstring const& w) +{ + return std::string(w.begin(), w.end()); +} + void test_deprecated(const wchar_t&, const test_regex_search_tag&) { #ifndef BOOST_NO_WREGEX @@ -154,7 +159,7 @@ void test_deprecated(const wchar_t&, const test_regex_search_tag&) boost::regex_tW re; if(boost::regcompW(&re, expression.c_str(), posix_options) != 0) { - BOOST_REGEX_TEST_ERROR("Expression : \"" << expression.c_str() << "\" did not compile with the POSIX C API.", wchar_t); + BOOST_REGEX_TEST_ERROR("Expression : \"" << to_narrow_string(expression.c_str()) << "\" did not compile with the POSIX C API.", wchar_t); return; } // try and find the first occurrence: @@ -183,7 +188,7 @@ void test_deprecated(const wchar_t&, const test_regex_search_tag&) { if(results[0] >= 0) { - BOOST_REGEX_TEST_ERROR("Expression : \"" << expression.c_str() << "\" was not found with the POSIX C API.", wchar_t); + BOOST_REGEX_TEST_ERROR("Expression : \"" << to_narrow_string(expression.c_str()) << "\" was not found with the POSIX C API.", wchar_t); } } // clean up whatever: @@ -248,7 +253,7 @@ void test_deprecated(const wchar_t&, const test_invalid_regex_tag&) if(code == 0) { boost::regfreeW(&re); - BOOST_REGEX_TEST_ERROR("Expression : \"" << expression.c_str() << "\" unexpectedly compiled with the POSIX C API.", wchar_t); + BOOST_REGEX_TEST_ERROR("Expression : \"" << to_narrow_string(expression.c_str()) << "\" unexpectedly compiled with the POSIX C API.", wchar_t); } else { diff --git a/test/test_consolidated.cpp b/test/test_consolidated.cpp index 188033f7..7c1aa699 100644 --- a/test/test_consolidated.cpp +++ b/test/test_consolidated.cpp @@ -10,20 +10,13 @@ */ -#include #include -#include -#include #include -#include #include #include #include #include #include #include -#include -#include #include #include -#include