| ... | @@ -1197,7 +1197,7 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons | ... | @@ -1197,7 +1197,7 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons |
| 1197 | /// - `"main.zig"` ⇒ `".zig"` | 1197 | /// - `"main.zig"` ⇒ `".zig"` |
| 1198 | /// - `"src/main.zig"` ⇒ `".zig"` | 1198 | /// - `"src/main.zig"` ⇒ `".zig"` |
| 1199 | /// - `".gitignore"` ⇒ `""` | 1199 | /// - `".gitignore"` ⇒ `""` |
| 1200 | /// - `"keep."` ⇒ `""` | 1200 | /// - `"keep."` ⇒ `"."` |
| 1201 | /// - `"src.keep.me"` ⇒ `".me"` | 1201 | /// - `"src.keep.me"` ⇒ `".me"` |
| 1202 | /// - `"/src/keep.me"` ⇒ `".me"` | 1202 | /// - `"/src/keep.me"` ⇒ `".me"` |
| 1203 | /// - `"/src/keep.me/"` ⇒ `".me"` | 1203 | /// - `"/src/keep.me/"` ⇒ `".me"` |
| ... | @@ -1205,13 +1205,9 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons | ... | @@ -1205,13 +1205,9 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons |
| 1205 | /// pointer address range of `path`, even if it is length zero. | 1205 | /// pointer address range of `path`, even if it is length zero. |
| 1206 | pub fn extension(path: []const u8) []const u8 { | 1206 | pub fn extension(path: []const u8) []const u8 { |
| 1207 | const filename = basename(path); | 1207 | const filename = basename(path); |
| 1208 | return if (std.mem.lastIndexOf(u8, filename, ".")) |index| | 1208 | const index = mem.lastIndexOf(u8, filename, ".") orelse return path[path.len..]; |
| 1209 | if (index == 0 or index == filename.len - 1) | 1209 | if (index == 0) return path[path.len..]; |
| 1210 | path[path.len..] | 1210 | return filename[index..]; |
| 1211 | else | | |
| 1212 | filename[index..] | | |
| 1213 | else | | |
| 1214 | path[path.len..]; | | |
| 1215 | } | 1211 | } |
| 1216 | | 1212 | |
| 1217 | fn testExtension(path: []const u8, expected: []const u8) void { | 1213 | fn testExtension(path: []const u8, expected: []const u8) void { |
| ... | @@ -1221,39 +1217,39 @@ fn testExtension(path: []const u8, expected: []const u8) void { | ... | @@ -1221,39 +1217,39 @@ fn testExtension(path: []const u8, expected: []const u8) void { |
| 1221 | test "extension" { | 1217 | test "extension" { |
| 1222 | testExtension("", ""); | 1218 | testExtension("", ""); |
| 1223 | testExtension(".", ""); | 1219 | testExtension(".", ""); |
| 1224 | testExtension("a.", ""); | 1220 | testExtension("a.", "."); |
| 1225 | testExtension("abc.", ""); | 1221 | testExtension("abc.", "."); |
| 1226 | testExtension(".a", ""); | 1222 | testExtension(".a", ""); |
| 1227 | testExtension(".file", ""); | 1223 | testExtension(".file", ""); |
| 1228 | testExtension(".gitignore", ""); | 1224 | testExtension(".gitignore", ""); |
| 1229 | testExtension("file.ext", ".ext"); | 1225 | testExtension("file.ext", ".ext"); |
| 1230 | testExtension("file.ext.", ""); | 1226 | testExtension("file.ext.", "."); |
| 1231 | testExtension("very-long-file.bruh", ".bruh"); | 1227 | testExtension("very-long-file.bruh", ".bruh"); |
| 1232 | testExtension("a.b.c", ".c"); | 1228 | testExtension("a.b.c", ".c"); |
| 1233 | testExtension("a.b.c/", ".c"); | 1229 | testExtension("a.b.c/", ".c"); |
| 1234 | | 1230 | |
| 1235 | testExtension("/", ""); | 1231 | testExtension("/", ""); |
| 1236 | testExtension("/.", ""); | 1232 | testExtension("/.", ""); |
| 1237 | testExtension("/a.", ""); | 1233 | testExtension("/a.", "."); |
| 1238 | testExtension("/abc.", ""); | 1234 | testExtension("/abc.", "."); |
| 1239 | testExtension("/.a", ""); | 1235 | testExtension("/.a", ""); |
| 1240 | testExtension("/.file", ""); | 1236 | testExtension("/.file", ""); |
| 1241 | testExtension("/.gitignore", ""); | 1237 | testExtension("/.gitignore", ""); |
| 1242 | testExtension("/file.ext", ".ext"); | 1238 | testExtension("/file.ext", ".ext"); |
| 1243 | testExtension("/file.ext.", ""); | 1239 | testExtension("/file.ext.", "."); |
| 1244 | testExtension("/very-long-file.bruh", ".bruh"); | 1240 | testExtension("/very-long-file.bruh", ".bruh"); |
| 1245 | testExtension("/a.b.c", ".c"); | 1241 | testExtension("/a.b.c", ".c"); |
| 1246 | testExtension("/a.b.c/", ".c"); | 1242 | testExtension("/a.b.c/", ".c"); |
| 1247 | | 1243 | |
| 1248 | testExtension("/foo/bar/bam/", ""); | 1244 | testExtension("/foo/bar/bam/", ""); |
| 1249 | testExtension("/foo/bar/bam/.", ""); | 1245 | testExtension("/foo/bar/bam/.", ""); |
| 1250 | testExtension("/foo/bar/bam/a.", ""); | 1246 | testExtension("/foo/bar/bam/a.", "."); |
| 1251 | testExtension("/foo/bar/bam/abc.", ""); | 1247 | testExtension("/foo/bar/bam/abc.", "."); |
| 1252 | testExtension("/foo/bar/bam/.a", ""); | 1248 | testExtension("/foo/bar/bam/.a", ""); |
| 1253 | testExtension("/foo/bar/bam/.file", ""); | 1249 | testExtension("/foo/bar/bam/.file", ""); |
| 1254 | testExtension("/foo/bar/bam/.gitignore", ""); | 1250 | testExtension("/foo/bar/bam/.gitignore", ""); |
| 1255 | testExtension("/foo/bar/bam/file.ext", ".ext"); | 1251 | testExtension("/foo/bar/bam/file.ext", ".ext"); |
| 1256 | testExtension("/foo/bar/bam/file.ext.", ""); | 1252 | testExtension("/foo/bar/bam/file.ext.", "."); |
| 1257 | testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh"); | 1253 | testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh"); |
| 1258 | testExtension("/foo/bar/bam/a.b.c", ".c"); | 1254 | testExtension("/foo/bar/bam/a.b.c", ".c"); |
| 1259 | testExtension("/foo/bar/bam/a.b.c/", ".c"); | 1255 | testExtension("/foo/bar/bam/a.b.c/", ".c"); |