Skip to content

Commit add4e47

Browse files
committed
Merge branch 'main' into modernize-zlib-install
2 parents 020151c + 8dd1abb commit add4e47

File tree

15 files changed

+131
-40
lines changed

15 files changed

+131
-40
lines changed

components/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ if(CLP_NEED_BOOST)
156156
if(CLP_USE_STATIC_LIBS)
157157
set(Boost_USE_STATIC_LIBS ON)
158158
endif()
159-
find_package(Boost 1.81 REQUIRED iostreams program_options filesystem system regex url)
159+
find_package(Boost 1.89 REQUIRED iostreams program_options filesystem regex url)
160160
if(Boost_FOUND)
161161
message(STATUS "Found Boost ${Boost_VERSION}")
162162
else()

components/core/src/clp/GrepCore.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <vector>
1111

1212
#include <log_surgeon/Lexer.hpp>
13+
#include <string_utils/constants.hpp>
1314
#include <string_utils/string_utils.hpp>
1415

1516
#include "Defs.h"
@@ -162,15 +163,16 @@ std::optional<Query> GrepCore::process_raw_query(
162163
bool is_var;
163164
std::string search_string_for_sub_queries{search_string};
164165
if (use_heuristic) {
165-
// Replace '?' wildcards with '*' wildcards since we currently have no support for
166+
// Replace unescaped '?' wildcards with '*' wildcards since we currently have no support for
166167
// generating sub-queries with '?' wildcards. The final wildcard match on the decompressed
167168
// message uses the original wildcards, so correctness will be maintained.
168-
std::replace(
169-
search_string_for_sub_queries.begin(),
170-
search_string_for_sub_queries.end(),
171-
'?',
172-
'*'
169+
string_utils::replace_unescaped_char(
170+
string_utils::cWildcardEscapeChar,
171+
string_utils::cSingleCharWildcard,
172+
string_utils::cZeroOrMoreCharsWildcard,
173+
search_string_for_sub_queries
173174
);
175+
174176
// Clean-up in case any instances of "?*" or "*?" were changed into "**"
175177
search_string_for_sub_queries
176178
= string_utils::clean_up_wildcard_search_string(search_string_for_sub_queries);

components/core/src/clp/regex_utils/constants.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ constexpr size_t cCharBitarraySize = 128;
2424
return bit_array;
2525
}
2626

27-
// Wildcard meta characters
28-
constexpr char cZeroOrMoreCharsWildcard{'*'};
29-
constexpr char cSingleCharWildcard{'?'};
30-
3127
// Regex meta characters
3228
constexpr char cRegexZeroOrMore{'*'};
3329
constexpr char cRegexOneOrMore{'+'};

components/core/src/clp/regex_utils/regex_translation_utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string>
66
#include <string_view>
77

8+
#include <string_utils/constants.hpp>
89
#include <string_utils/string_utils.hpp>
910
#include <ystdlib/error_handling/Result.hpp>
1011

@@ -13,6 +14,8 @@
1314
#include "RegexToWildcardTranslatorConfig.hpp"
1415

1516
namespace clp::regex_utils {
17+
using clp::string_utils::cSingleCharWildcard;
18+
using clp::string_utils::cZeroOrMoreCharsWildcard;
1619
using clp::string_utils::is_alphabet;
1720
using std::optional;
1821
using std::string;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef CLP_STRING_UTILS_CONSTANTS_HPP
2+
#define CLP_STRING_UTILS_CONSTANTS_HPP
3+
4+
namespace clp::string_utils {
5+
// Wildcard meta characters
6+
constexpr char cZeroOrMoreCharsWildcard{'*'};
7+
constexpr char cSingleCharWildcard{'?'};
8+
9+
constexpr char cWildcardEscapeChar{'\\'};
10+
} // namespace clp::string_utils
11+
12+
#endif // CLP_STRING_UTILS_CONSTANTS_HPP

components/core/src/clp/string_utils/string_utils.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,28 @@ string replace_characters(
113113
return new_value;
114114
}
115115

116+
auto replace_unescaped_char(
117+
char const escape_char,
118+
char const from_char,
119+
char const to_char,
120+
std::string& str
121+
) -> void {
122+
bool escaped{false};
123+
124+
auto should_replace_char = [&](char c) -> bool {
125+
if (escaped) {
126+
escaped = false;
127+
} else if (escape_char == c) {
128+
escaped = true;
129+
} else if (from_char == c) {
130+
return true;
131+
}
132+
return false;
133+
};
134+
135+
std::replace_if(str.begin(), str.end(), should_replace_char, to_char);
136+
}
137+
116138
void to_lower(string& str) {
117139
std::transform(str.cbegin(), str.cend(), str.begin(), [](unsigned char c) {
118140
return std::tolower(c);

components/core/src/clp/string_utils/string_utils.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ std::string replace_characters(
5555
bool escape
5656
);
5757

58+
/**
59+
* Replace unescaped instances of `from_char` with `to_char` in `str`.
60+
*
61+
* NOTE: `from_char` and `escape_char` must not be the same character. If they are, the function's
62+
* behaviour is undefined.
63+
*
64+
* @param escape_char The character used for escaping
65+
* @param from_char
66+
* @param to_char
67+
* @param str String in which to replace the characters
68+
*/
69+
auto replace_unescaped_char(char escape_char, char from_char, char to_char, std::string& str)
70+
-> void;
71+
5872
/**
5973
* Converts a string to lowercase
6074
* @param str

components/core/src/reducer/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ if(CLP_BUILD_EXECUTABLES)
4444
target_link_libraries(reducer-server
4545
PRIVATE
4646
Boost::program_options
47-
Boost::system
4847
clp::string_utils
4948
fmt::fmt
5049
${MONGOCXX_TARGET}

components/core/tests/test-string_utils.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
#include <boost/foreach.hpp>
44
#include <boost/range/combine.hpp>
55
#include <catch2/catch.hpp>
6+
#include <string_utils/constants.hpp>
67
#include <string_utils/string_utils.hpp>
78

89
using clp::string_utils::clean_up_wildcard_search_string;
910
using clp::string_utils::convert_string_to_int;
11+
using clp::string_utils::cSingleCharWildcard;
12+
using clp::string_utils::cWildcardEscapeChar;
13+
using clp::string_utils::cZeroOrMoreCharsWildcard;
14+
using clp::string_utils::replace_unescaped_char;
1015
using clp::string_utils::wildcard_match_unsafe;
1116
using clp::string_utils::wildcard_match_unsafe_case_sensitive;
1217
using std::chrono::duration;
@@ -22,6 +27,57 @@ TEST_CASE("to_lower", "[to_lower]") {
2227
REQUIRE(str == "test123test");
2328
}
2429

30+
TEST_CASE("replace_unescaped_char", "[replace_unescaped_char]") {
31+
auto check = [](char escape_char,
32+
char from_char,
33+
char to_char,
34+
std::string in,
35+
std::string const& expected) {
36+
replace_unescaped_char(escape_char, from_char, to_char, in);
37+
REQUIRE((in == expected));
38+
};
39+
40+
SECTION("Conventional escape and wildcard characters") {
41+
auto [str, expected] = GENERATE(
42+
as<std::pair<string, string>>{},
43+
44+
// Replacements with no escape chars present
45+
std::pair{R"(a?b)", R"(a*b)"},
46+
std::pair{R"(?leading)", R"(*leading)"},
47+
std::pair{R"(trailing?)", R"(trailing*)"},
48+
std::pair{R"(multiple??q)", R"(multiple**q)"},
49+
50+
// Replacements with escape chars present
51+
std::pair{R"(a\\?b)", R"(a\\*b)"},
52+
std::pair{R"(\\?abc)", R"(\\*abc)"},
53+
std::pair{R"(abc\\?)", R"(abc\\*)"},
54+
55+
// No replacements with escape chars present
56+
std::pair{R"(a\?b)", R"(a\?b)"},
57+
std::pair{R"(\?abc)", R"(\?abc)"},
58+
std::pair{R"(abc\?)", R"(abc\?)"},
59+
60+
// Mixed
61+
std::pair{R"(a\\?b a\?b a?b)", R"(a\\*b a\?b a*b)"},
62+
std::pair{R"(\\?abc \?abc a?b)", R"(\\*abc \?abc a*b)"},
63+
std::pair{R"(abc\\? abc\? a?b)", R"(abc\\* abc\? a*b)"},
64+
65+
// Additional edge cases
66+
std::pair{R"(no change)", R"(no change)"},
67+
std::pair{R"()", R"()"},
68+
std::pair{R"(\)", R"(\)"},
69+
std::pair{R"(\\)", R"(\\)"},
70+
std::pair{R"(?\)", R"(*\)"}
71+
);
72+
73+
check(cWildcardEscapeChar, cSingleCharWildcard, cZeroOrMoreCharsWildcard, str, expected);
74+
}
75+
76+
SECTION("Unconventional escape and wildcard characters") {
77+
check('q', 'w', 'e', R"(aqqwb aqwb awb)", R"(aqqeb aqwb aeb)");
78+
}
79+
}
80+
2581
TEST_CASE("clean_up_wildcard_search_string", "[clean_up_wildcard_search_string]") {
2682
string str;
2783

components/core/tools/scripts/lib_install/centos-stream-9/install-packages-from-source.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
1010
lib_install_scripts_dir="${script_dir}/.."
1111

1212
# NOTE: The remaining installation scripts depend on boost, so we install it beforehand.
13-
"${lib_install_scripts_dir}/install-boost.sh" 1.87.0
13+
"${lib_install_scripts_dir}/install-boost.sh" 1.89.0
1414

1515
"${lib_install_scripts_dir}/liblzma.sh" 5.8.1
1616
"${lib_install_scripts_dir}/msgpack.sh" 7.0.0

0 commit comments

Comments
 (0)