Skip to content

Commit

Permalink
Finish migrating std::regex to RE2
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulat committed Dec 11, 2023
1 parent 2757c51 commit 2bd5ec8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
14 changes: 4 additions & 10 deletions scwx-qt/source/scwx/qt/manager/update_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include <scwx/util/logger.hpp>

#include <mutex>
#include <regex>

#include <boost/json.hpp>
#include <cpr/cpr.h>
#include <re2/re2.h>

namespace scwx
{
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 9 additions & 9 deletions scwx-qt/source/scwx/qt/map/map_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <scwx/util/logger.hpp>
#include <scwx/util/time.hpp>

#include <regex>
#include <set>

#include <backends/imgui_impl_opengl3.h>
Expand All @@ -33,6 +32,7 @@
#include <boost/uuid/random_generator.hpp>
#include <fmt/format.h>
#include <imgui.h>
#include <re2/re2.h>
#include <QApplication>
#include <QColor>
#include <QDebug>
Expand Down Expand Up @@ -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())
{
Expand Down
7 changes: 3 additions & 4 deletions scwx-qt/source/scwx/qt/settings/palette_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#include <scwx/qt/settings/settings_variable.hpp>
#include <scwx/qt/util/color.hpp>

#include <regex>

#include <boost/gil.hpp>
#include <fmt/format.h>
#include <re2/re2.h>

namespace scwx
{
Expand Down Expand Up @@ -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() :
Expand Down
20 changes: 10 additions & 10 deletions test/source/scwx/qt/map/map_provider.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
#include <scwx/util/environment.hpp>
#include <scwx/util/logger.hpp>

#include <regex>

#include <QCoreApplication>
#include <QMapLibreGL/QMapLibreGL>
#include <QTimer>

#include <gtest/gtest.h>
#include <re2/re2.h>

namespace scwx
{
Expand Down Expand Up @@ -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())
{
Expand Down

0 comments on commit 2bd5ec8

Please sign in to comment.