mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
std.fs.path.extension: add additional API guarantee
Added: The returned slice is guaranteed to have its pointer within the start and end pointer address range of `path`, even if it is length zero.
This commit is contained in:
parent
1852dc7e13
commit
52bc1442d6
@ -1201,15 +1201,17 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons
|
||||
/// - `"src.keep.me"` ⇒ `".me"`
|
||||
/// - `"/src/keep.me"` ⇒ `".me"`
|
||||
/// - `"/src/keep.me/"` ⇒ `".me"`
|
||||
/// The returned slice is guaranteed to have its pointer within the start and end
|
||||
/// pointer address range of `path`, even if it is length zero.
|
||||
pub fn extension(path: []const u8) []const u8 {
|
||||
const filename = basename(path);
|
||||
return if (std.mem.lastIndexOf(u8, filename, ".")) |index|
|
||||
if (index == 0 or index == filename.len - 1)
|
||||
""
|
||||
path[path.len..]
|
||||
else
|
||||
filename[index..]
|
||||
else
|
||||
"";
|
||||
path[path.len..];
|
||||
}
|
||||
|
||||
fn testExtension(path: []const u8, expected: []const u8) void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user