diff --git a/include/wx/regex.h b/include/wx/regex.h index 536fbc2bf2..e94714a055 100644 --- a/include/wx/regex.h +++ b/include/wx/regex.h @@ -16,6 +16,7 @@ #if wxUSE_REGEX #include "wx/string.h" +#include "wx/versioninfo.h" // ---------------------------------------------------------------------------- // constants @@ -148,6 +149,9 @@ public: // return the extended RE corresponding to the given basic RE static wxString ConvertFromBasic(const wxString& bre); + // return version information for the underlying regex library + static wxVersionInfo GetLibraryVersionInfo(); + // dtor not virtual, don't derive from this class ~wxRegEx(); diff --git a/interface/wx/regex.h b/interface/wx/regex.h index 711cb3d673..2578fd9723 100644 --- a/interface/wx/regex.h +++ b/interface/wx/regex.h @@ -360,5 +360,17 @@ public: @since 3.1.6 */ static wxString ConvertFromBasic(const wxString& bre); + + /** + Return the version of PCRE used. + + The returned wxVersionInfo object currently always has its micro + version component set to 0, as PCRE uses only major and minor version + components. Its description component contains the version number, + release date and, for pre-release PCRE versions, a mention of it. + + @since 3.1.6 + */ + static wxVersionInfo GetLibraryVersionInfo(); }; diff --git a/src/common/regex.cpp b/src/common/regex.cpp index 4a772141ec..7deddcbb02 100644 --- a/src/common/regex.cpp +++ b/src/common/regex.cpp @@ -1494,4 +1494,13 @@ wxString wxRegEx::QuoteMeta(const wxString& str) return strEscaped; } +/* static */ +wxVersionInfo wxRegEx::GetLibraryVersionInfo() +{ + wxRegChar buf[64]; + pcre2_config(PCRE2_CONFIG_VERSION, buf); + + return wxVersionInfo("PCRE2", PCRE2_MAJOR, PCRE2_MINOR, 0, buf); +} + #endif // wxUSE_REGEX diff --git a/tests/regex/wxregextest.cpp b/tests/regex/wxregextest.cpp index 4bc6463f06..ce5721d4b0 100644 --- a/tests/regex/wxregextest.cpp +++ b/tests/regex/wxregextest.cpp @@ -196,4 +196,13 @@ TEST_CASE("wxRegEx::Unicode", "[regex][unicode]") CHECK( re.GetMatch(cyrillicSmallA) == cyrillicSmallA ); } +// This pseudo test can be used just to see the version of PCRE being used. +TEST_CASE("wxRegEx::GetLibraryVersionInfo", "[.]") +{ + const wxVersionInfo ver = wxRegEx::GetLibraryVersionInfo(); + WARN("Using " << ver.GetName() << " " << ver.GetDescription() + << " (major=" << ver.GetMajor() + << ", minor=" << ver.GetMinor() << ")"); +} + #endif // wxUSE_REGEX