| ... | @@ -146,72 +146,51 @@ pub fn isAbsolute(path: []const u8) bool { | ... | @@ -146,72 +146,51 @@ pub fn isAbsolute(path: []const u8) bool { |
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| 148 | | 148 | |
| 149 | pub fn isAbsoluteW(path_w: [*:0]const u16) bool { | 149 | fn isAbsoluteWindowsImpl(comptime T: type, path: []const T) bool { |
| 150 | if (path_w[0] == '/') | 150 | if (path.len < 1) |
| 151 | return true; | | |
| 152 | | | |
| 153 | if (path_w[0] == '\\') { | | |
| 154 | return true; | | |
| 155 | } | | |
| 156 | if (path_w[0] == 0 or path_w[1] == 0 or path_w[2] == 0) { | | |
| 157 | return false; | 151 | return false; |
| 158 | } | | |
| 159 | if (path_w[1] == ':') { | | |
| 160 | if (path_w[2] == '/') | | |
| 161 | return true; | | |
| 162 | if (path_w[2] == '\\') | | |
| 163 | return true; | | |
| 164 | } | | |
| 165 | return false; | | |
| 166 | } | | |
| 167 | | 152 | |
| 168 | pub fn isAbsoluteWindows(path: []const u8) bool { | | |
| 169 | if (path[0] == '/') | 153 | if (path[0] == '/') |
| 170 | return true; | 154 | return true; |
| 171 | | 155 | |
| 172 | if (path[0] == '\\') { | 156 | if (path[0] == '\\') |
| 173 | return true; | 157 | return true; |
| 174 | } | 158 | |
| 175 | if (path.len < 3) { | 159 | if (path.len < 3) |
| 176 | return false; | 160 | return false; |
| 177 | } | 161 | |
| 178 | if (path[1] == ':') { | 162 | if (path[1] == ':') { |
| 179 | if (path[2] == '/') | 163 | if (path[2] == '/') |
| 180 | return true; | 164 | return true; |
| 181 | if (path[2] == '\\') | 165 | if (path[2] == '\\') |
| 182 | return true; | 166 | return true; |
| 183 | } | 167 | } |
| | 168 | |
| 184 | return false; | 169 | return false; |
| 185 | } | 170 | } |
| 186 | | 171 | |
| 187 | pub fn isAbsoluteWindowsC(path_c: [*:0]const u8) bool { | 172 | pub fn isAbsoluteWindows(path: []const u8) bool { |
| 188 | if (path_c[0] == '/') | 173 | return isAbsoluteWindowsImpl(u8, path); |
| 189 | return true; | 174 | } |
| 190 | | 175 | |
| 191 | if (path_c[0] == '\\') { | 176 | pub fn isAbsoluteW(path_w: [*:0]const u16) bool { |
| 192 | return true; | 177 | return isAbsoluteWindowsImpl(u16, mem.toSliceConst(u16, path_w)); |
| 193 | } | 178 | } |
| 194 | if (path_c[0] == 0 or path_c[1] == 0 or path_c[2] == 0) { | 179 | |
| 195 | return false; | 180 | pub fn isAbsoluteWindowsC(path_c: [*:0]const u8) bool { |
| 196 | } | 181 | return isAbsoluteWindowsImpl(u8, mem.toSliceConst(u8, path_c)); |
| 197 | if (path_c[1] == ':') { | | |
| 198 | if (path_c[2] == '/') | | |
| 199 | return true; | | |
| 200 | if (path_c[2] == '\\') | | |
| 201 | return true; | | |
| 202 | } | | |
| 203 | return false; | | |
| 204 | } | 182 | } |
| 205 | | 183 | |
| 206 | pub fn isAbsolutePosix(path: []const u8) bool { | 184 | pub fn isAbsolutePosix(path: []const u8) bool { |
| 207 | return path[0] == sep_posix; | 185 | return path.len > 0 and path[0] == sep_posix; |
| 208 | } | 186 | } |
| 209 | | 187 | |
| 210 | pub fn isAbsolutePosixC(path_c: [*:0]const u8) bool { | 188 | pub fn isAbsolutePosixC(path_c: [*:0]const u8) bool { |
| 211 | return path_c[0] == sep_posix; | 189 | return isAbsolutePosix(mem.toSliceConst(u8, path_c)); |
| 212 | } | 190 | } |
| 213 | | 191 | |
| 214 | test "isAbsoluteWindows" { | 192 | test "isAbsoluteWindows" { |
| | 193 | testIsAbsoluteWindows("", false); |
| 215 | testIsAbsoluteWindows("/", true); | 194 | testIsAbsoluteWindows("/", true); |
| 216 | testIsAbsoluteWindows("//", true); | 195 | testIsAbsoluteWindows("//", true); |
| 217 | testIsAbsoluteWindows("//server", true); | 196 | testIsAbsoluteWindows("//server", true); |
| ... | @@ -234,6 +213,7 @@ test "isAbsoluteWindows" { | ... | @@ -234,6 +213,7 @@ test "isAbsoluteWindows" { |
| 234 | } | 213 | } |
| 235 | | 214 | |
| 236 | test "isAbsolutePosix" { | 215 | test "isAbsolutePosix" { |
| | 216 | testIsAbsolutePosix("", false); |
| 237 | testIsAbsolutePosix("/home/foo", true); | 217 | testIsAbsolutePosix("/home/foo", true); |
| 238 | testIsAbsolutePosix("/home/foo/..", true); | 218 | testIsAbsolutePosix("/home/foo/..", true); |
| 239 | testIsAbsolutePosix("bar/", false); | 219 | testIsAbsolutePosix("bar/", false); |