]> granicus.if.org Git - clang/commitdiff
Don't use std::next() on an input iterator; NFC.
authorAaron Ballman <aaron@aaronballman.com>
Tue, 6 Nov 2018 21:12:44 +0000 (21:12 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Tue, 6 Nov 2018 21:12:44 +0000 (21:12 +0000)
Instead, advance the old-fashioned way, as std::next() cannot be used on an input iterator until C++17.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346266 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/SarifDiagnostics.cpp

index db1550c63fdc99d51acb6c1cf5e7dc6dfe1ce0ed..448faa4a9044125d2e5128462eb62289a38ae138 100644 (file)
@@ -82,25 +82,27 @@ static std::string fileNameToURI(StringRef Filename) {
     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;
-
-                  // 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);
-                  }
-                });
+  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 += "/";
+
+      // URI encode the part.
+      for (char C : Component) {
+        Ret += percentEncodeURICharacter(C);
+      }
+    });
+  }
 
   return Ret.str().str();
 }