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
This commit is contained in:
Bruce Mitchener 2015-09-01 23:57:17 +00:00
parent 11deaae8a1
commit e8433cc179
11 changed files with 19 additions and 19 deletions

View File

@ -2424,10 +2424,10 @@ FormatEntity::ExtractVariableInfo (llvm::StringRef &format_str, llvm::StringRef
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)

View File

@ -107,7 +107,7 @@ FileSpec::ResolveUsername (llvm::SmallVectorImpl<char> &path)
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

View File

@ -37,7 +37,7 @@ ThisThread::SetName(llvm::StringRef name, int max_length)
{
// 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;

View File

@ -230,7 +230,7 @@ AppleObjCTypeEncodingParser::BuildObjCObjectPointerType (clang::ASTContext &ast_
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)
{

View File

@ -609,12 +609,12 @@ RSModuleDescriptor::ParseRSInfo()
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())

View File

@ -40,7 +40,7 @@ UriParser::Parse(const std::string& uri,
// 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

View File

@ -142,8 +142,8 @@ CMICmdArgValFile::IsFilePath(const CMIUtilString &vrFileNamePath) const
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 @@ CMICmdArgValFile::IsFilePath(const CMIUtilString &vrFileNamePath) const
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;

View File

@ -249,8 +249,8 @@ CMICmdArgValOptionLong::ExtractExpectedOptions(CMICmdArgContext &vrwTxt, const M
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;

View File

@ -220,8 +220,8 @@ CMICmdArgValString::IsStringArgSingleText(const CMIUtilString &vrTxt) const
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;
}

View File

@ -117,7 +117,7 @@ bool
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;

View File

@ -118,10 +118,10 @@ static size_t findFileSeparatorPos(const std::string& x)
{
// 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;
}