Author: zturner
Date: Sun Nov 6 18:07:25 2016
New Revision: 286088
URL: http://llvm.org/viewvc/llvm-project?rev=286088&view=rev
Log:
Convert some helper functions to use StringRef.
I will probably submit a lot of small trivial changes
like this over the coming weeks. The end goal is to
convert Options::SetOptionValue to take the option arg
as a StringRef, but doing so in one pass would be a huge
mess of disparate changes just to satisfy the compiler,
and with a high risk of breaking. So I'm going to do
this in small pieces, changing seemingly random things
here and there until the final change to the signature
of Options::SetOptionValue() can be done trivially.
Modified:
lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
Modified:
lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
URL:
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp?rev=286088&r1=286087&r2=286088&view=diff
==
---
lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
(original)
+++
lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
Sun Nov 6 18:07:25 2016
@@ -562,7 +562,7 @@ public:
break;
case 'f':
- return ParseFilterRule(option_arg);
+ return ParseFilterRule(option_strref);
case 'i':
m_include_info_level = true;
@@ -664,10 +664,10 @@ public:
bool GetBroadcastEvents() const { return m_broadcast_events; }
private:
- Error ParseFilterRule(const char *rule_text_cstr) {
+ Error ParseFilterRule(llvm::StringRef rule_text) {
Error error;
-if (!rule_text_cstr || !rule_text_cstr[0]) {
+if (rule_text.empty()) {
error.SetErrorString("invalid rule_text");
return error;
}
@@ -692,14 +692,12 @@ private:
// match {exact-match-text} |
// regex {search-regex}
-const std::string rule_text(rule_text_cstr);
-
// Parse action.
auto action_end_pos = rule_text.find(" ");
if (action_end_pos == std::string::npos) {
error.SetErrorStringWithFormat("could not parse filter rule "
"action from \"%s\"",
- rule_text_cstr);
+ rule_text.str().c_str());
return error;
}
auto action = rule_text.substr(0, action_end_pos);
@@ -709,8 +707,7 @@ private:
else if (action == "reject")
accept = false;
else {
- error.SetErrorString("filter action must be \"accept\" or "
- "\"deny\"");
+ error.SetErrorString("filter action must be \"accept\" or \"deny\"");
return error;
}
@@ -719,7 +716,7 @@ private:
if (attribute_end_pos == std::string::npos) {
error.SetErrorStringWithFormat("could not parse filter rule "
"attribute from \"%s\"",
- rule_text_cstr);
+ rule_text.str().c_str());
return error;
}
auto attribute = rule_text.substr(action_end_pos + 1,
@@ -728,7 +725,7 @@ private:
if (attribute_index < 0) {
error.SetErrorStringWithFormat("filter rule attribute unknown: "
"%s",
- attribute.c_str());
+ attribute.str().c_str());
return error;
}
@@ -748,12 +745,10 @@ private:
return error;
}
- int MatchAttributeIndex(const std::string &attribute_name) {
-auto attribute_count =
-sizeof(s_filter_attributes) / sizeof(s_filter_attributes[0]);
-for (size_t i = 0; i < attribute_count; ++i) {
- if (attribute_name == s_filter_attributes[i])
-return static_cast(i);
+ int MatchAttributeIndex(llvm::StringRef attribute_name) const {
+for (const auto &Item : llvm::enumerate(s_filter_attributes)) {
+ if (attribute_name == Item.Value)
+return Item.Index;
}
// We didn't match anything.
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits