aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/paths.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-06-24 13:37:09 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-06-24 13:37:09 -0400
commit271017ba9970e4220e1bd0dc83ce146afe9222a2 (patch)
tree995233d21141f164aa5f9e1d9b7bab757124e622 /src/stdlib/paths.c
parente122e5525ef044c25c2cd888bc267f7a2bd91b4f (diff)
Add Path.has_extension() and update manpages/api docs
Diffstat (limited to 'src/stdlib/paths.c')
-rw-r--r--src/stdlib/paths.c16
1 files changed, 16 insertions, 0 deletions
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(";")))