-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core-clp): get_entry_matching_value should handle ignore-case properly. #690
base: main
Are you sure you want to change the base?
Changes from all commits
327c317
b4fdba2
8a515f8
aaac6a0
61dea57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,9 +82,9 @@ class DictionaryReader { | |||||
* Gets the entry exactly matching the given search string | ||||||
* @param search_string | ||||||
* @param ignore_case | ||||||
* @return nullptr if an exact match is not found, the entry otherwise | ||||||
* @return a (possibly empty) vector of entries | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kirkrodrigues how about
Suggested change
|
||||||
*/ | ||||||
EntryType const* | ||||||
std::vector<EntryType const*> | ||||||
get_entry_matching_value(std::string const& search_string, bool ignore_case) const; | ||||||
/** | ||||||
* Gets the entries that match a given wildcard string | ||||||
|
@@ -233,26 +233,30 @@ std::string const& DictionaryReader<DictionaryIdType, EntryType>::get_value(Dict | |||||
} | ||||||
|
||||||
template <typename DictionaryIdType, typename EntryType> | ||||||
EntryType const* DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value( | ||||||
std::vector<EntryType const*> | ||||||
DictionaryReader<DictionaryIdType, EntryType>::get_entry_matching_value( | ||||||
std::string const& search_string, | ||||||
bool ignore_case | ||||||
) const { | ||||||
std::vector<EntryType const*> entries; | ||||||
if (false == ignore_case) { | ||||||
for (auto const& entry : m_entries) { | ||||||
if (entry.get_value() == search_string) { | ||||||
return &entry; | ||||||
entries.push_back(&entry); | ||||||
aestriplex marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// early exit for case sensitive branch | ||||||
return entries; | ||||||
} | ||||||
} | ||||||
} else { | ||||||
auto const& search_string_uppercase = boost::algorithm::to_upper_copy(search_string); | ||||||
for (auto const& entry : m_entries) { | ||||||
if (boost::algorithm::to_upper_copy(entry.get_value()) == search_string_uppercase) { | ||||||
return &entry; | ||||||
entries.push_back(&entry); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return nullptr; | ||||||
return entries; | ||||||
} | ||||||
|
||||||
template <typename DictionaryIdType, typename EntryType> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,6 +376,47 @@ TEST_CASE("EncodedVariableInterpreter", "[EncodedVariableInterpreter]") { | |
)); | ||
} | ||
|
||
SECTION("Test multiple metching values") { | ||
char const cVarDictPath[] = "var.dict"; | ||
char const cVarSegmentIndexPath[] = "var.segindex"; | ||
vector<string> var_strs = {"python2.7.3", "Python2.7.3", "PyThOn2.7.3", "PYTHON2.7.3"}; | ||
clp::VariableDictionaryWriter var_dict_writer; | ||
aestriplex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var_dict_writer.open(cVarDictPath, cVarSegmentIndexPath, cVariableDictionaryIdMax); | ||
|
||
vector<encoded_variable_t> encoded_vars; | ||
aestriplex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
vector<clp::variable_dictionary_id_t> var_ids; | ||
clp::LogTypeDictionaryEntry logtype_dict_entry; | ||
string const msg_template = "here is a string with a dictionary var: "; | ||
|
||
for (auto const& var_str : var_strs) { | ||
EncodedVariableInterpreter::encode_and_add_to_dictionary( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of directly using the var_strs as msg argument for encode_and_add_to_dictionary, can we construct a message with a dummy log type? I guess what you can do can be similar to
|
||
msg_template + var_str, | ||
logtype_dict_entry, | ||
var_dict_writer, | ||
encoded_vars, | ||
var_ids | ||
); | ||
} | ||
var_dict_writer.close(); | ||
|
||
clp::VariableDictionaryReader var_dict_reader; | ||
var_dict_reader.open(cVarDictPath, cVarSegmentIndexPath); | ||
var_dict_reader.read_new_entries(); | ||
|
||
REQUIRE(var_dict_reader.get_entry_matching_value(var_strs.at(0), true).size() | ||
== var_strs.size()); | ||
REQUIRE(var_dict_reader.get_entry_matching_value(var_strs.at(0), false).size() == 1); | ||
|
||
var_dict_reader.close(); | ||
|
||
// Clean-up | ||
int retval = unlink(cVarDictPath); | ||
REQUIRE(0 == retval); | ||
retval = unlink(cVarSegmentIndexPath); | ||
REQUIRE(0 == retval); | ||
} | ||
|
||
SECTION("Test encoding and decoding") { | ||
string msg; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should update the docstring.
@kirkrodrigues any suggestions on how to account for multiple possible matching? "entry(entries)"?