Simplify find_first_of & find_last_of on single char.
Summary:
When calling find_first_of and find_last_of on a single character,
we can instead just call find / rfind and make our intent more
clear.
Reviewers: clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D12518
llvm-svn: 246609
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index a53b46a..4e02588 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2424,10 +2424,10 @@
variable_name = llvm::StringRef();
variable_format = llvm::StringRef();
- const size_t paren_pos = format_str.find_first_of('}');
+ const size_t paren_pos = format_str.find('}');
if (paren_pos != llvm::StringRef::npos)
{
- const size_t percent_pos = format_str.find_first_of('%');
+ const size_t percent_pos = format_str.find('%');
if (percent_pos < paren_pos)
{
if (percent_pos > 0)
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp
index a917a89..9efdacb 100644
--- a/lldb/source/Host/common/FileSpec.cpp
+++ b/lldb/source/Host/common/FileSpec.cpp
@@ -107,7 +107,7 @@
return;
llvm::StringRef path_str(path.data(), path.size());
- size_t slash_pos = path_str.find_first_of("/", 1);
+ size_t slash_pos = path_str.find('/', 1);
if (slash_pos == 1 || path.size() == 1)
{
// A path of ~/ resolves to the current user's home dir
diff --git a/lldb/source/Host/common/ThisThread.cpp b/lldb/source/Host/common/ThisThread.cpp
index 289ec78..7637014 100644
--- a/lldb/source/Host/common/ThisThread.cpp
+++ b/lldb/source/Host/common/ThisThread.cpp
@@ -37,7 +37,7 @@
{
// We're still too long. Since this is a dotted component, use everything after the last
// dot, up to a maximum of |length| characters.
- std::string::size_type last_dot = truncated_name.find_last_of(".");
+ std::string::size_type last_dot = truncated_name.rfind('.');
if (last_dot != std::string::npos)
begin = last_dot + 1;
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
index 40879e1..9308c7a 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
@@ -230,7 +230,7 @@
if (for_expression && !name.empty())
{
- size_t less_than_pos = name.find_first_of('<');
+ size_t less_than_pos = name.find('<');
if (less_than_pos != std::string::npos)
{
diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
index cc47778..b3670b5 100644
--- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
@@ -609,12 +609,12 @@
std::string info((const char *)buffer->GetBytes());
std::vector<std::string> info_lines;
- size_t lpos = info.find_first_of("\n");
+ size_t lpos = info.find('\n');
while (lpos != std::string::npos)
{
info_lines.push_back(info.substr(0, lpos));
info = info.substr(lpos + 1);
- lpos = info.find_first_of("\n");
+ lpos = info.find('\n');
}
size_t offset = 0;
while (offset < info_lines.size())
diff --git a/lldb/source/Utility/UriParser.cpp b/lldb/source/Utility/UriParser.cpp
index 6febae2..77e16b0 100644
--- a/lldb/source/Utility/UriParser.cpp
+++ b/lldb/source/Utility/UriParser.cpp
@@ -40,7 +40,7 @@
// Extract path.
tmp_scheme = uri.substr(0, pos);
auto host_pos = pos + strlen(kSchemeSep);
- auto path_pos = uri.find_first_of("/", host_pos);
+ auto path_pos = uri.find('/', host_pos);
if (path_pos != std::string::npos)
tmp_path = uri.substr(path_pos);
else
diff --git a/lldb/tools/lldb-mi/MICmdArgValFile.cpp b/lldb/tools/lldb-mi/MICmdArgValFile.cpp
index 9e59dec..7f5b20e 100644
--- a/lldb/tools/lldb-mi/MICmdArgValFile.cpp
+++ b/lldb/tools/lldb-mi/MICmdArgValFile.cpp
@@ -142,8 +142,8 @@
if (vrFileNamePath.empty())
return false;
- const bool bHavePosSlash = (vrFileNamePath.find_first_of("/") != std::string::npos);
- const bool bHaveBckSlash = (vrFileNamePath.find_first_of("\\") != std::string::npos);
+ const bool bHavePosSlash = (vrFileNamePath.find('/') != std::string::npos);
+ const bool bHaveBckSlash = (vrFileNamePath.find('\\') != std::string::npos);
// Look for --someLongOption
size_t nPos = vrFileNamePath.find("--");
@@ -152,13 +152,13 @@
return false;
// Look for -f type short parameters
- nPos = vrFileNamePath.find_first_of("-");
+ nPos = vrFileNamePath.find('-');
const bool bShort = (nPos == 0);
if (bShort)
return false;
// Look for i1 i2 i3....
- nPos = vrFileNamePath.find_first_of("i");
+ nPos = vrFileNamePath.find('i');
const bool bFoundI1 = ((nPos == 0) && (::isdigit(vrFileNamePath[1])));
if (bFoundI1)
return false;
diff --git a/lldb/tools/lldb-mi/MICmdArgValOptionLong.cpp b/lldb/tools/lldb-mi/MICmdArgValOptionLong.cpp
index fef180e..1b03849 100644
--- a/lldb/tools/lldb-mi/MICmdArgValOptionLong.cpp
+++ b/lldb/tools/lldb-mi/MICmdArgValOptionLong.cpp
@@ -249,8 +249,8 @@
bool
CMICmdArgValOptionLong::IsArgLongOption(const CMIUtilString &vrTxt) const
{
- const bool bHavePosSlash = (vrTxt.find_first_of("/") != std::string::npos);
- const bool bHaveBckSlash = (vrTxt.find_first_of("\\") != std::string::npos);
+ const bool bHavePosSlash = (vrTxt.find('/') != std::string::npos);
+ const bool bHaveBckSlash = (vrTxt.find('\\') != std::string::npos);
if (bHavePosSlash || bHaveBckSlash)
return false;
diff --git a/lldb/tools/lldb-mi/MICmdArgValString.cpp b/lldb/tools/lldb-mi/MICmdArgValString.cpp
index aefcffe..bea5935 100644
--- a/lldb/tools/lldb-mi/MICmdArgValString.cpp
+++ b/lldb/tools/lldb-mi/MICmdArgValString.cpp
@@ -220,8 +220,8 @@
if (!m_bHandleDirPaths)
{
// Look for directory file paths, if found reject
- const bool bHavePosSlash = (vrTxt.find_first_of("/") != std::string::npos);
- const bool bHaveBckSlash = (vrTxt.find_first_of("\\") != std::string::npos);
+ const bool bHavePosSlash = (vrTxt.find('/') != std::string::npos);
+ const bool bHaveBckSlash = (vrTxt.find('\\') != std::string::npos);
if (bHavePosSlash || bHaveBckSlash)
return false;
}
diff --git a/lldb/tools/lldb-mi/MICmdArgValThreadGrp.cpp b/lldb/tools/lldb-mi/MICmdArgValThreadGrp.cpp
index 400ec70..6b79fc8 100644
--- a/lldb/tools/lldb-mi/MICmdArgValThreadGrp.cpp
+++ b/lldb/tools/lldb-mi/MICmdArgValThreadGrp.cpp
@@ -117,7 +117,7 @@
CMICmdArgValThreadGrp::IsArgThreadGrp(const CMIUtilString &vrTxt) const
{
// Look for i1 i2 i3....
- const MIint nPos = vrTxt.find_first_of("i");
+ const MIint nPos = vrTxt.find('i');
if (nPos != 0)
return false;
diff --git a/lldb/tools/lldb-mi/MICmdCmdBreak.cpp b/lldb/tools/lldb-mi/MICmdCmdBreak.cpp
index 87db5ab..3c16e2e 100644
--- a/lldb/tools/lldb-mi/MICmdCmdBreak.cpp
+++ b/lldb/tools/lldb-mi/MICmdCmdBreak.cpp
@@ -118,10 +118,10 @@
{
// Full paths in windows can have ':' after a drive letter, so we
// search backwards, taking care to skip C++ namespace tokens '::'.
- size_t n = x.find_last_of(':');
+ size_t n = x.rfind(':');
while (n != std::string::npos && n > 1 && x[n-1] == ':')
{
- n = x.find_last_of(':', n - 2);
+ n = x.rfind(':', n - 2);
}
return n;
}