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