-
Notifications
You must be signed in to change notification settings - Fork 1
/
path.d
44 lines (43 loc) · 868 Bytes
/
path.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module util.path;
version(WASM){
string buildPath(string[] args...){
import std.string;
return args.join("/");
}
string dirName(string arg){
while(arg.length&&arg[$-1]=='/')
arg=arg[0..$-1];
auto i=arg.length;
if(!i) return "/";
for(;i-->0;)
if(arg[i]=='/')
return arg[0..i];
return "/";
}
string extension(string arg){
auto i=arg.length;
if(!i) return "";
i--;
for(;i-->0;)
if(arg[i]=='/')
return extension(arg[i+1..$]);
i=arg.length-1;
for(;i-->0;)
if(arg[i]=='.')
return arg[i+1..$];
return "";
}
string setExtension(string arg,string ext){
auto i=arg.length;
if(!i) return "";
i--;
for(;i-->0;)
if(arg[i]=='/')
return arg[0..i+1]~setExtension(arg[i+1..$],ext);
i=arg.length-1;
for(;i-->0;)
if(arg[i]=='.')
return arg[0..i+1]~ext;
return "";
}
}else public import std.path;