From 271017ba9970e4220e1bd0dc83ce146afe9222a2 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 24 Jun 2025 13:37:09 -0400 Subject: Add Path.has_extension() and update manpages/api docs --- src/stdlib/paths.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/stdlib/paths.c') diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 5047d615..772fa1fd 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -609,6 +609,22 @@ public Text_t Path$extension(Path_t path, bool full) return Text$from_str(extension); } +public bool Path$has_extension(Path_t path, Text_t extension) +{ + if (path.components.length < 2) + return extension.length == 0; + + Text_t last = *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)); + + if (extension.length == 0) + return !Text$has(Text$from(last, I(2)), Text(".")) || Text$equal_values(last, Text("..")); + + if (!Text$starts_with(extension, Text("."))) + extension = Texts(Text("."), extension); + + return Text$ends_with(Text$from(last, I(2)), extension); +} + public Path_t Path$child(Path_t path, Text_t name) { if (Text$has(name, Text("/")) || Text$has(name, Text(";"))) -- cgit v1.2.3