Skip to content

Commit 0bafefc

Browse files
authored
Merge pull request etr#141 from etr/reduce_regex_usage
Reduce regex usage
2 parents e471d21 + 8083b79 commit 0bafefc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/http_utils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ std::vector<std::string> http_utils::tokenize_url(
223223

224224
std::string http_utils::standardize_url(const std::string& url)
225225
{
226-
std::string n_url = string_utilities::regex_replace(url, "(\\/)+", "/");
226+
std::string n_url = url;
227+
228+
std::string::iterator new_end = std::unique(n_url.begin(), n_url.end(), [](char a, char b) { return (a == b) && (a == '/'); });
229+
n_url.erase(new_end, n_url.end());
230+
227231
std::string::size_type n_url_length = n_url.length();
228232

229233
std::string result;

test/unit/http_utils_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, standardize_url)
128128
url = "/abc/pqr", result = "";
129129
result = http::http_utils::standardize_url(url);
130130
LT_CHECK_EQ(result, "/abc/pqr");
131+
132+
url = "/abc//pqr", result = "";
133+
result = http::http_utils::standardize_url(url);
134+
LT_CHECK_EQ(result, "/abc/pqr");
131135
LT_END_AUTO_TEST(standardize_url)
132136

133137
LT_BEGIN_AUTO_TEST(http_utils_suite, ip_to_str)

0 commit comments

Comments
 (0)