diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-16 15:33:15 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-16 15:33:15 -0400 |
| commit | 2e184ab46e01db678cef676843a02ce7d3adb085 (patch) | |
| tree | e0c219fbf0f5584428dfc43e288d39cfeb4a8496 | |
| parent | e31e3d1514717ff2de3d76d13e7edc013485cbae (diff) | |
Fix up paths API to use updated Text:match()
| -rw-r--r-- | stdlib/paths.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/stdlib/paths.c b/stdlib/paths.c index afdd5426..01228537 100644 --- a/stdlib/paths.c +++ b/stdlib/paths.c @@ -145,7 +145,7 @@ public Text_t Path$relative(Path_t path, Path_t relative_to) { path = Path$resolved(path, relative_to); relative_to = Path$resolved(relative_to, Path(".")); - if (Text$matches(path, Patterns(Pattern("{start}"), relative_to, Pattern("{0+..}")))) + if (Text$starts_with(path, Text$concat(relative_to, Text("/")))) return Text$slice(path, I(relative_to.length + 2), I(-1)); return path; } @@ -438,10 +438,12 @@ public 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); - if (Text$matches(base, Pattern(".{!.}.{..}"))) - return Text$replace(base, full ? Pattern(".{!.}.{..}") : Pattern(".{..}.{!.}{end}"), Text("@2"), Text("@"), false); - else if (Text$matches(base, Pattern("{!.}.{..}"))) - return Text$replace(base, full ? Pattern("{!.}.{..}") : Pattern("{..}.{!.}{end}"), Text("@2"), Text("@"), false); + 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(""); } |
