Skip to content

Commit b9a4f11

Browse files
[clang-tidy][NFC] Fix a couple of suspicious StringRef::data() usages
1 parent 48babe1 commit b9a4f11

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static bool bodyEmpty(const ASTContext *Context, const CompoundStmt *Body) {
204204
CharSourceRange::getCharRange(Body->getLBracLoc().getLocWithOffset(1),
205205
Body->getRBracLoc()),
206206
Context->getSourceManager(), Context->getLangOpts(), &Invalid);
207-
return !Invalid && std::strspn(Text.data(), " \t\r\n") == Text.size();
207+
return !Invalid && Text.ltrim(" \t\r\n").empty();
208208
}
209209

210210
UseEqualsDefaultCheck::UseEqualsDefaultCheck(StringRef Name,

clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
337337

338338
// Remove keywords
339339
for (StringRef Kw : Keywords) {
340-
for (size_t Pos = 0;
341-
(Pos = Type.find(Kw.data(), Pos)) != std::string::npos;) {
340+
for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;) {
342341
Type.replace(Pos, Kw.size(), "");
343342
}
344343
}
@@ -373,7 +372,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
373372
" int", " char", " double", " long", " short"};
374373
bool RedundantRemoved = false;
375374
for (auto Kw : TailsOfMultiWordType) {
376-
size_t Pos = Type.rfind(Kw.data());
375+
size_t Pos = Type.rfind(Kw);
377376
if (Pos != std::string::npos) {
378377
const size_t PtrCount = getAsteriskCount(Type, ND);
379378
Type = Type.substr(0, Pos + Kw.size() + PtrCount);
@@ -602,9 +601,8 @@ std::string IdentifierNamingCheck::HungarianNotation::getDataTypePrefix(
602601
if (PtrCount > 0) {
603602
ModifiedTypeName = [&](std::string Str, StringRef From, StringRef To) {
604603
size_t StartPos = 0;
605-
while ((StartPos = Str.find(From.data(), StartPos)) !=
606-
std::string::npos) {
607-
Str.replace(StartPos, From.size(), To.data());
604+
while ((StartPos = Str.find(From, StartPos)) != std::string::npos) {
605+
Str.replace(StartPos, From.size(), To);
608606
StartPos += To.size();
609607
}
610608
return Str;

0 commit comments

Comments
 (0)