#include <cerrno>
#include <iostream>
#include <ostream>
+#include <regex>
#include <string>
#include "base/check.h"
return didYouMean.getMatchAsString(inputTag);
}
+/**
+ * Select all tags from validTags that match the given (globbing) pattern.
+ * The pattern may contain `*` as wildcards. These are internally converted to
+ * `.*` and matched using std::regex. If no wildcards are present, regular
+ * string comparisons are used.
+ */
+std::vector<std::string> selectTags(const std::vector<std::string>& validTags, std::string pattern)
+{
+ bool isRegex = false;
+ size_t pos = 0;
+ while ((pos = pattern.find('*', pos)) != std::string::npos)
+ {
+ pattern.replace(pos, 1, ".*");
+ pos += 2;
+ isRegex = true;
+ }
+ std::vector<std::string> results;
+ if (isRegex)
+ {
+ std::regex re(pattern);
+ std::copy_if(validTags.begin(), validTags.end(), std::back_inserter(results),
+ [&re](const auto& tag){ return std::regex_match(tag, re); }
+ );
+ }
+ else
+ {
+ if (std::find(validTags.begin(), validTags.end(), pattern) != validTags.end())
+ {
+ results.emplace_back(pattern);
+ }
+ }
+ return results;
+}
+
} // namespace
OptionsHandler::OptionsHandler(Options* options) : d_options(options) { }
{
throw OptionException("trace tags not available in non-tracing builds");
}
- else if (!Configuration::isTraceTag(optarg))
+ auto tags = selectTags(Configuration::getTraceTags(), optarg);
+ if (tags.empty())
{
if (optarg == "help")
{
}
throw OptionException(
- std::string("trace tag ") + optarg + std::string(" not available.")
+ std::string("no trace tag matching ") + optarg + std::string(" was found.")
+ suggestTags(Configuration::getTraceTags(), optarg, {}));
}
- Trace.on(optarg);
+ for (const auto& tag: tags)
+ {
+ Trace.on(tag);
+ }
}
void OptionsHandler::enableDebugTag(const std::string& flag,
constexpr uint64_t swapCost = 0;
constexpr uint64_t substituteCost = 2;
constexpr uint64_t addCost = 1;
- constexpr uint64_t deleteCost = 3;
+ constexpr uint64_t deleteCost = 2;
constexpr uint64_t switchCaseCost = 0;
uint64_t len1 = a.size();
}
/** Magic numbers */
- constexpr uint64_t similarityThreshold = 7;
+ constexpr uint64_t similarityThreshold = 10;
constexpr uint64_t numMatchesThreshold = 10;
std::vector<std::pair<uint64_t,std::string>> scores;
// from here on, matches are not similar enough
if (score.first > similarityThreshold) break;
// from here on, matches are way worse than the best one
- if (score.first > min_score + 2) break;
+ if (score.first > min_score + 4) break;
// we already have enough matches
if (ret.size() >= numMatchesThreshold) break;
ret.push_back(score.second);