Skip to content

Commit 5ee1a99

Browse files
committed
switch to std::regex
1 parent 9c286da commit 5ee1a99

File tree

11 files changed

+17
-42
lines changed

11 files changed

+17
-42
lines changed

Diff for: CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ include(external/curl.cmake)
6464
include(external/yaml_cpp.cmake)
6565
include(external/toml11.cmake)
6666
include(external/ghc.cmake)
67-
include(external/re2.cmake)
6867
include(external/digestpp.cmake)
6968

7069
# Define and install library

Diff for: cmake_modules/fdpapiConfig.cmake.in

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ find_package(digestpp)
88
find_package(ghc_filesystem)
99
find_package(jsoncpp)
1010
find_package(yaml-cpp)
11-
find_package(re2)
1211

1312
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
1413

Diff for: external/re2.cmake

-7
This file was deleted.

Diff for: include/fdp/objects/config.hxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <string>
1616
#include <ghc/filesystem.hpp>
1717
#include <yaml-cpp/yaml.h>
18-
#include <re2/re2.h>
1918
#include <map>
19+
#include <regex>
2020
#include <ghc/filesystem.hpp>
2121
#include <stdio.h>
2222

Diff for: include/fdp/objects/metadata.hxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <sstream>
1919
#include <random>
2020
#include <chrono>
21-
#include <re2/re2.h>
21+
#include <regex>
2222

2323
#include "digestpp/digestpp.hpp"
2424

Diff for: include/fdp/registry/api.hxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <iterator>
1919
#include <json/reader.h>
2020
#include <map>
21-
#include <re2/re2.h>
21+
#include <regex>
2222
#include <string>
2323
#include <vector>
2424

Diff for: src/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ target_link_libraries(fdpapi PRIVATE toml11::toml11)
5454
target_link_libraries(fdpapi PRIVATE digestpp::digestpp)
5555
target_link_libraries(fdpapi PRIVATE CURL::libcurl)
5656
target_link_libraries(fdpapi PRIVATE yaml-cpp)
57-
target_link_libraries(fdpapi PRIVATE re2::re2)
5857
target_link_libraries(fdpapi PRIVATE ghcFilesystem::ghc_filesystem)
5958
if(BUILD_SHARED_LIBS)
6059
target_link_libraries(fdpapi PRIVATE jsoncpp_lib)

Diff for: src/objects/config.cxx

+1-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ void FairDataPipeline::Config::initialise(RESTAPI api_location) {
326326
Json::Value j_code_repo_root = api_->post("storage_root", repo_storage_root_value_, token_);
327327
this->code_repo_storage_root_ = ApiObject::from_json( j_code_repo_root );
328328

329-
std::string repo_storage_path_ = meta_data_()["remote_repo"].as<std::string>();
330-
RE2::GlobalReplace(&repo_storage_path_, repo_storage_root_value_["root"].asString(), "");
329+
std::string repo_storage_path_ = std::regex_replace(meta_data_()["remote_repo"].as<std::string>(), std::regex(repo_storage_root_value_["root"].asString()), "");
331330

332331
Json::Value repo_storage_location_value_;
333332
repo_storage_location_value_["hash"] = meta_data_()["latest_commit"].as<std::string>();

Diff for: src/objects/metadata.cxx

+2-6
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,11 @@ std::string current_time_stamp(bool file_name) {
6464
}
6565

6666
std::string remove_local_from_root(const std::string &root){
67-
std::string result = root;
68-
RE2::GlobalReplace(&result, "file:\\/\\/", "");
69-
return result;
67+
return std::regex_replace(root, std::regex(std::string("file:\\/\\/")), "");
7068
}
7169

7270
std::string remove_backslash_from_path(const std::string &path){
73-
std::string result = path;
74-
RE2::GlobalReplace(&result, "\\\\", "/");
75-
return result;
71+
return std::regex_replace(path, std::regex(std::string("\\\\")), "/");
7672
}
7773

7874
bool file_exists( const std::string &Filename )

Diff for: src/registry/api.cxx

+11-20
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ CURL *API::setup_download_session_(const ghc::filesystem::path &addr_path,
9595

9696
Json::Value API::get_request(const ghc::filesystem::path &addr_path,
9797
long expected_response, std::string token) {
98-
std::string addr_path_ = addr_path.string();
99-
RE2::GlobalReplace(&addr_path_, "\\\\", "/");
98+
std::string addr_path_ = std::regex_replace(addr_path.string(), std::regex(std::string("\\\\")), "/");
10099
return get_request(addr_path_, expected_response);
101100
}
102101

@@ -168,8 +167,6 @@ std::string API::json_to_query_string(Json::Value &json_value) {
168167
std::string rtn = "?";
169168
// Need to remove the api address from any values using regex
170169
std::string regex_string = "(" + url_root_ + ")([A-Za-z_]+)\\/([0-9]+)\\/";
171-
std::string match1, match2;
172-
int match3;
173170
// Check the json value is not empty
174171
if (json_value.size() > 0) {
175172
// Iterate through the json keys
@@ -182,20 +179,18 @@ std::string API::json_to_query_string(Json::Value &json_value) {
182179
i++) {
183180
// add the key and value to the return string after removing the api
184181
// address with regex
185-
std::string str = json_value.get(key, "")[i].asString();
186-
if(RE2::FullMatch(str, regex_string, &match1, &match2, &match3)){
187-
str = std::to_string(match3);
188-
}
189-
rtn += key + "=" + str + "&";
182+
rtn += key + "=" +
183+
std::regex_replace(json_value.get(key, "")[i].asString(),
184+
std::regex(regex_string), "$3") +
185+
"&";
190186
}
191187
} else {
192188
// if it's not an array add the key and value to the return string after
193189
// removing the api address with regex
194-
std::string str = json_value.get(key, "").asString();
195-
if(RE2::FullMatch(str, regex_string, &match1, &match2, &match3)){
196-
str = std::to_string(match3);
197-
}
198-
rtn += key + "=" + str + "&";
190+
rtn += key + "=" +
191+
std::regex_replace(json_value.get(key, "").asString(),
192+
std::regex(regex_string), "$3") +
193+
"&";
199194
}
200195
}
201196
}
@@ -205,9 +200,7 @@ std::string API::json_to_query_string(Json::Value &json_value) {
205200

206201
std::string API::escape_space(std::string &str) {
207202
// Using regex replace space with html character (%20)
208-
std::string result = str;
209-
RE2::GlobalReplace(&result, " ", "%20");
210-
return result;
203+
return std::string(std::regex_replace(str, std::regex(" "), "%20"));
211204
}
212205

213206
Json::Value API::post(std::string addr_path, Json::Value &post_data,
@@ -229,9 +222,7 @@ Json::Value API::post_file_type(Json::Value &post_data, const std::string &token
229222
logger::get_logger()->error() << "Error: Post Data does not contain a file extension";
230223
throw rest_apiquery_error("Failed to post file_type");
231224
}
232-
std::string extension = post_data["extension"].asString();
233-
RE2::GlobalReplace(&extension, ".", "");
234-
post_data["extension"] = extension;
225+
post_data["extension"] = regex_replace(post_data["name"].asString(), std::regex("."), "");
235226
Json::Value _file_type_query;
236227
_file_type_query["extension"] = post_data["extension"];
237228
Json::Value _file_type_exists = get_by_json_query("file_type", _file_type_query);

Diff for: test/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ target_link_libraries(fdpapi-tests PRIVATE gtest gtest_main)
6464

6565
target_link_libraries(fdpapi-tests PRIVATE toml11::toml11)
6666
target_link_libraries(fdpapi-tests PRIVATE digestpp::digestpp)
67-
target_link_libraries(fdpapi-tests PRIVATE re2::re2)
6867
target_link_libraries(fdpapi-tests PRIVATE CURL::libcurl)
6968
target_link_libraries(fdpapi-tests PRIVATE yaml-cpp)
7069
if(BUILD_SHARED_LIBS)

0 commit comments

Comments
 (0)