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();
}