1 /++ 2 $(H2 Scriptlike $(SCRIPTLIKE_VERSION)) 3 4 Wrappers for $(MODULE_STD_PATH) that add support for Scriptlike's 5 $(API_PATH_EXTR Path) and command echoing features. 6 7 Copyright: Copyright (C) 2014-2017 Nick Sabalausky 8 License: zlib/libpng 9 Authors: Nick Sabalausky 10 +/ 11 module scriptlike.path.wrappers; 12 13 import std.algorithm; 14 import std.conv; 15 import std.datetime; 16 import std.file; 17 import std.process; 18 import std.range; 19 import std.stdio; 20 import std..string; 21 import std.traits; 22 import std.typecons; 23 import std.typetuple; 24 25 static import std.path; 26 public import std.path : dirSeparator, pathSeparator, isDirSeparator, 27 CaseSensitive, osDefaultCaseSensitivity, buildPath, buildNormalizedPath; 28 29 import scriptlike.path.extras; 30 31 /// Alias of same-named function from $(MODULE_STD_PATH) 32 alias baseName() = std.path.baseName; 33 alias dirName() = std.path.dirName; ///ditto 34 alias rootName() = std.path.rootName; ///ditto 35 alias driveName() = std.path.driveName; ///ditto 36 alias stripDrive() = std.path.stripDrive; ///ditto 37 alias extension() = std.path.extension; ///ditto 38 alias stripExtension() = std.path.stripExtension; ///ditto 39 alias setExtension() = std.path.setExtension; ///ditto 40 alias defaultExtension() = std.path.defaultExtension; ///ditto 41 alias pathSplitter() = std.path.pathSplitter; ///ditto 42 alias isRooted() = std.path.isRooted; ///ditto 43 alias isAbsolute() = std.path.isAbsolute; ///ditto 44 alias absolutePath = std.path.absolutePath; ///ditto 45 alias relativePath() = std.path.relativePath; ///ditto 46 alias filenameCmp() = std.path.filenameCmp; ///ditto 47 alias globMatch() = std.path.globMatch; ///ditto 48 alias isValidFilename() = std.path.isValidFilename; ///ditto 49 alias isValidPath() = std.path.isValidPath; ///ditto 50 alias expandTilde = std.path.expandTilde; ///ditto 51 52 /// Like $(FULL_STD_PATH baseName), but operates on Path. 53 Path baseName(Path path) 54 @trusted pure 55 { 56 return Path( std.path.baseName(path.raw) ); 57 } 58 59 ///ditto 60 Path baseName(CaseSensitive cs = CaseSensitive.osDefault) 61 (Path path, in string suffix) 62 @safe pure 63 { 64 return Path( std.path.baseName!cs(path.raw, suffix) ); 65 } 66 /// Like $(FULL_STD_PATH dirName), but operates on Path. 67 Path dirName(Path path) 68 { 69 return Path( std.path.dirName(path.raw) ); 70 } 71 72 /// Like $(FULL_STD_PATH rootName), but operates on Path. 73 Path rootName(Path path) @safe pure nothrow 74 { 75 return Path( std.path.rootName(path.raw) ); 76 } 77 78 /// Like $(FULL_STD_PATH driveName), but operates on Path. 79 Path driveName(Path path) @safe pure nothrow 80 { 81 return Path( std.path.driveName(path.raw) ); 82 } 83 84 /// Like $(FULL_STD_PATH stripDrive), but operates on Path. 85 Path stripDrive(Path path) @safe pure nothrow 86 { 87 return Path( std.path.stripDrive(path.raw) ); 88 } 89 90 /// Like $(FULL_STD_PATH extension), but takes a Path and returns an Ext. 91 Ext extension(in Path path) @safe pure nothrow 92 { 93 return Ext( std.path.extension(path.raw) ); 94 } 95 96 /// Like $(FULL_STD_PATH stripExtension), but operates on Path. 97 Path stripExtension(Path path) @safe pure nothrow 98 { 99 return Path( std.path.stripExtension(path.raw) ); 100 } 101 102 /// Like $(FULL_STD_PATH setExtension), but operates on Path. 103 Path setExtension(Path path, string ext) 104 @trusted pure nothrow 105 { 106 return Path( std.path.setExtension(path.raw, ext) ); 107 } 108 109 ///ditto 110 Path setExtension(Path path, Ext ext) 111 @trusted pure nothrow 112 { 113 return path.setExtension(ext.toString()); 114 } 115 116 /// Like $(FULL_STD_PATH defaultExtension), but operates on Path and optionally Ext. 117 Path defaultExtension(Path path, in string ext) 118 @trusted pure 119 { 120 return Path( std.path.defaultExtension(path.raw, ext) ); 121 } 122 123 ///ditto 124 Path defaultExtension(Path path, Ext ext) 125 @trusted pure 126 { 127 return path.defaultExtension(ext.toString()); 128 } 129 130 /// Like $(FULL_STD_PATH pathSplitter). Note this returns a range of strings, 131 /// not a range of Path. 132 auto pathSplitter(Path path) @safe pure nothrow 133 { 134 return std.path.pathSplitter(path.raw); 135 } 136 137 /// Like $(FULL_STD_PATH isRooted), but operates on Path. 138 bool isRooted()(in Path path) @safe pure nothrow 139 { 140 return std.path.isRooted(path.raw); 141 } 142 143 /// Like $(FULL_STD_PATH isAbsolute), but operates on Path. 144 bool isAbsolute(in Path path) @safe pure nothrow 145 { 146 return std.path.isAbsolute(path.raw); 147 } 148 149 /// Like $(FULL_STD_PATH absolutePath), but operates on Path. 150 Path absolutePath(Path path, lazy string base = getcwd()) 151 @safe pure 152 { 153 return Path( std.path.absolutePath(path.raw, base) ); 154 } 155 156 ///ditto 157 Path absolutePath(Path path, Path base) 158 @safe pure 159 { 160 return Path( std.path.absolutePath(path.raw, base.raw.to!string()) ); 161 } 162 163 /// Like $(FULL_STD_PATH relativePath), but operates on Path. 164 Path relativePath(CaseSensitive cs = CaseSensitive.osDefault) 165 (Path path, lazy string base = getcwd()) 166 { 167 return Path( std.path.relativePath!cs(path.raw, base) ); 168 } 169 170 ///ditto 171 Path relativePath(CaseSensitive cs = CaseSensitive.osDefault) 172 (Path path, Path base) 173 { 174 return Path( std.path.relativePath!cs(path.raw, base.raw.to!string()) ); 175 } 176 177 /// Like $(FULL_STD_PATH filenameCmp), but operates on Path. 178 int filenameCmp(CaseSensitive cs = CaseSensitive.osDefault) 179 (Path path, Path filename2) 180 @safe pure 181 { 182 return std.path.filenameCmp(path.raw, filename2.raw); 183 } 184 185 ///ditto 186 int filenameCmp(CaseSensitive cs = CaseSensitive.osDefault) 187 (Path path, string filename2) 188 @safe pure 189 { 190 return std.path.filenameCmp(path.raw, filename2); 191 } 192 193 ///ditto 194 int filenameCmp(CaseSensitive cs = CaseSensitive.osDefault) 195 (string path, Path filename2) 196 @safe pure 197 { 198 return std.path.filenameCmp(path, filename2.raw); 199 } 200 201 /// Like $(FULL_STD_PATH globMatch), but operates on Path. 202 bool globMatch(CaseSensitive cs = CaseSensitive.osDefault) 203 (Path path, string pattern) 204 @safe pure nothrow 205 { 206 return std.path.globMatch!cs(path.raw, pattern); 207 } 208 209 /// Like $(FULL_STD_PATH isValidFilename), but operates on Path. 210 bool isValidFilename(in Path path) @safe pure nothrow 211 { 212 return std.path.isValidFilename(path.raw); 213 } 214 215 /// Like $(FULL_STD_PATH isValidPath), but operates on Path. 216 bool isValidPath(in Path path) @safe pure nothrow 217 { 218 return std.path.isValidPath(path.raw); 219 } 220 221 /// Like $(FULL_STD_PATH expandTilde), but operates on Path. 222 Path expandTilde(Path path) 223 { 224 return Path( std.path.expandTilde(path.raw) ); 225 }