authorgravatar for xq@random-projects.netFelix "xq" Queißner <xq@random-projects.net> 2020-11-14 11:01:02+01:00
committergravatar for xq@random-projects.netFelix "xq" Queißner <xq@random-projects.net> 2020-11-14 11:01:47+01:00
log0bbf170514c74a70cf7fa5a9c044335a8f9dddd4
tree829c915976bf8fa4a821cb665d309ec1a39c73b2
parent2ced0316ebff1227ffe8e08b5d395754be10ef13

Adapts to @andrewrk​s comment to include dot.


1 files changed, 13 insertions(+), 13 deletions(-)

lib/std/fs/path.zig+13-13
......@@ -1187,18 +1187,18 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons
11871187/// This function will search for the file extension (separated by a `.`) and will return the text after the `.`.
11881188/// Files that end with `.` are considered to have no extension, files that start with `.`
11891189/// Examples:
1190/// - `"main.zig"` ⇒ `"zig"`
1191/// - `"src/main.zig"` ⇒ `"zig"`
1190/// - `"main.zig"` ⇒ `".zig"`
1191/// - `"src/main.zig"` ⇒ `".zig"`
11921192/// - `".gitignore"` ⇒ `null`
11931193/// - `"keep."` ⇒ `null`
1194/// - `"src.keep.me"` ⇒ `"me"`
1194/// - `"src.keep.me"` ⇒ `".me"`
11951195pub fn extension(path: []const u8) ?[]const u8 {
11961196 const filename = basename(path);
11971197 return if (std.mem.lastIndexOf(u8, filename, ".")) |index|
11981198 if (index == 0 or index == filename.len - 1)
11991199 null
12001200 else
1201 filename[index + 1 ..]
1201 filename[index..]
12021202 else
12031203 null;
12041204}
......@@ -1222,9 +1222,9 @@ test "extension" {
12221222 testExtension(".a", null);
12231223 testExtension(".file", null);
12241224 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");
12281228
12291229 testExtension("/", null);
12301230 testExtension("/.", null);
......@@ -1233,9 +1233,9 @@ test "extension" {
12331233 testExtension("/.a", null);
12341234 testExtension("/.file", null);
12351235 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");
12391239
12401240 testExtension("/foo/bar/bam/", null);
12411241 testExtension("/foo/bar/bam/.", null);
......@@ -1244,7 +1244,7 @@ test "extension" {
12441244 testExtension("/foo/bar/bam/.a", null);
12451245 testExtension("/foo/bar/bam/.file", null);
12461246 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");
12501250}