[clang-tools-extra] Use llvm::replace (NFC) (#140200)

This commit is contained in:
Kazu Hirata 2025-05-16 07:30:46 -07:00 committed by GitHub
parent e401fb8c47
commit ab1fea49e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 17 additions and 17 deletions

View File

@ -1022,12 +1022,12 @@ static llvm::Error serializeIndex(ClangDocContext &CDCtx) {
// JavaScript from escaping characters incorrectly, and introducing bad paths
// in the URLs.
std::string RootPathEscaped = RootPath.str().str();
std::replace(RootPathEscaped.begin(), RootPathEscaped.end(), '\\', '/');
llvm::replace(RootPathEscaped, '\\', '/');
OS << "var RootPath = \"" << RootPathEscaped << "\";\n";
llvm::SmallString<128> Base(CDCtx.Base);
std::string BaseEscaped = Base.str().str();
std::replace(BaseEscaped.begin(), BaseEscaped.end(), '\\', '/');
llvm::replace(BaseEscaped, '\\', '/');
OS << "var Base = \"" << BaseEscaped << "\";\n";
CDCtx.Idx.sort();

View File

@ -49,9 +49,9 @@ std::string LLVMHeaderGuardCheck::getHeaderGuard(StringRef Filename,
if (PosLLVM != StringRef::npos)
Guard = Guard.substr(PosLLVM);
std::replace(Guard.begin(), Guard.end(), '/', '_');
std::replace(Guard.begin(), Guard.end(), '.', '_');
std::replace(Guard.begin(), Guard.end(), '-', '_');
llvm::replace(Guard, '/', '_');
llvm::replace(Guard, '.', '_');
llvm::replace(Guard, '-', '_');
// The prevalent style in clang is LLVM_CLANG_FOO_BAR_H
if (StringRef(Guard).starts_with("clang"))

View File

@ -496,7 +496,7 @@ void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
StringRef Val = Options.get(Buffer, "");
if (!Val.empty()) {
std::string Type = PrimType.str();
std::replace(Type.begin(), Type.end(), '-', ' ');
llvm::replace(Type, '-', ' ');
HNOption.PrimitiveType[Type] = Val.str();
}
}
@ -1358,7 +1358,7 @@ IdentifierNamingCheck::getFailureInfo(
std::string KindName =
fixupWithCase(Type, StyleNames[SK], ND, Style, HNOption,
IdentifierNamingCheck::CT_LowerCase);
std::replace(KindName.begin(), KindName.end(), '_', ' ');
llvm::replace(KindName, '_', ' ');
std::string Fixup = fixupWithStyle(Type, Name, Style, HNOption, ND);
if (StringRef(Fixup) == Name) {

View File

@ -800,7 +800,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
M << "'";
}
// Don't allow source code to inject newlines into diagnostics.
std::replace(Message.begin(), Message.end(), '\n', ' ');
llvm::replace(Message, '\n', ' ');
}
}
if (Message.empty()) // either !SyntheticMessage, or we failed to make one.

View File

@ -57,7 +57,7 @@ LLVM_ATTRIBUTE_UNUSED std::string nodeToString(const DynTypedNode &N) {
OS << ": ";
N.print(OS, PrintingPolicy(LangOptions()));
}
std::replace(S.begin(), S.end(), '\n', ' ');
llvm::replace(S, '\n', ' ');
return S;
}

View File

@ -381,7 +381,7 @@ std::unique_ptr<SymbolIndex> openIndex(llvm::StringRef Index) {
bool runCommand(std::string Request, const SymbolIndex &Index) {
// Split on spaces and add required null-termination.
std::replace(Request.begin(), Request.end(), ' ', '\0');
llvm::replace(Request, ' ', '\0');
llvm::SmallVector<llvm::StringRef> Args;
llvm::StringRef(Request).split(Args, '\0', /*MaxSplit=*/-1,
/*KeepEmpty=*/false);

View File

@ -443,7 +443,7 @@ static std::string replaceDotDot(StringRef Path) {
// \returns The file path in canonical form.
std::string ModularizeUtilities::getCanonicalPath(StringRef FilePath) {
std::string Tmp(replaceDotDot(FilePath));
std::replace(Tmp.begin(), Tmp.end(), '\\', '/');
llvm::replace(Tmp, '\\', '/');
StringRef Tmp2(Tmp);
if (Tmp2.starts_with("./"))
Tmp = std::string(Tmp2.substr(2));

View File

@ -156,8 +156,8 @@ ensureNoCollisionWithReservedName(llvm::StringRef MightBeReservedName) {
static std::string
ensureVaidModuleName(llvm::StringRef MightBeInvalidName) {
std::string SafeName(MightBeInvalidName);
std::replace(SafeName.begin(), SafeName.end(), '-', '_');
std::replace(SafeName.begin(), SafeName.end(), '.', '_');
llvm::replace(SafeName, '-', '_');
llvm::replace(SafeName, '.', '_');
if (isdigit(SafeName[0]))
SafeName = "_" + SafeName;
return SafeName;
@ -192,7 +192,7 @@ static bool addModuleDescription(Module *RootModule,
return true;
}
// Make canonical.
std::replace(FilePath.begin(), FilePath.end(), '\\', '/');
llvm::replace(FilePath, '\\', '/');
// Insert module into tree, using subdirectories as submodules.
for (llvm::sys::path::const_iterator I = llvm::sys::path::begin(FilePath),
E = llvm::sys::path::end(FilePath);

View File

@ -904,7 +904,7 @@ public:
// Convert to a canonical path.
std::string getCanonicalPath(llvm::StringRef path) const {
std::string CanonicalPath(path);
std::replace(CanonicalPath.begin(), CanonicalPath.end(), '\\', '/');
llvm::replace(CanonicalPath, '\\', '/');
return CanonicalPath;
}

View File

@ -44,7 +44,7 @@ static std::string getSourceLocationString(Preprocessor &PP,
std::string Result = SS.str();
// YAML treats backslash as escape, so use forward slashes.
std::replace(Result.begin(), Result.end(), '\\', '/');
llvm::replace(Result, '\\', '/');
return Result;
}
@ -653,7 +653,7 @@ void PPCallbacksTracker::appendFilePathArgument(const char *Name,
llvm::StringRef Value) {
std::string Path(Value);
// YAML treats backslash as escape, so use forward slashes.
std::replace(Path.begin(), Path.end(), '\\', '/');
llvm::replace(Path, '\\', '/');
appendQuotedArgument(Name, Path);
}