diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-01 14:05:10 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-01 14:05:10 -0400 |
| commit | 4d59fc2987e52da0274e6b204a9d2885613f74b7 (patch) | |
| tree | 8c262f99cb6ae9b550b9f8abf0ab0477044d087a /src/stdlib/paths.c | |
| parent | 7a2c99de74f5870e1dea5b59d049678ad0ef8e44 (diff) | |
Move patterns into a module
Diffstat (limited to 'src/stdlib/paths.c')
| -rw-r--r-- | src/stdlib/paths.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 05575620..3f27aef7 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -24,7 +24,6 @@ #include "integers.h" #include "optionals.h" #include "paths.h" -#include "patterns.h" #include "structs.h" #include "text.h" #include "types.h" @@ -599,15 +598,10 @@ public PUREFUNC Text_t Path$base_name(Path_t path) public Text_t Path$extension(Path_t path, bool full) { - Text_t base = Path$base_name(path); - Array_t results = Text$matches(base, full ? Pattern(".{!.}.{..}") : Pattern(".{..}.{!.}{end}")); - if (results.length > 0) - return *((Text_t*)(results.data + results.stride*1)); - results = Text$matches(base, full ? Pattern("{!.}.{..}") : Pattern("{..}.{!.}{end}")); - if (results.length > 0) - return *((Text_t*)(results.data + results.stride*1)); - else - return Text(""); + const char *base = Text$as_c_string(Path$base_name(path)); + const char *dot = full ? strchr(base + 1, '.') : strrchr(base + 1, '.'); + const char *extension = dot ? dot + 1 : ""; + return Text$from_str(extension); } public Path_t Path$with_component(Path_t path, Text_t component) @@ -635,10 +629,10 @@ public Path_t Path$with_extension(Path_t path, Text_t extension, bool replace) Text_t last = *(Text_t*)(path.components.data + path.components.stride*(path.components.length-1)); Array$remove_at(&result.components, I(-1), I(1), sizeof(Text_t)); if (replace) { - if (Text$starts_with(last, Text("."))) - last = Text$replace(last, Pattern(".{!.}.{..}"), Text(".@1"), Pattern("@"), false); - else - last = Text$replace(last, Pattern("{!.}.{..}"), Text("@1"), Pattern("@"), false); + const char *base = Text$as_c_string(last); + const char *dot = strchr(base + 1, '.'); + if (dot) + last = Text$from_strn(base, (size_t)(dot - base)); } last = Text$concat(last, extension); |
