r346266 - Don't use std::next() on an input iterator; NFC.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 6 13:12:44 PST 2018
Author: aaronballman
Date: Tue Nov 6 13:12:44 2018
New Revision: 346266
URL: http://llvm.org/viewvc/llvm-project?rev=346266&view=rev
Log:
Don't use std::next() on an input iterator; NFC.
Instead, advance the old-fashioned way, as std::next() cannot be used on an input iterator until C++17.
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=346266&r1=346265&r2=346266&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Tue Nov 6 13:12:44 2018
@@ -82,25 +82,27 @@ static std::string fileNameToURI(StringR
Ret += Twine("/" + Root).str();
}
- // Add the rest of the path components, encoding any reserved characters.
- std::for_each(std::next(sys::path::begin(Filename)), sys::path::end(Filename),
- [&Ret](StringRef Component) {
- // For reasons unknown to me, we may get a backslash with
- // Windows native paths for the initial backslash following
- // the drive component, which we need to ignore as a URI path
- // part.
- if (Component == "\\")
- return;
+ auto Iter = sys::path::begin(Filename), End = sys::path::end(Filename);
+ if (Iter != End) {
+ // Add the rest of the path components, encoding any reserved characters;
+ // we skip past the first path component, as it was handled it above.
+ std::for_each(++Iter, End, [&Ret](StringRef Component) {
+ // For reasons unknown to me, we may get a backslash with Windows native
+ // paths for the initial backslash following the drive component, which
+ // we need to ignore as a URI path part.
+ if (Component == "\\")
+ return;
- // Add the separator between the previous path part and the
- // one being currently processed.
- Ret += "/";
+ // Add the separator between the previous path part and the one being
+ // currently processed.
+ Ret += "/";
- // URI encode the part.
- for (char C : Component) {
- Ret += percentEncodeURICharacter(C);
- }
- });
+ // URI encode the part.
+ for (char C : Component) {
+ Ret += percentEncodeURICharacter(C);
+ }
+ });
+ }
return Ret.str().str();
}
More information about the cfe-commits
mailing list