Add wxRegEx::GetLibraryVersionInfo()

This allows to check the version of PCRE used.
This commit is contained in:
Vadim Zeitlin
2021-07-17 20:28:39 +02:00
parent dbe0950384
commit 3415325f4f
4 changed files with 34 additions and 0 deletions

View File

@@ -16,6 +16,7 @@
#if wxUSE_REGEX #if wxUSE_REGEX
#include "wx/string.h" #include "wx/string.h"
#include "wx/versioninfo.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
@@ -148,6 +149,9 @@ public:
// return the extended RE corresponding to the given basic RE // return the extended RE corresponding to the given basic RE
static wxString ConvertFromBasic(const wxString& bre); 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 // dtor not virtual, don't derive from this class
~wxRegEx(); ~wxRegEx();

View File

@@ -360,5 +360,17 @@ public:
@since 3.1.6 @since 3.1.6
*/ */
static wxString ConvertFromBasic(const wxString& bre); 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();
}; };

View File

@@ -1494,4 +1494,13 @@ wxString wxRegEx::QuoteMeta(const wxString& str)
return strEscaped; 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 #endif // wxUSE_REGEX

View File

@@ -196,4 +196,13 @@ TEST_CASE("wxRegEx::Unicode", "[regex][unicode]")
CHECK( re.GetMatch(cyrillicSmallA) == cyrillicSmallA ); 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 #endif // wxUSE_REGEX