diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-09 04:19:31 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-09 04:19:31 -0400 |
| commit | 6f174aa85dc935b717c160174326bbfccd76b0ff (patch) | |
| tree | ffabe8e7ade271c76572d7bb5637cf353a4e5326 /builtins/path.c | |
| parent | 4f2de3568f903cabecb52ba8b3a5e07de925d1ce (diff) | |
Fix some logic for extensions and base names
Diffstat (limited to 'builtins/path.c')
| -rw-r--r-- | builtins/path.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/builtins/path.c b/builtins/path.c index 7c9df396..caabf2ab 100644 --- a/builtins/path.c +++ b/builtins/path.c @@ -325,19 +325,24 @@ public Text_t Path$write_unique(Path_t path, Text_t text) public Path_t Path$parent(Path_t path) { - return Text$replace(path, Pattern("{..}/{!/}{end}"), Text("@1"), Text("@"), false); + return Text$replace(path, Pattern("{0+..}/{!/}{end}"), Text("@1"), Text("@"), false); } public Text_t Path$base_name(Path_t path) { - return Text$replace(path, Pattern("{..}/{!/}{end}"), Text("@2"), Text("@"), false); + if (Text$matches(path, Pattern("/{end}"))) + return Text$replace(path, Pattern("{0+..}/{!/}/{end}"), Text("@2"), Text("@"), false); + else + return Text$replace(path, Pattern("{0+..}/{!/}{end}"), Text("@2"), Text("@"), false); } public Text_t Path$extension(Path_t path, bool full) { Text_t base = Path$base_name(path); - if (Text$has(base, Pattern("{!.}.{!.}"))) - return Text$replace(base, full ? Pattern("{!.}.{..}{end}") : Pattern("{..}.{!.}{end}"), Text("@2"), Text("@"), false); + 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); else return Text(""); } |
