Skip to content

Commit

Permalink
Use skipOver in uriToFile
Browse files Browse the repository at this point in the history
  • Loading branch information
nordlow committed Nov 19, 2024
1 parent 0c7fe66 commit 77c2fcc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions protocol/source/served/lsp/uri.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ string uriToFile(DocumentUri uri)
import std.uri : decodeComponent;
import std.string : startsWith;

if (uri.startsWith("file://"))
if (uri.skipOver("file://"))
{
string ret = uri["file://".length .. $].decodeComponent;
if (ret.length >= 3 && ret[0] == '/' && ret[2] == ':') // file:///x: windows path
return ret[1 .. $].replace("/", "\\");
else if (ret.length >= 1 && ret[0] != '/') // file://share windows path
return "\\\\" ~ ret.replace("/", "\\");
return ret;
if (uri.length >= 3 && uri[0] == '/' && uri[2] == ':') // file:///x: windows path
return uri[1 .. $].replace("/", "\\");
else if (uri.length >= 1 && uri[0] != '/') // file://share windows path
return "\\\\" ~ uri.replace("/", "\\");
return uri;
}
else
return null;
Expand Down Expand Up @@ -283,7 +282,7 @@ unittest
{
assertEquals(uriNormalize(`b/../a.d`), `a.d`);
assertEquals(uriNormalize(`b/../../a.d`), `../a.d`);

foreach (prefix; ["file:///", "file://", "", "/", "//"])
{
assertEquals(uriNormalize(prefix ~ `foo/bar/./a.d`), prefix ~ `foo/bar/a.d`);
Expand Down

0 comments on commit 77c2fcc

Please sign in to comment.