| ... | ... | @@ -1187,18 +1187,18 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons |
| 1187 | 1187 | /// This function will search for the file extension (separated by a `.`) and will return the text after the `.`. |
| 1188 | 1188 | /// Files that end with `.` are considered to have no extension, files that start with `.` |
| 1189 | 1189 | /// Examples: |
| 1190 | | /// - `"main.zig"` ⇒ `"zig"` |
| 1191 | | /// - `"src/main.zig"` ⇒ `"zig"` |
| 1190 | /// - `"main.zig"` ⇒ `".zig"` |
| 1191 | /// - `"src/main.zig"` ⇒ `".zig"` |
| 1192 | 1192 | /// - `".gitignore"` ⇒ `null` |
| 1193 | 1193 | /// - `"keep."` ⇒ `null` |
| 1194 | | /// - `"src.keep.me"` ⇒ `"me"` |
| 1194 | /// - `"src.keep.me"` ⇒ `".me"` |
| 1195 | 1195 | pub fn extension(path: []const u8) ?[]const u8 { |
| 1196 | 1196 | const filename = basename(path); |
| 1197 | 1197 | return if (std.mem.lastIndexOf(u8, filename, ".")) |index| |
| 1198 | 1198 | if (index == 0 or index == filename.len - 1) |
| 1199 | 1199 | null |
| 1200 | 1200 | else |
| 1201 | | filename[index + 1 ..] |
| 1201 | filename[index..] |
| 1202 | 1202 | else |
| 1203 | 1203 | null; |
| 1204 | 1204 | } |
| ... | ... | @@ -1222,9 +1222,9 @@ test "extension" { |
| 1222 | 1222 | testExtension(".a", null); |
| 1223 | 1223 | testExtension(".file", null); |
| 1224 | 1224 | testExtension(".gitignore", null); |
| 1225 | | testExtension("file.ext", "ext"); |
| 1226 | | testExtension("very-long-file.bruh", "bruh"); |
| 1227 | | testExtension("a.b.c", "c"); |
| 1225 | testExtension("file.ext", ".ext"); |
| 1226 | testExtension("very-long-file.bruh", ".bruh"); |
| 1227 | testExtension("a.b.c", ".c"); |
| 1228 | 1228 | |
| 1229 | 1229 | testExtension("/", null); |
| 1230 | 1230 | testExtension("/.", null); |
| ... | ... | @@ -1233,9 +1233,9 @@ test "extension" { |
| 1233 | 1233 | testExtension("/.a", null); |
| 1234 | 1234 | testExtension("/.file", null); |
| 1235 | 1235 | testExtension("/.gitignore", null); |
| 1236 | | testExtension("/file.ext", "ext"); |
| 1237 | | testExtension("/very-long-file.bruh", "bruh"); |
| 1238 | | testExtension("/a.b.c", "c"); |
| 1236 | testExtension("/file.ext", ".ext"); |
| 1237 | testExtension("/very-long-file.bruh", ".bruh"); |
| 1238 | testExtension("/a.b.c", ".c"); |
| 1239 | 1239 | |
| 1240 | 1240 | testExtension("/foo/bar/bam/", null); |
| 1241 | 1241 | testExtension("/foo/bar/bam/.", null); |
| ... | ... | @@ -1244,7 +1244,7 @@ test "extension" { |
| 1244 | 1244 | testExtension("/foo/bar/bam/.a", null); |
| 1245 | 1245 | testExtension("/foo/bar/bam/.file", null); |
| 1246 | 1246 | testExtension("/foo/bar/bam/.gitignore", null); |
| 1247 | | testExtension("/foo/bar/bam/file.ext", "ext"); |
| 1248 | | testExtension("/foo/bar/bam/very-long-file.bruh", "bruh"); |
| 1249 | | testExtension("/foo/bar/bam/a.b.c", "c"); |
| 1247 | testExtension("/foo/bar/bam/file.ext", ".ext"); |
| 1248 | testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh"); |
| 1249 | testExtension("/foo/bar/bam/a.b.c", ".c"); |
| 1250 | 1250 | } |