From 2bd5ec87055c48d7b48ad601f32368a37d5ecc2b Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 11 Dec 2023 07:07:34 -0600 Subject: [PATCH] Finish migrating std::regex to RE2 --- .../source/scwx/qt/manager/update_manager.cpp | 14 ++++--------- scwx-qt/source/scwx/qt/map/map_widget.cpp | 18 ++++++++--------- .../scwx/qt/settings/palette_settings.cpp | 7 +++---- test/source/scwx/qt/map/map_provider.test.cpp | 20 +++++++++---------- 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/update_manager.cpp b/scwx-qt/source/scwx/qt/manager/update_manager.cpp index 213354ec..08304263 100644 --- a/scwx-qt/source/scwx/qt/manager/update_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/update_manager.cpp @@ -2,10 +2,10 @@ #include #include -#include #include #include +#include namespace scwx { @@ -61,16 +61,10 @@ std::string UpdateManager::latest_version() const std::string UpdateManager::Impl::GetVersionString(const std::string& releaseName) { - static const std::regex re {"\\d+\\.\\d+\\.\\d+"}; - std::string versionString {}; - std::smatch m; + static constexpr LazyRE2 re = {"(\\d+\\.\\d+\\.\\d+)"}; + std::string versionString {}; - std::regex_search(releaseName, m, re); - - if (!m.empty()) - { - versionString = m[0].str(); - } + RE2::PartialMatch(releaseName, *re, &versionString); return versionString; } diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index a897748b..ebef32e7 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -33,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -769,14 +769,14 @@ std::string MapWidgetImpl::FindMapSymbologyLayer() const std::string layer = qlayer.toStdString(); // Draw below layers defined in map style - auto it = std::find_if( - currentStyle_->drawBelow_.cbegin(), - currentStyle_->drawBelow_.cend(), - [&layer](const std::string& styleLayer) -> bool - { - std::regex re {styleLayer, std::regex_constants::icase}; - return std::regex_match(layer, re); - }); + auto it = std::find_if(currentStyle_->drawBelow_.cbegin(), + currentStyle_->drawBelow_.cend(), + [&layer](const std::string& styleLayer) -> bool + { + // Perform case-insensitive matching + RE2 re {"(?i)" + styleLayer}; + return RE2::FullMatch(layer, re); + }); if (it != currentStyle_->drawBelow_.cend()) { diff --git a/scwx-qt/source/scwx/qt/settings/palette_settings.cpp b/scwx-qt/source/scwx/qt/settings/palette_settings.cpp index 8133a452..dcf58f2e 100644 --- a/scwx-qt/source/scwx/qt/settings/palette_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/palette_settings.cpp @@ -2,10 +2,9 @@ #include #include -#include - #include #include +#include namespace scwx { @@ -134,8 +133,8 @@ class PaletteSettings::Impl bool PaletteSettings::Impl::ValidateColor(const std::string& value) { - static const std::regex re {"#[0-9A-Za-z]{8}"}; - return std::regex_match(value, re); + static constexpr LazyRE2 re = {"#[0-9A-Fa-f]{8}"}; + return RE2::FullMatch(value, *re); } PaletteSettings::PaletteSettings() : diff --git a/test/source/scwx/qt/map/map_provider.test.cpp b/test/source/scwx/qt/map/map_provider.test.cpp index f3883992..8b330de9 100644 --- a/test/source/scwx/qt/map/map_provider.test.cpp +++ b/test/source/scwx/qt/map/map_provider.test.cpp @@ -2,13 +2,12 @@ #include #include -#include - #include #include #include #include +#include namespace scwx { @@ -108,14 +107,15 @@ TEST_P(ByMapProviderTest, MapProviderLayers) const std::string layer = qlayer.toStdString(); // Draw below layers defined in map style - auto it = std::find_if( - mapStyle.drawBelow_.cbegin(), - mapStyle.drawBelow_.cend(), - [&layer](const std::string& styleLayer) -> bool - { - std::regex re {styleLayer, std::regex_constants::icase}; - return std::regex_match(layer, re); - }); + auto it = + std::find_if(mapStyle.drawBelow_.cbegin(), + mapStyle.drawBelow_.cend(), + [&layer](const std::string& styleLayer) -> bool + { + // Perform case insensitive matching + RE2 re {"(?i)" + styleLayer}; + return RE2::FullMatch(layer, re); + }); if (it != mapStyle.drawBelow_.cend()) {