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...@@ -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"`
1195pub fn extension(path: []const u8) ?[]const u8 {1195pub 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 null1199 null
1200 else1200 else
1201 filename[index + 1 ..]1201 filename[index..]
1202 else1202 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");
12281228
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");
12391239
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}