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