diff --git a/include/boost/regex/concepts.hpp b/include/boost/regex/concepts.hpp index 2eafac1b..617e5a71 100644 --- a/include/boost/regex/concepts.hpp +++ b/include/boost/regex/concepts.hpp @@ -24,7 +24,7 @@ #include #include #include -#ifndef BOOST_TEST_TR1_REGEX +#if !defined(BOOST_TEST_TR1_REGEX) && !defined(BOOST_REGEX_TEST_MODULE) #include #endif #include @@ -37,6 +37,16 @@ #define RW_NS std #endif + + // + // alter this to std::tr1, to test a std implementation: + // +#ifndef BOOST_TEST_TR1_REGEX +namespace global_regex_namespace = ::boost; +#else +namespace global_regex_namespace = ::std::tr1; +#endif + namespace boost{ // @@ -178,15 +188,6 @@ private: regex_traits_architype& operator=(const regex_traits_architype&){ return *this; } }; -// -// alter this to std::tr1, to test a std implementation: -// -#ifndef BOOST_TEST_TR1_REGEX -namespace global_regex_namespace = ::boost; -#else -namespace global_regex_namespace = ::std::tr1; -#endif - template struct BitmaskConcept { @@ -273,7 +274,7 @@ template struct regex_traits_computer; template -struct regex_traits_computer< global_regex_namespace::basic_regex > +struct regex_traits_computer< ::boost::basic_regex > { typedef traits type; }; diff --git a/include/boost/regex/config.hpp b/include/boost/regex/config.hpp index bed485fa..e5f41cf3 100644 --- a/include/boost/regex/config.hpp +++ b/include/boost/regex/config.hpp @@ -33,6 +33,13 @@ #endif #endif +#ifndef BOOST_REGEX_MODULE_EXPORT +#define BOOST_REGEX_MODULE_EXPORT +#define BOOST_REGEX_STATIC_CONST static const +#else +#define BOOST_REGEX_STATIC_CONST inline constexpr +#endif + /* * Borland C++ Fix/error check * this has to go *before* we include any std lib headers: @@ -51,7 +58,9 @@ *************************************************************************/ #ifdef BOOST_REGEX_STANDALONE +#ifndef BOOST_REGEX_AS_MODULE #include +#endif # define BOOST_REGEX_ASSERT(x) assert(x) #else #include diff --git a/include/boost/regex/v5/basic_regex.hpp b/include/boost/regex/v5/basic_regex.hpp index 5c73775f..aa984c5f 100644 --- a/include/boost/regex/v5/basic_regex.hpp +++ b/include/boost/regex/v5/basic_regex.hpp @@ -19,7 +19,9 @@ #ifndef BOOST_REGEX_V5_BASIC_REGEX_HPP #define BOOST_REGEX_V5_BASIC_REGEX_HPP +#ifndef BOOST_REGEX_AS_MODULE #include +#endif namespace boost{ #ifdef BOOST_REGEX_MSVC @@ -58,7 +60,12 @@ void bubble_down_one(I first, I last) } } -static const int hash_value_mask = 1 << (std::numeric_limits::digits - 1); +#ifndef BOOST_REGEX_AS_MODULE +static +#else +inline +#endif +const int hash_value_mask = 1 << (std::numeric_limits::digits - 1); template inline int hash_value_from_capture_name(Iterator i, Iterator j) @@ -306,7 +313,7 @@ public: // represents the compiled // regular expression: // - +BOOST_REGEX_MODULE_EXPORT #ifdef BOOST_REGEX_NO_FWD template > #else @@ -660,13 +667,13 @@ typename basic_regex::locale_type basic_regex::im // // non-members: // -template +BOOST_REGEX_MODULE_EXPORT template void swap(basic_regex& e1, basic_regex& e2) { e1.swap(e2); } -template +BOOST_REGEX_MODULE_EXPORT template std::basic_ostream& operator << (std::basic_ostream& os, const basic_regex& e) diff --git a/include/boost/regex/v5/basic_regex_creator.hpp b/include/boost/regex/v5/basic_regex_creator.hpp index bb76c7c1..03c419d9 100644 --- a/include/boost/regex/v5/basic_regex_creator.hpp +++ b/include/boost/regex/v5/basic_regex_creator.hpp @@ -28,7 +28,9 @@ #endif #endif +#ifndef BOOST_REGEX_AS_MODULE #include +#endif namespace boost{ @@ -217,8 +219,10 @@ public: m_icase = static_cast(f & regbase::icase); } } - re_syntax_base* append_state(syntax_element_type t, std::size_t s = sizeof(re_syntax_base)); - re_syntax_base* insert_state(std::ptrdiff_t pos, syntax_element_type t, std::size_t s = sizeof(re_syntax_base)); + re_syntax_base* append_state(syntax_element_type t, std::size_t s); + re_syntax_base* append_state(syntax_element_type t) { return append_state(t, sizeof(re_syntax_base)); } + re_syntax_base* insert_state(std::ptrdiff_t pos, syntax_element_type t, std::size_t s); + re_syntax_base* insert_state(std::ptrdiff_t pos, syntax_element_type t) { return insert_state(pos, t, sizeof(re_syntax_base)); } re_literal* append_literal(charT c); re_syntax_base* append_set(const basic_char_set& char_set); re_syntax_base* append_set(const basic_char_set& char_set, std::integral_constant*); diff --git a/include/boost/regex/v5/c_regex_traits.hpp b/include/boost/regex/v5/c_regex_traits.hpp index 9de34632..1488379b 100644 --- a/include/boost/regex/v5/c_regex_traits.hpp +++ b/include/boost/regex/v5/c_regex_traits.hpp @@ -21,7 +21,9 @@ #include #include +#ifndef BOOST_REGEX_AS_MODULE #include +#endif namespace boost{ @@ -49,10 +51,10 @@ namespace boost{ } -template +BOOST_REGEX_MODULE_EXPORT template struct c_regex_traits; -template<> +BOOST_REGEX_MODULE_EXPORT template<> struct c_regex_traits { c_regex_traits(){} @@ -97,7 +99,7 @@ private: }; #ifndef BOOST_NO_WREGEX -template<> +BOOST_REGEX_MODULE_EXPORT template<> struct c_regex_traits { c_regex_traits(){} diff --git a/include/boost/regex/v5/cpp_regex_traits.hpp b/include/boost/regex/v5/cpp_regex_traits.hpp index 26b6f503..a79f6628 100644 --- a/include/boost/regex/v5/cpp_regex_traits.hpp +++ b/include/boost/regex/v5/cpp_regex_traits.hpp @@ -20,22 +20,25 @@ #define BOOST_CPP_REGEX_TRAITS_HPP_INCLUDED #include + +#ifndef BOOST_REGEX_AS_MODULE #include #include #include +#include +#include +#include +#ifdef BOOST_HAS_THREADS +#include +#endif +#endif #include #include -#ifdef BOOST_HAS_THREADS -#include -#endif #include #include -#include -#include -#include #ifdef BOOST_REGEX_MSVC #pragma warning(push) @@ -47,7 +50,7 @@ namespace boost{ // // forward declaration is needed by some compilers: // -template +BOOST_REGEX_MODULE_EXPORT template class cpp_regex_traits; namespace BOOST_REGEX_DETAIL_NS{ @@ -731,7 +734,7 @@ inline std::shared_ptr > create_cpp } // BOOST_REGEX_DETAIL_NS -template +BOOST_REGEX_MODULE_EXPORT template class cpp_regex_traits { private: diff --git a/include/boost/regex/v5/cregex.hpp b/include/boost/regex/v5/cregex.hpp index a6571052..13e99b90 100644 --- a/include/boost/regex/v5/cregex.hpp +++ b/include/boost/regex/v5/cregex.hpp @@ -39,11 +39,13 @@ #endif #endif +#ifndef BOOST_REGEX_AS_MODULE #ifdef __cplusplus #include #else #include #endif +#endif /* include these defs only for POSIX compatablity */ #ifdef __cplusplus diff --git a/include/boost/regex/v5/error_type.hpp b/include/boost/regex/v5/error_type.hpp index afcc71e3..a3161d28 100644 --- a/include/boost/regex/v5/error_type.hpp +++ b/include/boost/regex/v5/error_type.hpp @@ -26,7 +26,7 @@ namespace boost{ #ifdef __cplusplus namespace regex_constants{ -enum error_type{ +BOOST_REGEX_MODULE_EXPORT enum error_type{ error_ok = 0, /* not used */ error_no_match = 1, /* not used */ diff --git a/include/boost/regex/v5/icu.hpp b/include/boost/regex/v5/icu.hpp index f172553d..5dae468f 100644 --- a/include/boost/regex/v5/icu.hpp +++ b/include/boost/regex/v5/icu.hpp @@ -19,11 +19,13 @@ #ifndef BOOST_REGEX_ICU_V5_HPP #define BOOST_REGEX_ICU_V5_HPP +#ifndef BOOST_REGEX_AS_MODULE #include #include #include #include #include +#endif #include #include @@ -835,7 +837,7 @@ bool do_regex_match(BidiIterator first, BidiIterator last, } } // namespace BOOST_REGEX_DETAIL_NS -template +BOOST_REGEX_MODULE_EXPORT template inline bool u32regex_match(BidiIterator first, BidiIterator last, match_results& m, const u32regex& e, @@ -843,7 +845,7 @@ inline bool u32regex_match(BidiIterator first, BidiIterator last, { return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast const*>(0)); } -inline bool u32regex_match(const UChar* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const UChar* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -851,7 +853,7 @@ inline bool u32regex_match(const UChar* p, return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast const*>(0)); } #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) -inline bool u32regex_match(const wchar_t* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const wchar_t* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -859,21 +861,21 @@ inline bool u32regex_match(const wchar_t* p, return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast const*>(0)); } #endif -inline bool u32regex_match(const char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const char* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) { return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast const*>(0)); } -inline bool u32regex_match(const unsigned char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const unsigned char* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) { return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast const*>(0)); } -inline bool u32regex_match(const std::string& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const std::string& s, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -881,7 +883,7 @@ inline bool u32regex_match(const std::string& s, return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast const*>(0)); } #ifndef BOOST_NO_STD_WSTRING -inline bool u32regex_match(const std::wstring& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const std::wstring& s, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -889,7 +891,7 @@ inline bool u32regex_match(const std::wstring& s, return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast const*>(0)); } #endif -inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -899,7 +901,7 @@ inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s, // // regex_match overloads that do not return what matched: // -template +BOOST_REGEX_MODULE_EXPORT template inline bool u32regex_match(BidiIterator first, BidiIterator last, const u32regex& e, match_flag_type flags = match_default) @@ -907,7 +909,7 @@ inline bool u32regex_match(BidiIterator first, BidiIterator last, match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_match(first, last, m, e, flags, static_cast const*>(0)); } -inline bool u32regex_match(const UChar* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const UChar* p, const u32regex& e, match_flag_type flags = match_default) { @@ -915,7 +917,7 @@ inline bool u32regex_match(const UChar* p, return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast const*>(0)); } #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) -inline bool u32regex_match(const wchar_t* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const wchar_t* p, const u32regex& e, match_flag_type flags = match_default) { @@ -923,21 +925,21 @@ inline bool u32regex_match(const wchar_t* p, return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::wcslen(p), m, e, flags, static_cast const*>(0)); } #endif -inline bool u32regex_match(const char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const char* p, const u32regex& e, match_flag_type flags = match_default) { match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen(p), m, e, flags, static_cast const*>(0)); } -inline bool u32regex_match(const unsigned char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const unsigned char* p, const u32regex& e, match_flag_type flags = match_default) { match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+std::strlen((const char*)p), m, e, flags, static_cast const*>(0)); } -inline bool u32regex_match(const std::string& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const std::string& s, const u32regex& e, match_flag_type flags = match_default) { @@ -945,7 +947,7 @@ inline bool u32regex_match(const std::string& s, return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast const*>(0)); } #ifndef BOOST_NO_STD_WSTRING -inline bool u32regex_match(const std::wstring& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const std::wstring& s, const u32regex& e, match_flag_type flags = match_default) { @@ -953,7 +955,7 @@ inline bool u32regex_match(const std::wstring& s, return BOOST_REGEX_DETAIL_NS::do_regex_match(s.begin(), s.end(), m, e, flags, static_cast const*>(0)); } #endif -inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_match(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, match_flag_type flags = match_default) { @@ -1011,7 +1013,7 @@ bool do_regex_search(BidiIterator first, BidiIterator last, } } -template +BOOST_REGEX_MODULE_EXPORT template inline bool u32regex_search(BidiIterator first, BidiIterator last, match_results& m, const u32regex& e, @@ -1019,7 +1021,7 @@ inline bool u32regex_search(BidiIterator first, BidiIterator last, { return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast const*>(0)); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool u32regex_search(BidiIterator first, BidiIterator last, match_results& m, const u32regex& e, @@ -1028,7 +1030,7 @@ inline bool u32regex_search(BidiIterator first, BidiIterator last, { return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, base, static_cast const*>(0)); } -inline bool u32regex_search(const UChar* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const UChar* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -1036,7 +1038,7 @@ inline bool u32regex_search(const UChar* p, return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast const*>(0)); } #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) -inline bool u32regex_search(const wchar_t* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const wchar_t* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -1044,21 +1046,21 @@ inline bool u32regex_search(const wchar_t* p, return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast const*>(0)); } #endif -inline bool u32regex_search(const char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const char* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) { return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast const*>(0)); } -inline bool u32regex_search(const unsigned char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const unsigned char* p, match_results& m, const u32regex& e, match_flag_type flags = match_default) { return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast const*>(0)); } -inline bool u32regex_search(const std::string& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const std::string& s, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -1066,7 +1068,7 @@ inline bool u32regex_search(const std::string& s, return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast const*>(0)); } #ifndef BOOST_NO_STD_WSTRING -inline bool u32regex_search(const std::wstring& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const std::wstring& s, match_results& m, const u32regex& e, match_flag_type flags = match_default) @@ -1074,14 +1076,14 @@ inline bool u32regex_search(const std::wstring& s, return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast const*>(0)); } #endif -inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s, match_results& m, const u32regex& e, match_flag_type flags = match_default) { return BOOST_REGEX_DETAIL_NS::do_regex_search(s.getBuffer(), s.getBuffer() + s.length(), m, e, flags, s.getBuffer(), static_cast const*>(0)); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool u32regex_search(BidiIterator first, BidiIterator last, const u32regex& e, match_flag_type flags = match_default) @@ -1089,7 +1091,7 @@ inline bool u32regex_search(BidiIterator first, BidiIterator last, match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_search(first, last, m, e, flags, first, static_cast const*>(0)); } -inline bool u32regex_search(const UChar* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const UChar* p, const u32regex& e, match_flag_type flags = match_default) { @@ -1097,7 +1099,7 @@ inline bool u32regex_search(const UChar* p, return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast const*>(0)); } #if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) -inline bool u32regex_search(const wchar_t* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const wchar_t* p, const u32regex& e, match_flag_type flags = match_default) { @@ -1105,21 +1107,21 @@ inline bool u32regex_search(const wchar_t* p, return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::wcslen(p), m, e, flags, p, static_cast const*>(0)); } #endif -inline bool u32regex_search(const char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const char* p, const u32regex& e, match_flag_type flags = match_default) { match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen(p), m, e, flags, p, static_cast const*>(0)); } -inline bool u32regex_search(const unsigned char* p, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const unsigned char* p, const u32regex& e, match_flag_type flags = match_default) { match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+std::strlen((const char*)p), m, e, flags, p, static_cast const*>(0)); } -inline bool u32regex_search(const std::string& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const std::string& s, const u32regex& e, match_flag_type flags = match_default) { @@ -1127,7 +1129,7 @@ inline bool u32regex_search(const std::string& s, return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast const*>(0)); } #ifndef BOOST_NO_STD_WSTRING -inline bool u32regex_search(const std::wstring& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const std::wstring& s, const u32regex& e, match_flag_type flags = match_default) { @@ -1135,7 +1137,7 @@ inline bool u32regex_search(const std::wstring& s, return BOOST_REGEX_DETAIL_NS::do_regex_search(s.begin(), s.end(), m, e, flags, s.begin(), static_cast const*>(0)); } #endif -inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s, +BOOST_REGEX_MODULE_EXPORT inline bool u32regex_search(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, match_flag_type flags = match_default) { @@ -1258,7 +1260,7 @@ inline BaseIterator extract_output_base(const utf16_output_iterator +BOOST_REGEX_MODULE_EXPORT template inline OutputIterator u32regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last, @@ -1277,7 +1279,7 @@ inline OutputIterator u32regex_replace(OutputIterator out, ); } -template +BOOST_REGEX_MODULE_EXPORT template inline OutputIterator u32regex_replace(OutputIterator out, Iterator first, Iterator last, @@ -1296,7 +1298,7 @@ inline OutputIterator u32regex_replace(OutputIterator out, ); } -template +BOOST_REGEX_MODULE_EXPORT template inline OutputIterator u32regex_replace(OutputIterator out, Iterator first, Iterator last, @@ -1315,7 +1317,7 @@ inline OutputIterator u32regex_replace(OutputIterator out, ); } -template +BOOST_REGEX_MODULE_EXPORT template std::basic_string u32regex_replace(const std::basic_string& s, const u32regex& e, const charT* fmt, @@ -1327,7 +1329,7 @@ std::basic_string u32regex_replace(const std::basic_string& s, return result; } -template +BOOST_REGEX_MODULE_EXPORT template std::basic_string u32regex_replace(const std::basic_string& s, const u32regex& e, const std::basic_string& fmt, diff --git a/include/boost/regex/v5/iterator_category.hpp b/include/boost/regex/v5/iterator_category.hpp index 9bd74578..bb6f638e 100644 --- a/include/boost/regex/v5/iterator_category.hpp +++ b/include/boost/regex/v5/iterator_category.hpp @@ -21,8 +21,10 @@ #ifndef BOOST_REGEX_ITERATOR_CATEGORY_HPP #define BOOST_REGEX_ITERATOR_CATEGORY_HPP +#ifndef BOOST_REGEX_AS_MODULE #include #include +#endif namespace boost{ namespace detail{ diff --git a/include/boost/regex/v5/match_flags.hpp b/include/boost/regex/v5/match_flags.hpp index 6ff236b0..7c4ee5f5 100644 --- a/include/boost/regex/v5/match_flags.hpp +++ b/include/boost/regex/v5/match_flags.hpp @@ -35,7 +35,7 @@ namespace boost{ #endif #endif -typedef enum _match_flags +BOOST_REGEX_MODULE_EXPORT typedef enum _match_flags { match_default = 0, match_not_bol = 1, /* first is not start of line */ @@ -89,22 +89,22 @@ typedef enum _match_flags } match_flags; -typedef match_flags match_flag_type; +BOOST_REGEX_MODULE_EXPORT typedef match_flags match_flag_type; #ifdef __cplusplus -inline match_flags operator&(match_flags m1, match_flags m2) +BOOST_REGEX_MODULE_EXPORT inline match_flags operator&(match_flags m1, match_flags m2) { return static_cast(static_cast(m1) & static_cast(m2)); } -inline match_flags operator|(match_flags m1, match_flags m2) +BOOST_REGEX_MODULE_EXPORT inline match_flags operator|(match_flags m1, match_flags m2) { return static_cast(static_cast(m1) | static_cast(m2)); } -inline match_flags operator^(match_flags m1, match_flags m2) +BOOST_REGEX_MODULE_EXPORT inline match_flags operator^(match_flags m1, match_flags m2) { return static_cast(static_cast(m1) ^ static_cast(m2)); } -inline match_flags operator~(match_flags m1) +BOOST_REGEX_MODULE_EXPORT inline match_flags operator~(match_flags m1) { return static_cast(~static_cast(m1)); } -inline match_flags& operator&=(match_flags& m1, match_flags m2) +BOOST_REGEX_MODULE_EXPORT inline match_flags& operator&=(match_flags& m1, match_flags m2) { m1 = m1&m2; return m1; } -inline match_flags& operator|=(match_flags& m1, match_flags m2) +BOOST_REGEX_MODULE_EXPORT inline match_flags& operator|=(match_flags& m1, match_flags m2) { m1 = m1|m2; return m1; } -inline match_flags& operator^=(match_flags& m1, match_flags m2) +BOOST_REGEX_MODULE_EXPORT inline match_flags& operator^=(match_flags& m1, match_flags m2) { m1 = m1^m2; return m1; } #endif @@ -113,36 +113,36 @@ inline match_flags& operator^=(match_flags& m1, match_flags m2) /* * import names into boost for backwards compatibility: */ -using regex_constants::match_flag_type; -using regex_constants::match_default; -using regex_constants::match_not_bol; -using regex_constants::match_not_eol; -using regex_constants::match_not_bob; -using regex_constants::match_not_eob; -using regex_constants::match_not_bow; -using regex_constants::match_not_eow; -using regex_constants::match_not_dot_newline; -using regex_constants::match_not_dot_null; -using regex_constants::match_prev_avail; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_flag_type; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_default; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_bol; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_eol; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_bob; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_eob; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_bow; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_eow; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_dot_newline; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_dot_null; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_prev_avail; /* using regex_constants::match_init; */ -using regex_constants::match_any; -using regex_constants::match_not_null; -using regex_constants::match_continuous; -using regex_constants::match_partial; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_any; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_not_null; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_continuous; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_partial; /*using regex_constants::match_stop; */ -using regex_constants::match_all; -using regex_constants::match_perl; -using regex_constants::match_posix; -using regex_constants::match_nosubs; -using regex_constants::match_extra; -using regex_constants::match_single_line; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_all; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_perl; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_posix; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_nosubs; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_extra; +BOOST_REGEX_MODULE_EXPORT using regex_constants::match_single_line; /*using regex_constants::match_max; */ -using regex_constants::format_all; -using regex_constants::format_sed; -using regex_constants::format_perl; -using regex_constants::format_default; -using regex_constants::format_no_copy; -using regex_constants::format_first_only; +BOOST_REGEX_MODULE_EXPORT using regex_constants::format_all; +BOOST_REGEX_MODULE_EXPORT using regex_constants::format_sed; +BOOST_REGEX_MODULE_EXPORT using regex_constants::format_perl; +BOOST_REGEX_MODULE_EXPORT using regex_constants::format_default; +BOOST_REGEX_MODULE_EXPORT using regex_constants::format_no_copy; +BOOST_REGEX_MODULE_EXPORT using regex_constants::format_first_only; /*using regex_constants::format_is_if;*/ #ifdef BOOST_REGEX_MSVC diff --git a/include/boost/regex/v5/match_results.hpp b/include/boost/regex/v5/match_results.hpp index 3f9cd012..8d2baccc 100644 --- a/include/boost/regex/v5/match_results.hpp +++ b/include/boost/regex/v5/match_results.hpp @@ -37,7 +37,7 @@ class named_subexpressions; } -template +BOOST_REGEX_MODULE_EXPORT template class match_results { private: @@ -643,13 +643,13 @@ void match_results::maybe_assign(const match_results +BOOST_REGEX_MODULE_EXPORT template void swap(match_results& a, match_results& b) { a.swap(b); } -template +BOOST_REGEX_MODULE_EXPORT template std::basic_ostream& operator << (std::basic_ostream& os, const match_results& s) diff --git a/include/boost/regex/v5/mem_block_cache.hpp b/include/boost/regex/v5/mem_block_cache.hpp index 3e1216d0..87e233bc 100644 --- a/include/boost/regex/v5/mem_block_cache.hpp +++ b/include/boost/regex/v5/mem_block_cache.hpp @@ -18,6 +18,7 @@ #ifndef BOOST_REGEX_V5_MEM_BLOCK_CACHE_HPP #define BOOST_REGEX_V5_MEM_BLOCK_CACHE_HPP +#ifndef BOOST_REGEX_AS_MODULE #include #ifdef BOOST_HAS_THREADS #include @@ -30,6 +31,7 @@ #define BOOST_REGEX_ATOMIC_POINTER std::atomic #endif #endif +#endif namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ diff --git a/include/boost/regex/v5/object_cache.hpp b/include/boost/regex/v5/object_cache.hpp index 6ebef9b3..c9aede14 100644 --- a/include/boost/regex/v5/object_cache.hpp +++ b/include/boost/regex/v5/object_cache.hpp @@ -20,6 +20,7 @@ #define BOOST_REGEX_OBJECT_CACHE_HPP #include +#ifndef BOOST_REGEX_AS_MODULE #include #include #include @@ -28,6 +29,7 @@ #ifdef BOOST_HAS_THREADS #include #endif +#endif namespace boost{ diff --git a/include/boost/regex/v5/pattern_except.hpp b/include/boost/regex/v5/pattern_except.hpp index 3fbdca0a..5de5bb68 100644 --- a/include/boost/regex/v5/pattern_except.hpp +++ b/include/boost/regex/v5/pattern_except.hpp @@ -23,8 +23,10 @@ #include #endif +#ifndef BOOST_REGEX_AS_MODULE #include #include +#endif #include #include @@ -37,7 +39,7 @@ namespace boost{ #pragma warning(disable : 26812 4459) #endif #endif -class regex_error : public std::runtime_error +BOOST_REGEX_MODULE_EXPORT class regex_error : public std::runtime_error { public: explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0) @@ -72,8 +74,8 @@ private: std::ptrdiff_t m_position; }; -typedef regex_error bad_pattern; -typedef regex_error bad_expression; +BOOST_REGEX_MODULE_EXPORT typedef regex_error bad_pattern; +BOOST_REGEX_MODULE_EXPORT typedef regex_error bad_expression; namespace BOOST_REGEX_DETAIL_NS{ diff --git a/include/boost/regex/v5/regbase.hpp b/include/boost/regex/v5/regbase.hpp index 5cefb36b..b9c32b40 100644 --- a/include/boost/regex/v5/regbase.hpp +++ b/include/boost/regex/v5/regbase.hpp @@ -112,7 +112,7 @@ public: // namespace regex_constants{ - enum flag_type_ + BOOST_REGEX_MODULE_EXPORT enum flag_type_ { no_except = ::boost::regbase::no_except, @@ -148,7 +148,7 @@ namespace regex_constants{ JavaScript = normal, JScript = normal }; - typedef ::boost::regbase::flag_type syntax_option_type; + BOOST_REGEX_MODULE_EXPORT typedef ::boost::regbase::flag_type syntax_option_type; } // namespace regex_constants diff --git a/include/boost/regex/v5/regex.hpp b/include/boost/regex/v5/regex.hpp index eb6dc728..bd5244ee 100644 --- a/include/boost/regex/v5/regex.hpp +++ b/include/boost/regex/v5/regex.hpp @@ -46,17 +46,17 @@ namespace boost{ #ifdef BOOST_REGEX_NO_FWD -typedef basic_regex > regex; +BOOST_REGEX_MODULE_EXPORT typedef basic_regex > regex; #ifndef BOOST_NO_WREGEX -typedef basic_regex > wregex; +BOOST_REGEX_MODULE_EXPORT typedef basic_regex > wregex; #endif #endif -typedef match_results cmatch; -typedef match_results smatch; +BOOST_REGEX_MODULE_EXPORT typedef match_results cmatch; +BOOST_REGEX_MODULE_EXPORT typedef match_results smatch; #ifndef BOOST_NO_WREGEX -typedef match_results wcmatch; -typedef match_results wsmatch; +BOOST_REGEX_MODULE_EXPORT typedef match_results wcmatch; +BOOST_REGEX_MODULE_EXPORT typedef match_results wsmatch; #endif } // namespace boost diff --git a/include/boost/regex/v5/regex_format.hpp b/include/boost/regex/v5/regex_format.hpp index 4c82d185..320ef8f3 100644 --- a/include/boost/regex/v5/regex_format.hpp +++ b/include/boost/regex/v5/regex_format.hpp @@ -21,15 +21,17 @@ #ifndef BOOST_REGEX_FORMAT_HPP #define BOOST_REGEX_FORMAT_HPP +#ifndef BOOST_REGEX_AS_MODULE #include #include +#endif namespace boost{ // // Forward declaration: // - template >::allocator_type > +BOOST_REGEX_MODULE_EXPORT template >::allocator_type > class match_results; namespace BOOST_REGEX_DETAIL_NS{ @@ -1095,7 +1097,7 @@ struct compute_functor_type } // namespace BOOST_REGEX_DETAIL_NS -template +BOOST_REGEX_MODULE_EXPORT template inline OutputIterator regex_format(OutputIterator out, const match_results& m, Functor fmt, @@ -1105,7 +1107,7 @@ inline OutputIterator regex_format(OutputIterator out, return m.format(out, fmt, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::char_type> regex_format(const match_results& m, Functor fmt, match_flag_type flags = format_all) diff --git a/include/boost/regex/v5/regex_fwd.hpp b/include/boost/regex/v5/regex_fwd.hpp index 3076b069..4f202a41 100644 --- a/include/boost/regex/v5/regex_fwd.hpp +++ b/include/boost/regex/v5/regex_fwd.hpp @@ -36,30 +36,30 @@ namespace boost{ -template +BOOST_REGEX_MODULE_EXPORT template class cpp_regex_traits; -template +BOOST_REGEX_MODULE_EXPORT template struct c_regex_traits; -template +BOOST_REGEX_MODULE_EXPORT template class w32_regex_traits; #ifdef BOOST_REGEX_USE_WIN32_LOCALE -template > +BOOST_REGEX_MODULE_EXPORT template > struct regex_traits; #elif defined(BOOST_REGEX_USE_CPP_LOCALE) -template > +BOOST_REGEX_MODULE_EXPORT template > struct regex_traits; #else -template > +BOOST_REGEX_MODULE_EXPORT template > struct regex_traits; #endif -template > +BOOST_REGEX_MODULE_EXPORT template > class basic_regex; -typedef basic_regex > regex; +BOOST_REGEX_MODULE_EXPORT typedef basic_regex > regex; #ifndef BOOST_NO_WREGEX -typedef basic_regex > wregex; +BOOST_REGEX_MODULE_EXPORT typedef basic_regex > wregex; #endif } // namespace boost diff --git a/include/boost/regex/v5/regex_grep.hpp b/include/boost/regex/v5/regex_grep.hpp index 6cd625d6..0de27cc4 100644 --- a/include/boost/regex/v5/regex_grep.hpp +++ b/include/boost/regex/v5/regex_grep.hpp @@ -26,7 +26,7 @@ namespace boost{ // regex_grep: // find all non-overlapping matches within the sequence first last: // -template +BOOST_REGEX_MODULE_EXPORT template inline unsigned int regex_grep(Predicate foo, BidiIterator first, BidiIterator last, @@ -76,7 +76,7 @@ inline unsigned int regex_grep(Predicate foo, // // regex_grep convenience interfaces: // -template +BOOST_REGEX_MODULE_EXPORT template inline unsigned int regex_grep(Predicate foo, const charT* str, const basic_regex& e, match_flag_type flags = match_default) @@ -84,7 +84,7 @@ inline unsigned int regex_grep(Predicate foo, const charT* str, return regex_grep(foo, str, str + traits::length(str), e, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline unsigned int regex_grep(Predicate foo, const std::basic_string& s, const basic_regex& e, match_flag_type flags = match_default) diff --git a/include/boost/regex/v5/regex_iterator.hpp b/include/boost/regex/v5/regex_iterator.hpp index b2e9d2ce..66e122ca 100644 --- a/include/boost/regex/v5/regex_iterator.hpp +++ b/include/boost/regex/v5/regex_iterator.hpp @@ -19,7 +19,9 @@ #ifndef BOOST_REGEX_V5_REGEX_ITERATOR_HPP #define BOOST_REGEX_V5_REGEX_ITERATOR_HPP +#ifndef BOOST_REGEX_AS_MODULE #include +#endif namespace boost{ @@ -72,7 +74,7 @@ private: regex_iterator_implementation& operator=(const regex_iterator_implementation&); }; -template ::value_type, class traits = regex_traits > class regex_iterator @@ -148,20 +150,20 @@ private: } }; -typedef regex_iterator cregex_iterator; -typedef regex_iterator sregex_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_iterator cregex_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_iterator sregex_iterator; #ifndef BOOST_NO_WREGEX -typedef regex_iterator wcregex_iterator; -typedef regex_iterator wsregex_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_iterator wcregex_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_iterator wsregex_iterator; #endif // make_regex_iterator: -template +BOOST_REGEX_MODULE_EXPORT template inline regex_iterator make_regex_iterator(const charT* p, const basic_regex& e, regex_constants::match_flag_type m = regex_constants::match_default) { return regex_iterator(p, p+traits::length(p), e, m); } -template +BOOST_REGEX_MODULE_EXPORT template inline regex_iterator::const_iterator, charT, traits> make_regex_iterator(const std::basic_string& p, const basic_regex& e, regex_constants::match_flag_type m = regex_constants::match_default) { return regex_iterator::const_iterator, charT, traits>(p.begin(), p.end(), e, m); diff --git a/include/boost/regex/v5/regex_match.hpp b/include/boost/regex/v5/regex_match.hpp index 21753576..c95c3a59 100644 --- a/include/boost/regex/v5/regex_match.hpp +++ b/include/boost/regex/v5/regex_match.hpp @@ -29,7 +29,7 @@ namespace boost{ // returns true if the specified regular expression matches // the whole of the input. Fills in what matched in m. // -template +BOOST_REGEX_MODULE_EXPORT template bool regex_match(BidiIterator first, BidiIterator last, match_results& m, const basic_regex& e, @@ -38,7 +38,7 @@ bool regex_match(BidiIterator first, BidiIterator last, BOOST_REGEX_DETAIL_NS::perl_matcher matcher(first, last, m, e, flags, first); return matcher.match(); } -template +BOOST_REGEX_MODULE_EXPORT template bool regex_match(iterator first, iterator last, const basic_regex& e, match_flag_type flags = match_default) @@ -49,7 +49,7 @@ bool regex_match(iterator first, iterator last, // // query_match convenience interfaces: // -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_match(const charT* str, match_results& m, const basic_regex& e, @@ -58,7 +58,7 @@ inline bool regex_match(const charT* str, return regex_match(str, str + traits::length(str), m, e, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_match(const std::basic_string& s, match_results::const_iterator, Allocator>& m, const basic_regex& e, @@ -66,7 +66,7 @@ inline bool regex_match(const std::basic_string& s, { return regex_match(s.begin(), s.end(), m, e, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_match(const charT* str, const basic_regex& e, match_flag_type flags = match_default) @@ -75,7 +75,7 @@ inline bool regex_match(const charT* str, return regex_match(str, str + traits::length(str), m, e, flags | regex_constants::match_any); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_match(const std::basic_string& s, const basic_regex& e, match_flag_type flags = match_default) diff --git a/include/boost/regex/v5/regex_merge.hpp b/include/boost/regex/v5/regex_merge.hpp index a5103c53..ba9ac21c 100644 --- a/include/boost/regex/v5/regex_merge.hpp +++ b/include/boost/regex/v5/regex_merge.hpp @@ -24,7 +24,7 @@ namespace boost{ -template +BOOST_REGEX_MODULE_EXPORT template inline OutputIterator regex_merge(OutputIterator out, Iterator first, Iterator last, @@ -35,7 +35,7 @@ inline OutputIterator regex_merge(OutputIterator out, return regex_replace(out, first, last, e, fmt, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline OutputIterator regex_merge(OutputIterator out, Iterator first, Iterator last, @@ -46,7 +46,7 @@ inline OutputIterator regex_merge(OutputIterator out, return regex_merge(out, first, last, e, fmt.c_str(), flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string regex_merge(const std::basic_string& s, const basic_regex& e, const charT* fmt, @@ -55,7 +55,7 @@ inline std::basic_string regex_merge(const std::basic_string& s, return regex_replace(s, e, fmt, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string regex_merge(const std::basic_string& s, const basic_regex& e, const std::basic_string& fmt, diff --git a/include/boost/regex/v5/regex_raw_buffer.hpp b/include/boost/regex/v5/regex_raw_buffer.hpp index 443c57a2..c074fa5a 100644 --- a/include/boost/regex/v5/regex_raw_buffer.hpp +++ b/include/boost/regex/v5/regex_raw_buffer.hpp @@ -25,8 +25,10 @@ #include #endif +#ifndef BOOST_REGEX_AS_MODULE #include #include +#endif namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ diff --git a/include/boost/regex/v5/regex_replace.hpp b/include/boost/regex/v5/regex_replace.hpp index 75f8894f..b66b024f 100644 --- a/include/boost/regex/v5/regex_replace.hpp +++ b/include/boost/regex/v5/regex_replace.hpp @@ -24,7 +24,7 @@ namespace boost{ -template +BOOST_REGEX_MODULE_EXPORT template OutputIterator regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last, @@ -58,7 +58,7 @@ OutputIterator regex_replace(OutputIterator out, return out; } -template +BOOST_REGEX_MODULE_EXPORT template std::basic_string regex_replace(const std::basic_string& s, const basic_regex& e, Formatter fmt, diff --git a/include/boost/regex/v5/regex_search.hpp b/include/boost/regex/v5/regex_search.hpp index d0addb19..e4a8cf0a 100644 --- a/include/boost/regex/v5/regex_search.hpp +++ b/include/boost/regex/v5/regex_search.hpp @@ -22,7 +22,7 @@ namespace boost{ -template +BOOST_REGEX_MODULE_EXPORT template bool regex_search(BidiIterator first, BidiIterator last, match_results& m, const basic_regex& e, @@ -31,7 +31,7 @@ bool regex_search(BidiIterator first, BidiIterator last, return regex_search(first, last, m, e, flags, first); } -template +BOOST_REGEX_MODULE_EXPORT template bool regex_search(BidiIterator first, BidiIterator last, match_results& m, const basic_regex& e, @@ -48,7 +48,7 @@ bool regex_search(BidiIterator first, BidiIterator last, // // regex_search convenience interfaces: // -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_search(const charT* str, match_results& m, const basic_regex& e, @@ -57,7 +57,7 @@ inline bool regex_search(const charT* str, return regex_search(str, str + traits::length(str), m, e, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_search(const std::basic_string& s, match_results::const_iterator, Allocator>& m, const basic_regex& e, @@ -66,7 +66,7 @@ inline bool regex_search(const std::basic_string& s, return regex_search(s.begin(), s.end(), m, e, flags); } -template +BOOST_REGEX_MODULE_EXPORT template bool regex_search(BidiIterator first, BidiIterator last, const basic_regex& e, match_flag_type flags = match_default) @@ -80,7 +80,7 @@ bool regex_search(BidiIterator first, BidiIterator last, return matcher.find(); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_search(const charT* str, const basic_regex& e, match_flag_type flags = match_default) @@ -88,7 +88,7 @@ inline bool regex_search(const charT* str, return regex_search(str, str + traits::length(str), e, flags); } -template +BOOST_REGEX_MODULE_EXPORT template inline bool regex_search(const std::basic_string& s, const basic_regex& e, match_flag_type flags = match_default) diff --git a/include/boost/regex/v5/regex_split.hpp b/include/boost/regex/v5/regex_split.hpp index 8d932896..7060ca1b 100644 --- a/include/boost/regex/v5/regex_split.hpp +++ b/include/boost/regex/v5/regex_split.hpp @@ -90,7 +90,7 @@ bool split_pred::operator() } // namespace BOOST_REGEX_DETAIL_NS -template +BOOST_REGEX_MODULE_EXPORT template std::size_t regex_split(OutputIterator out, std::basic_string& s, const basic_regex& e, @@ -125,7 +125,7 @@ std::size_t regex_split(OutputIterator out, return init_size - max_split; } -template +BOOST_REGEX_MODULE_EXPORT template inline std::size_t regex_split(OutputIterator out, std::basic_string& s, const basic_regex& e, @@ -134,7 +134,7 @@ inline std::size_t regex_split(OutputIterator out, return regex_split(out, s, e, flags, UINT_MAX); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::size_t regex_split(OutputIterator out, std::basic_string& s) { diff --git a/include/boost/regex/v5/regex_token_iterator.hpp b/include/boost/regex/v5/regex_token_iterator.hpp index 16832746..bf8124ef 100644 --- a/include/boost/regex/v5/regex_token_iterator.hpp +++ b/include/boost/regex/v5/regex_token_iterator.hpp @@ -19,7 +19,9 @@ #ifndef BOOST_REGEX_V5_REGEX_TOKEN_ITERATOR_HPP #define BOOST_REGEX_V5_REGEX_TOKEN_ITERATOR_HPP +#ifndef BOOST_REGEX_AS_MODULE #include +#endif namespace boost{ @@ -120,7 +122,7 @@ private: regex_token_iterator_implementation& operator=(const regex_token_iterator_implementation&); }; -template ::value_type, class traits = regex_traits > class regex_token_iterator @@ -208,39 +210,39 @@ private: } }; -typedef regex_token_iterator cregex_token_iterator; -typedef regex_token_iterator sregex_token_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_token_iterator cregex_token_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_token_iterator sregex_token_iterator; #ifndef BOOST_NO_WREGEX -typedef regex_token_iterator wcregex_token_iterator; -typedef regex_token_iterator wsregex_token_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_token_iterator wcregex_token_iterator; +BOOST_REGEX_MODULE_EXPORT typedef regex_token_iterator wsregex_token_iterator; #endif -template +BOOST_REGEX_MODULE_EXPORT template inline regex_token_iterator make_regex_token_iterator(const charT* p, const basic_regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default) { return regex_token_iterator(p, p+traits::length(p), e, submatch, m); } -template +BOOST_REGEX_MODULE_EXPORT template inline regex_token_iterator::const_iterator, charT, traits> make_regex_token_iterator(const std::basic_string& p, const basic_regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default) { return regex_token_iterator::const_iterator, charT, traits>(p.begin(), p.end(), e, submatch, m); } -template +BOOST_REGEX_MODULE_EXPORT template inline regex_token_iterator make_regex_token_iterator(const charT* p, const basic_regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default) { return regex_token_iterator(p, p+traits::length(p), e, submatch, m); } -template +BOOST_REGEX_MODULE_EXPORT template inline regex_token_iterator::const_iterator, charT, traits> make_regex_token_iterator(const std::basic_string& p, const basic_regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default) { return regex_token_iterator::const_iterator, charT, traits>(p.begin(), p.end(), e, submatch, m); } -template +BOOST_REGEX_MODULE_EXPORT template inline regex_token_iterator make_regex_token_iterator(const charT* p, const basic_regex& e, const std::vector& submatch, regex_constants::match_flag_type m = regex_constants::match_default) { return regex_token_iterator(p, p+traits::length(p), e, submatch, m); } -template +BOOST_REGEX_MODULE_EXPORT template inline regex_token_iterator::const_iterator, charT, traits> make_regex_token_iterator(const std::basic_string& p, const basic_regex& e, const std::vector& submatch, regex_constants::match_flag_type m = regex_constants::match_default) { return regex_token_iterator::const_iterator, charT, traits>(p.begin(), p.end(), e, submatch, m); diff --git a/include/boost/regex/v5/regex_traits.hpp b/include/boost/regex/v5/regex_traits.hpp index 6c64695b..25dd542b 100644 --- a/include/boost/regex/v5/regex_traits.hpp +++ b/include/boost/regex/v5/regex_traits.hpp @@ -33,7 +33,7 @@ namespace boost{ -template +BOOST_REGEX_MODULE_EXPORT template struct regex_traits : public implementationT { regex_traits() : implementationT() {} diff --git a/include/boost/regex/v5/regex_traits_defaults.hpp b/include/boost/regex/v5/regex_traits_defaults.hpp index 4b81441f..1cd7adc1 100644 --- a/include/boost/regex/v5/regex_traits_defaults.hpp +++ b/include/boost/regex/v5/regex_traits_defaults.hpp @@ -24,12 +24,14 @@ #include #include #include +#ifndef BOOST_REGEX_AS_MODULE #include #include #include #include #include #include +#endif namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ diff --git a/include/boost/regex/v5/regex_workaround.hpp b/include/boost/regex/v5/regex_workaround.hpp index e9ca79d4..23e8fe3f 100644 --- a/include/boost/regex/v5/regex_workaround.hpp +++ b/include/boost/regex/v5/regex_workaround.hpp @@ -20,9 +20,11 @@ #define BOOST_REGEX_WORKAROUND_HPP #include +#ifndef BOOST_REGEX_AS_MODULE #include #include #include +#endif #ifndef BOOST_REGEX_STANDALONE #include diff --git a/include/boost/regex/v5/sub_match.hpp b/include/boost/regex/v5/sub_match.hpp index aa61b560..3afa7c36 100644 --- a/include/boost/regex/v5/sub_match.hpp +++ b/include/boost/regex/v5/sub_match.hpp @@ -21,7 +21,7 @@ namespace boost{ -template +BOOST_REGEX_MODULE_EXPORT template struct sub_match : public std::pair { typedef typename std::iterator_traits::value_type value_type; @@ -145,167 +145,167 @@ public: BidiIterator end()const { return this->second; } }; -typedef sub_match csub_match; -typedef sub_match ssub_match; +BOOST_REGEX_MODULE_EXPORT typedef sub_match csub_match; +BOOST_REGEX_MODULE_EXPORT typedef sub_match ssub_match; #ifndef BOOST_NO_WREGEX -typedef sub_match wcsub_match; -typedef sub_match wssub_match; +BOOST_REGEX_MODULE_EXPORT typedef sub_match wcsub_match; +BOOST_REGEX_MODULE_EXPORT typedef sub_match wssub_match; #endif // comparison to std::basic_string<> part 1: -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator == (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) == 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator != (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) != 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator < (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) < 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator <= (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) <= 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator >= (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) >= 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator > (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) > 0; } // comparison to std::basic_string<> part 2: -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator == (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) == 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator != (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) != 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator < (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) < 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator > (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) > 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator <= (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) <= 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator >= (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) >= 0; } // comparison to const charT* part 1: -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator == (const sub_match& m, typename std::iterator_traits::value_type const* s) { return m.str().compare(s) == 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator != (const sub_match& m, typename std::iterator_traits::value_type const* s) { return m.str().compare(s) != 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator > (const sub_match& m, typename std::iterator_traits::value_type const* s) { return m.str().compare(s) > 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator < (const sub_match& m, typename std::iterator_traits::value_type const* s) { return m.str().compare(s) < 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator >= (const sub_match& m, typename std::iterator_traits::value_type const* s) { return m.str().compare(s) >= 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator <= (const sub_match& m, typename std::iterator_traits::value_type const* s) { return m.str().compare(s) <= 0; } // comparison to const charT* part 2: -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator == (typename std::iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) == 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator != (typename std::iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) != 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator < (typename std::iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) > 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator > (typename std::iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) < 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator <= (typename std::iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) >= 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator >= (typename std::iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) <= 0; } // comparison to const charT& part 1: -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator == (const sub_match& m, typename std::iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) == 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator != (const sub_match& m, typename std::iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) != 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator > (const sub_match& m, typename std::iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) > 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator < (const sub_match& m, typename std::iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) < 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator >= (const sub_match& m, typename std::iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) >= 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator <= (const sub_match& m, typename std::iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) <= 0; } // comparison to const charT* part 2: -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator == (typename std::iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) == 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator != (typename std::iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) != 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator < (typename std::iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) > 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator > (typename std::iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) < 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator <= (typename std::iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) >= 0; } -template +BOOST_REGEX_MODULE_EXPORT template inline bool operator >= (typename std::iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) <= 0; } // addition operators: -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::value_type, traits, Allocator> operator + (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) @@ -314,7 +314,7 @@ operator + (const std::basic_string +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::value_type, traits, Allocator> operator + (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) @@ -323,7 +323,7 @@ operator + (const sub_match& m, result.reserve(s.size() + m.length() + 1); return result.append(m.first, m.second).append(s); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::value_type> operator + (typename std::iterator_traits::value_type const* s, const sub_match& m) @@ -332,7 +332,7 @@ operator + (typename std::iterator_traits::value_type cons result.reserve(std::char_traits::value_type>::length(s) + m.length() + 1); return result.append(s).append(m.first, m.second); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::value_type> operator + (const sub_match& m, typename std::iterator_traits::value_type const * s) @@ -341,7 +341,7 @@ operator + (const sub_match& m, result.reserve(std::char_traits::value_type>::length(s) + m.length() + 1); return result.append(m.first, m.second).append(s); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::value_type> operator + (typename std::iterator_traits::value_type const& s, const sub_match& m) @@ -350,7 +350,7 @@ operator + (typename std::iterator_traits::value_type cons result.reserve(m.length() + 2); return result.append(1, s).append(m.first, m.second); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::value_type> operator + (const sub_match& m, typename std::iterator_traits::value_type const& s) @@ -359,7 +359,7 @@ operator + (const sub_match& m, result.reserve(m.length() + 2); return result.append(m.first, m.second).append(1, s); } -template +BOOST_REGEX_MODULE_EXPORT template inline std::basic_string::value_type> operator + (const sub_match& m1, const sub_match& m2) @@ -368,7 +368,7 @@ operator + (const sub_match& m1, result.reserve(m1.length() + m2.length() + 1); return result.append(m1.first, m1.second).append(m2.first, m2.second); } -template +BOOST_REGEX_MODULE_EXPORT template std::basic_ostream& operator << (std::basic_ostream& os, const sub_match& s) diff --git a/include/boost/regex/v5/syntax_type.hpp b/include/boost/regex/v5/syntax_type.hpp index 3efdf0b0..af66ad73 100644 --- a/include/boost/regex/v5/syntax_type.hpp +++ b/include/boost/regex/v5/syntax_type.hpp @@ -22,81 +22,81 @@ namespace boost{ namespace regex_constants{ -typedef unsigned char syntax_type; +BOOST_REGEX_MODULE_EXPORT typedef unsigned char syntax_type; // // values chosen are binary compatible with previous version: // -static const syntax_type syntax_char = 0; -static const syntax_type syntax_open_mark = 1; -static const syntax_type syntax_close_mark = 2; -static const syntax_type syntax_dollar = 3; -static const syntax_type syntax_caret = 4; -static const syntax_type syntax_dot = 5; -static const syntax_type syntax_star = 6; -static const syntax_type syntax_plus = 7; -static const syntax_type syntax_question = 8; -static const syntax_type syntax_open_set = 9; -static const syntax_type syntax_close_set = 10; -static const syntax_type syntax_or = 11; -static const syntax_type syntax_escape = 12; -static const syntax_type syntax_dash = 14; -static const syntax_type syntax_open_brace = 15; -static const syntax_type syntax_close_brace = 16; -static const syntax_type syntax_digit = 17; -static const syntax_type syntax_comma = 27; -static const syntax_type syntax_equal = 37; -static const syntax_type syntax_colon = 36; -static const syntax_type syntax_not = 53; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_char = 0; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_open_mark = 1; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_close_mark = 2; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_dollar = 3; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_caret = 4; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_dot = 5; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_star = 6; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_plus = 7; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_question = 8; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_open_set = 9; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_close_set = 10; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_or = 11; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_escape = 12; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_dash = 14; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_open_brace = 15; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_close_brace = 16; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_digit = 17; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_comma = 27; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_equal = 37; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_colon = 36; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_not = 53; // extensions: -static const syntax_type syntax_hash = 13; -static const syntax_type syntax_newline = 26; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_hash = 13; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST syntax_type syntax_newline = 26; // escapes: -typedef syntax_type escape_syntax_type; +BOOST_REGEX_MODULE_EXPORT typedef syntax_type escape_syntax_type; -static const escape_syntax_type escape_type_word_assert = 18; -static const escape_syntax_type escape_type_not_word_assert = 19; -static const escape_syntax_type escape_type_control_f = 29; -static const escape_syntax_type escape_type_control_n = 30; -static const escape_syntax_type escape_type_control_r = 31; -static const escape_syntax_type escape_type_control_t = 32; -static const escape_syntax_type escape_type_control_v = 33; -static const escape_syntax_type escape_type_ascii_control = 35; -static const escape_syntax_type escape_type_hex = 34; -static const escape_syntax_type escape_type_unicode = 0; // not used -static const escape_syntax_type escape_type_identity = 0; // not used -static const escape_syntax_type escape_type_backref = syntax_digit; -static const escape_syntax_type escape_type_decimal = syntax_digit; // not used -static const escape_syntax_type escape_type_class = 22; -static const escape_syntax_type escape_type_not_class = 23; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_word_assert = 18; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_not_word_assert = 19; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_control_f = 29; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_control_n = 30; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_control_r = 31; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_control_t = 32; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_control_v = 33; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_ascii_control = 35; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_hex = 34; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_unicode = 0; // not used +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_identity = 0; // not used +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_backref = syntax_digit; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_decimal = syntax_digit; // not used +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_class = 22; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_not_class = 23; // extensions: -static const escape_syntax_type escape_type_left_word = 20; -static const escape_syntax_type escape_type_right_word = 21; -static const escape_syntax_type escape_type_start_buffer = 24; // for \` -static const escape_syntax_type escape_type_end_buffer = 25; // for \' -static const escape_syntax_type escape_type_control_a = 28; // for \a -static const escape_syntax_type escape_type_e = 38; // for \e -static const escape_syntax_type escape_type_E = 47; // for \Q\E -static const escape_syntax_type escape_type_Q = 48; // for \Q\E -static const escape_syntax_type escape_type_X = 49; // for \X -static const escape_syntax_type escape_type_C = 50; // for \C -static const escape_syntax_type escape_type_Z = 51; // for \Z -static const escape_syntax_type escape_type_G = 52; // for \G +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_left_word = 20; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_right_word = 21; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_start_buffer = 24; // for \` +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_end_buffer = 25; // for \' +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_control_a = 28; // for \a +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_e = 38; // for \e +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_E = 47; // for \Q\E +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_Q = 48; // for \Q\E +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_X = 49; // for \X +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_C = 50; // for \C +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_Z = 51; // for \Z +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_G = 52; // for \G -static const escape_syntax_type escape_type_property = 54; // for \p -static const escape_syntax_type escape_type_not_property = 55; // for \P -static const escape_syntax_type escape_type_named_char = 56; // for \N -static const escape_syntax_type escape_type_extended_backref = 57; // for \g -static const escape_syntax_type escape_type_reset_start_mark = 58; // for \K -static const escape_syntax_type escape_type_line_ending = 59; // for \R +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_property = 54; // for \p +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_not_property = 55; // for \P +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_named_char = 56; // for \N +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_extended_backref = 57; // for \g +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_reset_start_mark = 58; // for \K +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type escape_type_line_ending = 59; // for \R -static const escape_syntax_type syntax_max = 60; +BOOST_REGEX_MODULE_EXPORT BOOST_REGEX_STATIC_CONST escape_syntax_type syntax_max = 60; } } diff --git a/include/boost/regex/v5/unicode_iterator.hpp b/include/boost/regex/v5/unicode_iterator.hpp index 9d3dd8b9..d7173763 100644 --- a/include/boost/regex/v5/unicode_iterator.hpp +++ b/include/boost/regex/v5/unicode_iterator.hpp @@ -60,12 +60,14 @@ Accepts UTF-32 code points and forwards them on as UTF-16 code points. #ifndef BOOST_REGEX_UNICODE_ITERATOR_HPP #define BOOST_REGEX_UNICODE_ITERATOR_HPP -#include #include +#ifndef BOOST_REGEX_AS_MODULE +#include #include #include #include #include // CHAR_BIT +#endif #ifndef BOOST_REGEX_STANDALONE #include @@ -75,9 +77,9 @@ namespace boost{ namespace detail{ -static const std::uint16_t high_surrogate_base = 0xD7C0u; -static const std::uint16_t low_surrogate_base = 0xDC00u; -static const std::uint32_t ten_bit_mask = 0x3FFu; +BOOST_REGEX_STATIC_CONST std::uint16_t high_surrogate_base = 0xD7C0u; +BOOST_REGEX_STATIC_CONST std::uint16_t low_surrogate_base = 0xDC00u; +BOOST_REGEX_STATIC_CONST std::uint32_t ten_bit_mask = 0x3FFu; inline bool is_high_surrogate(std::uint16_t v) { diff --git a/include/boost/regex/v5/w32_regex_traits.hpp b/include/boost/regex/v5/w32_regex_traits.hpp index 16f7ee4e..d6a56da5 100644 --- a/include/boost/regex/v5/w32_regex_traits.hpp +++ b/include/boost/regex/v5/w32_regex_traits.hpp @@ -23,9 +23,11 @@ #include #include +#ifndef BOOST_REGEX_AS_MODULE #ifdef BOOST_HAS_THREADS #include #endif +#endif #include #include @@ -652,7 +654,7 @@ std::shared_ptr > create_w32_regex_ } // BOOST_REGEX_DETAIL_NS -template +BOOST_REGEX_MODULE_EXPORT template class w32_regex_traits { public: diff --git a/module/regex.cxx b/module/regex.cxx new file mode 100644 index 00000000..a23200f0 --- /dev/null +++ b/module/regex.cxx @@ -0,0 +1,70 @@ + +module; + +#if defined(_WIN32) && __has_include() +#include +#endif +#include +#include +#include +#include + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef BOOST_HAS_THREADS +#include +#endif +#endif + + +#if __has_include() +#include +#include +#include +#endif + +#define BOOST_REGEX_AS_MODULE +#define BOOST_REGEX_STANDALONE +#define BOOST_REGEX_MODULE_EXPORT export + +export module boost.regex; + +#include + +#if __has_include() +#include +#endif diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index edbe190a..fc0a710f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -217,6 +217,7 @@ test-suite regex compile test_consolidated.cpp ; build-project ../example ; +build-project ./module ; # `quick` target (for CI) run quick.cpp ../build//boost_regex ; diff --git a/test/concepts/module_concept_check.cpp b/test/concepts/module_concept_check.cpp new file mode 100644 index 00000000..86d981a3 --- /dev/null +++ b/test/concepts/module_concept_check.cpp @@ -0,0 +1,99 @@ +/* + * + * Copyright (c) 2022 + * 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) + * + */ + +#ifdef __GNUC__ +// +// For some reason, GCC chokes unless all std lib includes appear +// before module imports: +// +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +import boost.regex; + +#define BOOST_REGEX_TEST_MODULE + +#include + + +int main() +{ + boost::function_requires< + boost::RegexTraitsConcept< + boost::regex_traits + > + >(); +#ifndef BOOST_NO_STD_LOCALE + boost::function_requires< + boost::BoostRegexConcept< + boost::basic_regex > + > + >(); +#ifndef BOOST_NO_WREGEX + boost::function_requires< + boost::BoostRegexConcept< + boost::basic_regex > + > + >(); +#endif +#endif + boost::function_requires< + boost::BoostRegexConcept< + boost::basic_regex > + > + >(); +#ifndef BOOST_NO_WREGEX + boost::function_requires< + boost::BoostRegexConcept< + boost::basic_regex > + > + >(); +#endif +#if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32) + boost::function_requires< + boost::BoostRegexConcept< + boost::basic_regex > + > + >(); +#ifndef BOOST_NO_WREGEX + boost::function_requires< + boost::BoostRegexConcept< + boost::basic_regex > + > + >(); +#endif +#endif + // + // now test the regex_traits concepts: + // + typedef boost::basic_regex > regex_traits_tester_type1; + boost::function_requires< + boost::BoostRegexConcept< + regex_traits_tester_type1 + > + >(); + typedef boost::basic_regex > regex_traits_tester_type2; + boost::function_requires< + boost::BaseRegexConcept< + regex_traits_tester_type2 + > + >(); + return 0; +} + + diff --git a/test/module/Jamfile.v2 b/test/module/Jamfile.v2 new file mode 100644 index 00000000..480bb070 --- /dev/null +++ b/test/module/Jamfile.v2 @@ -0,0 +1,33 @@ +# copyright John Maddock 2022 +# Distributed under 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. + +project + : requirements + multi + msvc:on + msvc:latest + gcc:-fmodules-ts + ; + +obj regex : ../../module/regex.cxx : msvc:-interface [ check-target-builds ./config//test_has_module_support : : no ] ; + +exe credit_card_example : credit_card_example.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe partial_regex_grep : partial_regex_grep.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe partial_regex_iterate : partial_regex_iterate.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe partial_regex_match : partial_regex_match.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_grep_example_1 : regex_grep_example_1.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_grep_example_2 : regex_grep_example_2.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_grep_example_3 : regex_grep_example_3.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_iterator_example : regex_iterator_example.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_match_example : regex_match_example.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_merge_example : regex_merge_example.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_replace_example : regex_replace_example.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_search_example : regex_search_example.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_split_example_1 : regex_split_example_1.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_split_example_2 : regex_split_example_2.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_token_iterator_eg_1 : regex_token_iterator_eg_1.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; +exe regex_token_iterator_eg_2 : regex_token_iterator_eg_2.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; + +compile ../concepts/module_concept_check.cpp regex : [ check-target-builds ./config//test_has_module_support : : no ] regex ; \ No newline at end of file diff --git a/test/module/config/Jamfile.v2 b/test/module/config/Jamfile.v2 new file mode 100644 index 00000000..f268160d --- /dev/null +++ b/test/module/config/Jamfile.v2 @@ -0,0 +1,17 @@ +# copyright John Maddock 2022 +# Distributed under 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. + +project + : requirements + multi + msvc:on + msvc:latest + gcc:-fmodules-ts + ; + + +obj has_module_support : has_module_support.cpp : msvc:-interface ; +exe test_has_module_support : test_has_module_support.cpp has_module_support : has_module_support ; +explicit test_has_module_support ; diff --git a/test/module/config/has_module_support.cpp b/test/module/config/has_module_support.cpp new file mode 100644 index 00000000..718e533b --- /dev/null +++ b/test/module/config/has_module_support.cpp @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2022 + * 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) + * + */ + +module; + +#include + +export module test_support; + +export template struct pimpl +{ +private: + std::shared_ptr data; +public: + pimpl(const T& x) : data(new T(x)) {} + pimpl() = default; +}; + diff --git a/test/module/config/test_has_module_support.cpp b/test/module/config/test_has_module_support.cpp new file mode 100644 index 00000000..79755121 --- /dev/null +++ b/test/module/config/test_has_module_support.cpp @@ -0,0 +1,17 @@ +/* + * + * Copyright (c) 2022 + * 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) + * + */ + +import test_support; + +int main() +{ + pimpl p1, p2(3); +} diff --git a/test/module/credit_card_example.cpp b/test/module/credit_card_example.cpp new file mode 100644 index 00000000..15f8aa09 --- /dev/null +++ b/test/module/credit_card_example.cpp @@ -0,0 +1,75 @@ +/* + * + * 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 credit_card_example.cpp + * VERSION see + * DESCRIPTION: Credit card number formatting code. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#endif + +import boost.regex; + + +bool validate_card_format(const std::string& s) +{ + static const boost::regex e("(\\d{4}[- ]){3}\\d{4}"); + return boost::regex_match(s, e); +} + +const boost::regex e("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"); +const std::string machine_format("\\1\\2\\3\\4"); +const std::string human_format("\\1-\\2-\\3-\\4"); + +std::string machine_readable_card_number(const std::string& s) +{ + return boost::regex_replace(s, e, machine_format, boost::match_default | boost::format_sed); +} + +std::string human_readable_card_number(const std::string& s) +{ + return boost::regex_replace(s, e, human_format, boost::match_default | boost::format_sed); +} + +int main() +{ + using namespace std; + + string s[4] = { "0000111122223333", "0000 1111 2222 3333", + "0000-1111-2222-3333", "000-1111-2222-3333", }; + int i; + for(i = 0; i < 4; ++i) + { + cout << "validate_card_format(\"" << s[i] << "\") returned " << validate_card_format(s[i]) << endl; + } + for(i = 0; i < 4; ++i) + { + cout << "machine_readable_card_number(\"" << s[i] << "\") returned " << machine_readable_card_number(s[i]) << endl; + } + for(i = 0; i < 4; ++i) + { + cout << "human_readable_card_number(\"" << s[i] << "\") returned " << human_readable_card_number(s[i]) << endl; + } + return 0; +} + + + + diff --git a/test/module/gcm.cache/boost.regex.gcm b/test/module/gcm.cache/boost.regex.gcm new file mode 100644 index 00000000..d1c7d065 Binary files /dev/null and b/test/module/gcm.cache/boost.regex.gcm differ diff --git a/test/module/icu_example.cpp b/test/module/icu_example.cpp new file mode 100644 index 00000000..6d1fc3be --- /dev/null +++ b/test/module/icu_example.cpp @@ -0,0 +1,188 @@ +/* + * + * 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 mfc_example.cpp + * VERSION see + * DESCRIPTION: examples of using Boost.Regex with MFC and ATL string types. + */ + +#include + +#ifdef BOOST_HAS_ICU + +#include +#include +#include + +// +// Find out if *password* meets our password requirements, +// as defined by the regular expression *requirements*. +// +bool is_valid_password(const U_NAMESPACE_QUALIFIER UnicodeString& password, const U_NAMESPACE_QUALIFIER UnicodeString& requirements) +{ + return boost::u32regex_match(password, boost::make_u32regex(requirements)); +} + +// +// Extract filename part of a path from a UTF-8 encoded std::string and return the result +// as another std::string: +// +std::string get_filename(const std::string& path) +{ + boost::u32regex r = boost::make_u32regex("(?:\\A|.*\\\\)([^\\\\]+)"); + boost::smatch what; + if(boost::u32regex_match(path, what, r)) + { + // extract $1 as a std::string: + return what.str(1); + } + else + { + throw std::runtime_error("Invalid pathname"); + } +} + +U_NAMESPACE_QUALIFIER UnicodeString extract_greek(const U_NAMESPACE_QUALIFIER UnicodeString& text) +{ + // searches through some UTF-16 encoded text for a block encoded in Greek, + // this expression is imperfect, but the best we can do for now - searching + // for specific scripts is actually pretty hard to do right. + boost::u32regex r = boost::make_u32regex(L"[\\x{370}-\\x{3FF}](?:[^[:L*:]]|[\\x{370}-\\x{3FF}])*"); + boost::u16match what; + if(boost::u32regex_search(text, what, r)) + { + // extract $0 as a UnicodeString: + return U_NAMESPACE_QUALIFIER UnicodeString(what[0].first, what.length(0)); + } + else + { + throw std::runtime_error("No Greek found!"); + } +} + +void enumerate_currencies(const std::string& text) +{ + // enumerate and print all the currency symbols, along + // with any associated numeric values: + const char* re = + "([[:Sc:]][[:Cf:][:Cc:][:Z*:]]*)?" + "([[:Nd:]]+(?:[[:Po:]][[:Nd:]]+)?)?" + "(?(1)" + "|(?(2)" + "[[:Cf:][:Cc:][:Z*:]]*" + ")" + "[[:Sc:]]" + ")"; + boost::u32regex r = boost::make_u32regex(re); + boost::u32regex_iterator i(boost::make_u32regex_iterator(text, r)), j; + while(i != j) + { + std::cout << (*i)[0] << std::endl; + ++i; + } +} + +void enumerate_currencies2(const std::string& text) +{ + // enumerate and print all the currency symbols, along + // with any associated numeric values: + const char* re = + "([[:Sc:]][[:Cf:][:Cc:][:Z*:]]*)?" + "([[:Nd:]]+(?:[[:Po:]][[:Nd:]]+)?)?" + "(?(1)" + "|(?(2)" + "[[:Cf:][:Cc:][:Z*:]]*" + ")" + "[[:Sc:]]" + ")"; + boost::u32regex r = boost::make_u32regex(re); + boost::u32regex_token_iterator + i(boost::make_u32regex_token_iterator(text, r, 1)), j; + while(i != j) + { + std::cout << *i << std::endl; + ++i; + } +} + + +// +// Take a credit card number as a string of digits, +// and reformat it as a human readable string with "-" +// separating each group of four digit;, +// note that we're mixing a UTF-32 regex, with a UTF-16 +// string and a UTF-8 format specifier, and it still all +// just works: +// +const boost::u32regex e = boost::make_u32regex("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"); +const char* human_format = "$1-$2-$3-$4"; + +U_NAMESPACE_QUALIFIER UnicodeString human_readable_card_number(const U_NAMESPACE_QUALIFIER UnicodeString& s) +{ + return boost::u32regex_replace(s, e, human_format); +} + + +int main() +{ + // password checks using u32regex_match: + U_NAMESPACE_QUALIFIER UnicodeString pwd = "abcDEF---"; + U_NAMESPACE_QUALIFIER UnicodeString pwd_check = "(?=.*[[:lower:]])(?=.*[[:upper:]])(?=.*[[:punct:]]).{6,}"; + bool b = is_valid_password(pwd, pwd_check); + assert(b); + pwd = "abcD-"; + b = is_valid_password(pwd, pwd_check); + assert(!b); + // filename extraction with u32regex_match: + std::string file = "abc.hpp"; + file = get_filename(file); + assert(file == "abc.hpp"); + file = "c:\\a\\b\\c\\d.h"; + file = get_filename(file); + assert(file == "d.h"); + + // Greek text extraction with u32regex_search: + const UChar t[] = { + 'S', 'o', 'm', 'e', ' ', 'w', 'h', 'e', 'r', 'e', ' ', 'i', 'n', 0x0391, 0x039D, 0x0395, 0x0398, 0x0391, 0 + }; + const UChar g[] = { + 0x0391, 0x039D, 0x0395, 0x0398, 0x0391, 0 + }; + U_NAMESPACE_QUALIFIER UnicodeString text = t; + U_NAMESPACE_QUALIFIER UnicodeString greek = extract_greek(text); + assert(greek == g); + + // extract currency symbols with associated value, use iterator interface: + std::string text2 = " $100.23 or \xC2\xA3""198.12 "; // \xC2\xA3 is the pound sign encoded in UTF-8 + enumerate_currencies(text2); + enumerate_currencies2(text2); + + U_NAMESPACE_QUALIFIER UnicodeString credit_card_number = "1234567887654321"; + credit_card_number = human_readable_card_number(credit_card_number); + assert(credit_card_number == "1234-5678-8765-4321"); + return 0; +} + +#else + +#include + +int main() +{ + std::cout << "ICU support not enabled, feature unavailable"; + return 0; +} + + +#endif + diff --git a/test/module/partial_regex_grep.cpp b/test/module/partial_regex_grep.cpp new file mode 100644 index 00000000..437c37f0 --- /dev/null +++ b/test/module/partial_regex_grep.cpp @@ -0,0 +1,109 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 partial_regex_grep.cpp + * VERSION see + * DESCRIPTION: Search example using partial matches. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#include +#endif + +import boost.regex; + +// match some kind of html tag: +boost::regex e("<[^>]*>"); +// count how many: +unsigned int tags = 0; +// saved position of partial match: +const char* next_pos = 0; + +bool grep_callback(const boost::match_results& m) +{ + if(m[0].matched == false) + { + // save position and return: + next_pos = m[0].first; + } + else + ++tags; + return true; +} + +void search(std::istream& is) +{ + char buf[4096]; + next_pos = buf + sizeof(buf); + bool have_more = true; + while(have_more) + { + // how much do we copy forward from last try: + std::ptrdiff_t leftover = (buf + sizeof(buf)) - next_pos; + // and how much is left to fill: + std::ptrdiff_t size = next_pos - buf; + // copy forward whatever we have left: + std::memmove(buf, next_pos, leftover); + // fill the rest from the stream: + is.read(buf + leftover, size); + std::streamsize read = is.gcount(); + // check to see if we've run out of text: + have_more = read == size; + // reset next_pos: + next_pos = buf + sizeof(buf); + // and then grep: + boost::regex_grep(grep_callback, + static_cast(buf), + static_cast(buf + read + leftover), + e, + boost::match_default | boost::match_partial); + } +} + +int main(int argc, char* argv[]) +{ + if(argc > 1) + { + for(int i = 1; i < argc; ++i) + { + std::ifstream fs(argv[i]); + if(fs.bad()) continue; + search(fs); + fs.close(); + } + } + else + { + std::string one(""); + std::string what; + while(what.size() < 10000) + { + what.append(one); + what.append(13, ' '); + } + std::stringstream ss; + ss.str(what); + search(ss); + } + std::cout << "total tag count was " << tags << std::endl; + return 0; +} + diff --git a/test/module/partial_regex_iterate.cpp b/test/module/partial_regex_iterate.cpp new file mode 100644 index 00000000..887abdc2 --- /dev/null +++ b/test/module/partial_regex_iterate.cpp @@ -0,0 +1,125 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 partial_regex_iterate.cpp + * VERSION see + * DESCRIPTION: Search example using partial matches. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#include +#endif + +import boost.regex; + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::memmove; } +#endif + +// match some kind of html tag: +boost::regex e("<[^>]*>"); +// count how many: +unsigned int tags = 0; + +void search(std::istream& is) +{ + // buffer we'll be searching in: + char buf[4096]; + // saved position of end of partial match: + const char* next_pos = buf + sizeof(buf); + // flag to indicate whether there is more input to come: + bool have_more = true; + + while(have_more) + { + // how much do we copy forward from last try: + std::ptrdiff_t leftover = (buf + sizeof(buf)) - next_pos; + // and how much is left to fill: + std::ptrdiff_t size = next_pos - buf; + // copy forward whatever we have left: + std::memmove(buf, next_pos, leftover); + // fill the rest from the stream: + is.read(buf + leftover, size); + std::streamsize read = is.gcount(); + // check to see if we've run out of text: + have_more = read == size; + // reset next_pos: + next_pos = buf + sizeof(buf); + // and then iterate: + boost::cregex_iterator a( + buf, + buf + read + leftover, + e, + boost::match_default | boost::match_partial); + boost::cregex_iterator b; + + while(a != b) + { + if((*a)[0].matched == false) + { + // Partial match, save position and break: + next_pos = (*a)[0].first; + break; + } + else + { + // full match: + ++tags; + } + + // move to next match: + ++a; + } + } +} + +int main(int argc, char* argv[]) +{ + if(argc > 1) + { + for(int i = 1; i < argc; ++i) + { + std::ifstream fs(argv[i]); + if(fs.bad()) continue; + search(fs); + fs.close(); + } + } + else + { + std::string one(""); + std::string what; + while(what.size() < 10000) + { + what.append(one); + what.append(13, ' '); + } + std::stringstream ss; + ss.str(what); + search(ss); + } + std::cout << "total tag count was " << tags << std::endl; + return 0; +} + + + + diff --git a/test/module/partial_regex_match.cpp b/test/module/partial_regex_match.cpp new file mode 100644 index 00000000..fc7c2273 --- /dev/null +++ b/test/module/partial_regex_match.cpp @@ -0,0 +1,77 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 partial_regex_match.cpp + * VERSION see + * DESCRIPTION: regex_match example using partial matches. + */ + + +//#include + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#endif + +import boost.regex; + +boost::regex e("(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})"); + +bool is_possible_card_number(const std::string& input) +{ + // + // return false for partial match, true for full match, or throw for + // impossible match based on what we have so far... + boost::match_results what; + if(0 == boost::regex_match(input, what, e, boost::match_default | boost::match_partial)) + { + // the input so far could not possibly be valid so reject it: + throw std::runtime_error("Invalid data entered - this could not possibly be a valid card number"); + } + // OK so far so good, but have we finished? + if(what[0].matched) + { + // excellent, we have a result: + return true; + } + // what we have so far is only a partial match... + return false; +} + +int main(int argc, char* argv[]) +{ + try{ + std::string input; + if(argc > 1) + input = argv[1]; + else + std::cin >> input; + if(is_possible_card_number(input)) + { + std::cout << "Matched OK..." << std::endl; + } + else + std::cout << "Got a partial match..." << std::endl; + } + catch(const std::exception& e) + { + std::cout << e.what() << std::endl; + } + return 0; +} + diff --git a/test/module/regex_grep_example_1.cpp b/test/module/regex_grep_example_1.cpp new file mode 100644 index 00000000..f8cf35a1 --- /dev/null +++ b/test/module/regex_grep_example_1.cpp @@ -0,0 +1,138 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_grep_example_1.cpp + * VERSION see + * DESCRIPTION: regex_grep example 1: searches a cpp file for class definitions. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include + +#endif + +import boost.regex; + +// purpose: +// takes the contents of a file in the form of a string +// and searches for all the C++ class definitions, storing +// their locations in a map of strings/int's + +typedef std::map > map_type; + +const char* re = + // possibly leading whitespace: + "^[[:space:]]*" + // possible template declaration: + "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?" + // class or struct: + "(class|struct)[[:space:]]*" + // leading declspec macros etc: + "(" + "\\<\\w+\\>" + "(" + "[[:blank:]]*\\([^)]*\\)" + ")?" + "[[:space:]]*" + ")*" + // the class name + "(\\<\\w*\\>)[[:space:]]*" + // template specialisation parameters + "(<[^;:{]+>)?[[:space:]]*" + // terminate in { or : + "(\\{|:[^;\\{()]*\\{)"; + +boost::regex expression(re); + +class IndexClassesPred +{ + map_type& m; + std::string::const_iterator base; +public: + IndexClassesPred(map_type& a, std::string::const_iterator b) : m(a), base(b) {} + bool operator()(const boost::match_results& what) + { + // what[0] contains the whole string + // what[5] contains the class name. + // what[6] contains the template specialisation if any. + // add class name and position to map: + m[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] = + what[5].first - base; + return true; + } +private: + IndexClassesPred& operator=(const IndexClassesPred&); +}; + +void IndexClasses(map_type& m, const std::string& file) +{ + std::string::const_iterator start, end; + start = file.begin(); + end = file.end(); + boost::regex_grep(IndexClassesPred(m, start), start, end, expression); +} + + +using namespace std; + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, const char** argv) +{ + std::string text; + for(int i = 1; i < argc; ++i) + { + cout << "Processing file " << argv[i] << endl; + map_type m; + std::ifstream fs(argv[i]); + load_file(text, fs); + fs.close(); + IndexClasses(m, text); + cout << m.size() << " matches found" << endl; + map_type::iterator c, d; + c = m.begin(); + d = m.end(); + while(c != d) + { + cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl; + ++c; + } + } + return 0; +} + + + + + + + diff --git a/test/module/regex_grep_example_2.cpp b/test/module/regex_grep_example_2.cpp new file mode 100644 index 00000000..dd27c1be --- /dev/null +++ b/test/module/regex_grep_example_2.cpp @@ -0,0 +1,128 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_grep_example_2.cpp + * VERSION see + * DESCRIPTION: regex_grep example 2: searches a cpp file for class definitions, + * using a global callback function. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#endif + +import boost.regex; + +// purpose: +// takes the contents of a file in the form of a string +// and searches for all the C++ class definitions, storing +// their locations in a map of strings/int's + +typedef std::map > map_type; + +const char* re = + // possibly leading whitespace: + "^[[:space:]]*" + // possible template declaration: + "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?" + // class or struct: + "(class|struct)[[:space:]]*" + // leading declspec macros etc: + "(" + "\\<\\w+\\>" + "(" + "[[:blank:]]*\\([^)]*\\)" + ")?" + "[[:space:]]*" + ")*" + // the class name + "(\\<\\w*\\>)[[:space:]]*" + // template specialisation parameters + "(<[^;:{]+>)?[[:space:]]*" + // terminate in { or : + "(\\{|:[^;\\{()]*\\{)"; + + +boost::regex expression(re); +map_type class_index; +std::string::const_iterator base; + +bool grep_callback(const boost::match_results& what) +{ + // what[0] contains the whole string + // what[5] contains the class name. + // what[6] contains the template specialisation if any. + // add class name and position to map: + class_index[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] = + what[5].first - base; + return true; +} + +void IndexClasses(const std::string& file) +{ + std::string::const_iterator start, end; + start = file.begin(); + end = file.end(); + base = start; + boost::regex_grep(grep_callback, start, end, expression); +} + +using namespace std; + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, const char** argv) +{ + std::string text; + for(int i = 1; i < argc; ++i) + { + cout << "Processing file " << argv[i] << endl; + std::ifstream fs(argv[i]); + load_file(text, fs); + fs.close(); + IndexClasses(text); + cout << class_index.size() << " matches found" << endl; + map_type::iterator c, d; + c = class_index.begin(); + d = class_index.end(); + while(c != d) + { + cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl; + ++c; + } + class_index.erase(class_index.begin(), class_index.end()); + } + return 0; +} + + + diff --git a/test/module/regex_grep_example_3.cpp b/test/module/regex_grep_example_3.cpp new file mode 100644 index 00000000..c796497d --- /dev/null +++ b/test/module/regex_grep_example_3.cpp @@ -0,0 +1,140 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_grep_example_3.cpp + * VERSION see + * DESCRIPTION: regex_grep example 3: searches a cpp file for class definitions, + * using a bound member function callback. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#include +#endif + +import boost.regex; + +// purpose: +// takes the contents of a file in the form of a string +// and searches for all the C++ class definitions, storing +// their locations in a map of strings/int's + +typedef std::map > map_type; + +const char* re = + // possibly leading whitespace: + "^[[:space:]]*" + // possible template declaration: + "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?" + // class or struct: + "(class|struct)[[:space:]]*" + // leading declspec macros etc: + "(" + "\\<\\w+\\>" + "(" + "[[:blank:]]*\\([^)]*\\)" + ")?" + "[[:space:]]*" + ")*" + // the class name + "(\\<\\w*\\>)[[:space:]]*" + // template specialisation parameters + "(<[^;:{]+>)?[[:space:]]*" + // terminate in { or : + "(\\{|:[^;\\{()]*\\{)"; + + +class class_index +{ + boost::regex expression; + map_type index; + std::string::const_iterator base; + + bool grep_callback(boost::match_results what); +public: + map_type& get_map() { return index; } + void IndexClasses(const std::string& file); + class_index() + : expression(re) {} +}; + +bool class_index::grep_callback(boost::match_results what) +{ + // what[0] contains the whole string + // what[5] contains the class name. + // what[6] contains the template specialisation if any. + // add class name and position to map: + index[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] = + what[5].first - base; + return true; +} + +void class_index::IndexClasses(const std::string& file) +{ + std::string::const_iterator start, end; + start = file.begin(); + end = file.end(); + base = start; + boost::regex_grep([&](boost::match_resultsconst & what)->bool { return this->grep_callback(what); }, + start, + end, + expression); +} + +using namespace std; + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, const char** argv) +{ + std::string text; + for(int i = 1; i < argc; ++i) + { + cout << "Processing file " << argv[i] << endl; + std::ifstream fs(argv[i]); + load_file(text, fs); + fs.close(); + class_index idx; + idx.IndexClasses(text); + cout << idx.get_map().size() << " matches found" << endl; + map_type::iterator c, d; + c = idx.get_map().begin(); + d = idx.get_map().end(); + while(c != d) + { + cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl; + ++c; + } + } + return 0; +} + diff --git a/test/module/regex_iterator_example.cpp b/test/module/regex_iterator_example.cpp new file mode 100644 index 00000000..29803f1a --- /dev/null +++ b/test/module/regex_iterator_example.cpp @@ -0,0 +1,122 @@ +/* + * + * Copyright (c) 2003-2022 + * 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 regex_iterator_example_2.cpp + * VERSION see + * DESCRIPTION: regex_iterator example 2: searches a cpp file for class definitions, + * using global data. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#include +#endif + +import boost.regex; + +using namespace std; + +// purpose: +// takes the contents of a file in the form of a string +// and searches for all the C++ class definitions, storing +// their locations in a map of strings/int's + +typedef std::map > map_type; + +const char* re = + // possibly leading whitespace: + "^[[:space:]]*" + // possible template declaration: + "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?" + // class or struct: + "(class|struct)[[:space:]]*" + // leading declspec macros etc: + "(" + "\\<\\w+\\>" + "(" + "[[:blank:]]*\\([^)]*\\)" + ")?" + "[[:space:]]*" + ")*" + // the class name + "(\\<\\w*\\>)[[:space:]]*" + // template specialisation parameters + "(<[^;:{]+>)?[[:space:]]*" + // terminate in { or : + "(\\{|:[^;\\{()]*\\{)"; + + +boost::regex expression(re); +map_type class_index; + +bool regex_callback(const boost::match_results& what) +{ + // what[0] contains the whole string + // what[5] contains the class name. + // what[6] contains the template specialisation if any. + // add class name and position to map: + class_index[what[5].str() + what[6].str()] = what.position(5); + return true; +} + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, const char** argv) +{ + std::string text; + for(int i = 1; i < argc; ++i) + { + cout << "Processing file " << argv[i] << endl; + std::ifstream fs(argv[i]); + load_file(text, fs); + fs.close(); + // construct our iterators: + boost::sregex_iterator m1(text.begin(), text.end(), expression); + boost::sregex_iterator m2; + std::for_each(m1, m2, ®ex_callback); + // copy results: + cout << class_index.size() << " matches found" << endl; + map_type::iterator c, d; + c = class_index.begin(); + d = class_index.end(); + while(c != d) + { + cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl; + ++c; + } + class_index.erase(class_index.begin(), class_index.end()); + } + return 0; +} + + + diff --git a/test/module/regex_match_example.cpp b/test/module/regex_match_example.cpp new file mode 100644 index 00000000..b42a198f --- /dev/null +++ b/test/module/regex_match_example.cpp @@ -0,0 +1,89 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_match_example.cpp + * VERSION see + * DESCRIPTION: ftp based regex_match example. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#endif + +import boost.regex; + +using namespace std; +using namespace boost; + +regex expression("^([0-9]+)(\\-| |$)(.*)$"); + +// process_ftp: +// on success returns the ftp response code, and fills +// msg with the ftp response message. +int process_ftp(const char* response, std::string* msg) +{ + cmatch what; + if(regex_match(response, what, expression)) + { + // what[0] contains the whole string + // what[1] contains the response code + // what[2] contains the separator character + // what[3] contains the text message. + if(msg) + msg->assign(what[3].first, what[3].second); + return ::atoi(what[1].first); + } + // failure did not match + if(msg) + msg->erase(); + return -1; +} + +int main(int argc, const char*[]) +{ + std::string in, out; + do + { + if(argc == 1) + { + cout << "enter test string" << endl; + getline(cin, in); + if(in == "quit") + break; + } + else + in = "100 this is an ftp message text"; + int result; + result = process_ftp(in.c_str(), &out); + if(result != -1) + { + cout << "Match found:" << endl; + cout << "Response code: " << result << endl; + cout << "Message text: " << out << endl; + } + else + { + cout << "Match not found" << endl; + } + cout << endl; + } while(argc == 1); + return 0; +} + diff --git a/test/module/regex_merge_example.cpp b/test/module/regex_merge_example.cpp new file mode 100644 index 00000000..bced4db9 --- /dev/null +++ b/test/module/regex_merge_example.cpp @@ -0,0 +1,134 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_merge_example.cpp + * VERSION see + * DESCRIPTION: regex_merge example: + * converts a C++ file to syntax highlighted HTML. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#include +#include +#include +#endif + +import boost.regex; + +// purpose: +// takes the contents of a file and transform to +// syntax highlighted code in html format + +boost::regex e1, e2; +extern const char* expression_text; +extern const char* format_string; +extern const char* pre_expression; +extern const char* pre_format; +extern const char* header_text; +extern const char* footer_text; + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, const char** argv) +{ + try{ + e1.assign(expression_text); + e2.assign(pre_expression); + for(int i = 1; i < argc; ++i) + { + std::cout << "Processing file " << argv[i] << std::endl; + std::ifstream fs(argv[i]); + std::string in; + load_file(in, fs); + fs.close(); + std::string out_name = std::string(argv[i]) + std::string(".htm"); + std::ofstream os(out_name.c_str()); + os << header_text; + // strip '<' and '>' first by outputting to a + // temporary string stream + std::ostringstream t(std::ios::out | std::ios::binary); + std::ostream_iterator oi(t); + boost::regex_merge(oi, in.begin(), in.end(), e2, pre_format, boost::match_default | boost::format_all); + // then output to final output stream + // adding syntax highlighting: + std::string s(t.str()); + std::ostream_iterator out(os); + boost::regex_merge(out, s.begin(), s.end(), e1, format_string, boost::match_default | boost::format_all); + os << footer_text; + os.close(); + } + } + catch(...) + { return -1; } + return 0; +} + +const char* pre_expression = "(<)|(>)|\\r"; +const char* pre_format = "(?1<)(?2>)"; + + +const char* expression_text = // preprocessor directives: index 1 + "(^[[:blank:]]*#(?:[^\\\\\\n]|\\\\[^\\n[:punct:][:word:]]*[\\n[:punct:][:word:]])*)|" + // comment: index 2 + "(//[^\\n]*|/\\*.*?\\*/)|" + // literals: index 3 + "\\<([+-]?(?:(?:0x[[:xdigit:]]+)|(?:(?:[[:digit:]]*\\.)?[[:digit:]]+(?:[eE][+-]?[[:digit:]]+)?))u?(?:(?:int(?:8|16|32|64))|L)?)\\>|" + // string literals: index 4 + "('(?:[^\\\\']|\\\\.)*'|\"(?:[^\\\\\"]|\\\\.)*\")|" + // keywords: index 5 + "\\<(__asm|__cdecl|__declspec|__export|__far16|__fastcall|__fortran|__import" + "|__pascal|__rtti|__stdcall|_asm|_cdecl|__except|_export|_far16|_fastcall" + "|__finally|_fortran|_import|_pascal|_stdcall|__thread|__try|asm|auto|bool" + "|break|case|catch|cdecl|char|class|const|const_cast|continue|default|delete" + "|do|double|dynamic_cast|else|enum|explicit|extern|false|float|for|friend|goto" + "|if|inline|int|long|mutable|namespace|new|operator|pascal|private|protected" + "|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_cast" + "|struct|switch|template|this|throw|true|try|typedef|typeid|typename|union|unsigned" + "|using|virtual|void|volatile|wchar_t|while)\\>" + ; + +const char* format_string = "(?1$&)" + "(?2$&)" + "(?3$&)" + "(?4$&)" + "(?5$&)"; + +const char* header_text = "\n\n" + "Auto-generated html formated source\n" + "\n" + "\n" + "\n" + "

\n
";
+
+const char* footer_text = "
\n\n\n"; + diff --git a/test/module/regex_replace_example.cpp b/test/module/regex_replace_example.cpp new file mode 100644 index 00000000..65d94623 --- /dev/null +++ b/test/module/regex_replace_example.cpp @@ -0,0 +1,145 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_replace_example.cpp + * VERSION see + * DESCRIPTION: regex_replace example: + * converts a C++ file to syntax highlighted HTML. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#include +#include +#include +#endif + +import boost.regex; + +// purpose: +// takes the contents of a file and transform to +// syntax highlighted code in html format + +boost::regex e1, e2; +extern const char* expression_text; +extern const char* format_string; +extern const char* pre_expression; +extern const char* pre_format; +extern const char* header_text; +extern const char* footer_text; + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, const char** argv) +{ + try{ + e1.assign(expression_text); + e2.assign(pre_expression); + for(int i = 1; i < argc; ++i) + { + std::cout << "Processing file " << argv[i] << std::endl; + std::ifstream fs(argv[i]); + std::string in; + load_file(in, fs); + fs.close(); + std::string out_name = std::string(argv[i]) + std::string(".htm"); + std::ofstream os(out_name.c_str()); + os << header_text; + // strip '<' and '>' first by outputting to a + // temporary string stream + std::ostringstream t(std::ios::out | std::ios::binary); + std::ostream_iterator oi(t); + boost::regex_replace(oi, in.begin(), in.end(), e2, pre_format, boost::match_default | boost::format_all); + // then output to final output stream + // adding syntax highlighting: + std::string s(t.str()); + std::ostream_iterator out(os); + boost::regex_replace(out, s.begin(), s.end(), e1, format_string, boost::match_default | boost::format_all); + os << footer_text; + os.close(); + } + } + catch(...) + { return -1; } + return 0; +} + +const char* pre_expression = "(<)|(>)|(&)|\\r"; +const char* pre_format = "(?1<)(?2>)(?3&)"; + + +const char* expression_text = // preprocessor directives: index 1 + "(^[[:blank:]]*#(?:[^\\\\\\n]|\\\\[^\\n[:punct:][:word:]]*[\\n[:punct:][:word:]])*)|" + // comment: index 2 + "(//[^\\n]*|/\\*.*?\\*/)|" + // literals: index 3 + "\\<([+-]?(?:(?:0x[[:xdigit:]]+)|(?:(?:[[:digit:]]*\\.)?[[:digit:]]+(?:[eE][+-]?[[:digit:]]+)?))u?(?:(?:int(?:8|16|32|64))|L)?)\\>|" + // string literals: index 4 + "('(?:[^\\\\']|\\\\.)*'|\"(?:[^\\\\\"]|\\\\.)*\")|" + // keywords: index 5 + "\\<(__asm|__cdecl|__declspec|__export|__far16|__fastcall|__fortran|__import" + "|__pascal|__rtti|__stdcall|_asm|_cdecl|__except|_export|_far16|_fastcall" + "|__finally|_fortran|_import|_pascal|_stdcall|__thread|__try|asm|auto|bool" + "|break|case|catch|cdecl|char|class|const|const_cast|continue|default|delete" + "|do|double|dynamic_cast|else|enum|explicit|extern|false|float|for|friend|goto" + "|if|inline|int|long|mutable|namespace|new|operator|pascal|private|protected" + "|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_cast" + "|struct|switch|template|this|throw|true|try|typedef|typeid|typename|union|unsigned" + "|using|virtual|void|volatile|wchar_t|while)\\>" + ; + +const char* format_string = "(?1$&)" + "(?2$&)" + "(?3$&)" + "(?4$&)" + "(?5$&)"; + +const char* header_text = "\n\n" + "Auto-generated html formated source\n" + "\n" + "\n" + "\n" + "

\n
";
+
+const char* footer_text = "
\n\n\n"; + + + + + + + + + + + + diff --git a/test/module/regex_search_example.cpp b/test/module/regex_search_example.cpp new file mode 100644 index 00000000..05fa08ee --- /dev/null +++ b/test/module/regex_search_example.cpp @@ -0,0 +1,135 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_search_example.cpp + * VERSION see + * DESCRIPTION: regex_search example: searches a cpp file for class definitions. + */ + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#endif + +import boost.regex; + +// purpose: +// takes the contents of a file in the form of a string +// and searches for all the C++ class definitions, storing +// their locations in a map of strings/int's + +typedef std::map > map_type; + +const char* re = + // possibly leading whitespace: + "^[[:space:]]*" + // possible template declaration: + "(template[[:space:]]*<[^;:{]+>[[:space:]]*)?" + // class or struct: + "(class|struct)[[:space:]]*" + // leading declspec macros etc: + "(" + "\\<\\w+\\>" + "(" + "[[:blank:]]*\\([^)]*\\)" + ")?" + "[[:space:]]*" + ")*" + // the class name + "(\\<\\w*\\>)[[:space:]]*" + // template specialisation parameters + "(<[^;:{]+>)?[[:space:]]*" + // terminate in { or : + "(\\{|:[^;\\{()]*\\{)"; + + +boost::regex expression(re); + +void IndexClasses(map_type& m, const std::string& file) +{ + std::string::const_iterator start, end; + start = file.begin(); + end = file.end(); + boost::match_results what; + boost::match_flag_type flags = boost::match_default; + while(boost::regex_search(start, end, what, expression, flags)) + { + // what[0] contains the whole string + // what[5] contains the class name. + // what[6] contains the template specialisation if any. + // add class name and position to map: + m[std::string(what[5].first, what[5].second) + std::string(what[6].first, what[6].second)] = + what[5].first - file.begin(); + // update search position: + start = what[0].second; + // update flags: + flags |= boost::match_prev_avail; + flags |= boost::match_not_bob; + } +} + + +using namespace std; + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, const char** argv) +{ + std::string text; + for(int i = 1; i < argc; ++i) + { + cout << "Processing file " << argv[i] << endl; + map_type m; + std::ifstream fs(argv[i]); + load_file(text, fs); + fs.close(); + IndexClasses(m, text); + cout << m.size() << " matches found" << endl; + map_type::iterator c, d; + c = m.begin(); + d = m.end(); + while(c != d) + { + cout << "class \"" << (*c).first << "\" found at index: " << (*c).second << endl; + ++c; + } + } + return 0; +} + + + + + + + + + diff --git a/test/module/regex_split_example_1.cpp b/test/module/regex_split_example_1.cpp new file mode 100644 index 00000000..905d2a02 --- /dev/null +++ b/test/module/regex_split_example_1.cpp @@ -0,0 +1,65 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_split_example_1.cpp + * VERSION see + * DESCRIPTION: regex_split example: split a string into tokens. + */ + + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#endif + +import boost.regex; + +unsigned tokenise(std::list& l, std::string& s) +{ + return boost::regex_split(std::back_inserter(l), s); +} + +using namespace std; + +int main(int argc, const char*[]) +{ + string s; + list l; + do{ + if(argc == 1) + { + cout << "Enter text to split (or \"quit\" to exit): "; + getline(cin, s); + if(s == "quit") break; + } + else + s = "This is a string of tokens"; + unsigned result = tokenise(l, s); + cout << result << " tokens found" << endl; + cout << "The remaining text is: \"" << s << "\"" << endl; + while(l.size()) + { + s = *(l.begin()); + l.pop_front(); + cout << s << endl; + } + }while(argc == 1); + return 0; +} + + diff --git a/test/module/regex_split_example_2.cpp b/test/module/regex_split_example_2.cpp new file mode 100644 index 00000000..b146291d --- /dev/null +++ b/test/module/regex_split_example_2.cpp @@ -0,0 +1,93 @@ +/* + * + * Copyright (c) 1998-2022 + * 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 regex_split_example_2.cpp + * VERSION see + * DESCRIPTION: regex_split example: spit out linked URL's. + */ + + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#include +#endif + +import boost.regex; + +boost::regex e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"", + boost::regex::normal | boost::regex::icase); + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + // + // attempt to grow string buffer to match file size, + // this doesn't always work... + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + // use logarithmic growth stategy, in case + // in_avail (above) returned zero: + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, char** argv) +{ + std::string s; + std::list l; + int i; + for(i = 1; i < argc; ++i) + { + std::cout << "Findings URL's in " << argv[i] << ":" << std::endl; + s.erase(); + std::ifstream is(argv[i]); + load_file(s, is); + is.close(); + boost::regex_split(std::back_inserter(l), s, e); + while(l.size()) + { + s = *(l.begin()); + l.pop_front(); + std::cout << s << std::endl; + } + } + // + // alternative method: + // split one match at a time and output direct to + // cout via ostream_iterator.... + // + for(i = 1; i < argc; ++i) + { + std::cout << "Findings URL's in " << argv[i] << ":" << std::endl; + s.erase(); + std::ifstream is(argv[i]); + load_file(s, is); + is.close(); + while(boost::regex_split(std::ostream_iterator(std::cout), s, e, boost::match_default, 1)) std::cout << std::endl; + } + + return 0; +} + + diff --git a/test/module/regex_token_iterator_eg_1.cpp b/test/module/regex_token_iterator_eg_1.cpp new file mode 100644 index 00000000..df38d02c --- /dev/null +++ b/test/module/regex_token_iterator_eg_1.cpp @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2003-2022 + * 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 regex_token_iterator_example_1.cpp + * VERSION see + * DESCRIPTION: regex_token_iterator example: split a string into tokens. + */ + + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#endif + +import boost.regex; + +using namespace std; + +int main(int argc, const char*[]) +{ + string s; + do{ + if(argc == 1) + { + cout << "Enter text to split (or \"quit\" to exit): "; + getline(cin, s); + if(s == "quit") break; + } + else + s = "This is a string of tokens"; + + boost::regex re("\\s+"); + boost::sregex_token_iterator i(s.begin(), s.end(), re, -1); + boost::sregex_token_iterator j; + + unsigned count = 0; + while(i != j) + { + cout << *i++ << endl; + count++; + } + cout << "There were " << count << " tokens found." << endl; + + }while(argc == 1); + return 0; +} + + diff --git a/test/module/regex_token_iterator_eg_2.cpp b/test/module/regex_token_iterator_eg_2.cpp new file mode 100644 index 00000000..8f1297bb --- /dev/null +++ b/test/module/regex_token_iterator_eg_2.cpp @@ -0,0 +1,96 @@ +/* + * + * Copyright (c) 2003-2022 + * 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 regex_token_iterator_example_2.cpp + * VERSION see + * DESCRIPTION: regex_token_iterator example: spit out linked URL's. + */ + + +#ifdef __cpp_lib_modules +import std; +#elif defined(MSVC_EXPERIMENTAL_STD_MODULE) +import std.core; +#else +#include +#include +#include +#endif + +import boost.regex; + +boost::regex e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"", + boost::regex::normal | boost::regex::icase); + +void load_file(std::string& s, std::istream& is) +{ + s.erase(); + if(is.bad()) return; + // + // attempt to grow string buffer to match file size, + // this doesn't always work... + s.reserve(static_cast(is.rdbuf()->in_avail())); + char c; + while(is.get(c)) + { + // use logarithmic growth stategy, in case + // in_avail (above) returned zero: + if(s.capacity() == s.size()) + s.reserve(s.capacity() * 3); + s.append(1, c); + } +} + +int main(int argc, char** argv) +{ + std::string s; + int i; + for(i = 1; i < argc; ++i) + { + std::cout << "Findings URL's in " << argv[i] << ":" << std::endl; + s.erase(); + std::ifstream is(argv[i]); + load_file(s, is); + is.close(); + boost::sregex_token_iterator i(s.begin(), s.end(), e, 1); + boost::sregex_token_iterator j; + while(i != j) + { + std::cout << *i++ << std::endl; + } + } + // + // alternative method: + // test the array-literal constructor, and split out the whole + // match as well as $1.... + // + for(i = 1; i < argc; ++i) + { + std::cout << "Findings URL's in " << argv[i] << ":" << std::endl; + s.erase(); + std::ifstream is(argv[i]); + load_file(s, is); + is.close(); + const int subs[] = {1, 0,}; + boost::sregex_token_iterator i(s.begin(), s.end(), e, subs); + boost::sregex_token_iterator j; + while(i != j) + { + std::cout << *i++ << std::endl; + } + } + + return 0; +} + +