Fix some logic for extensions and base names
This commit is contained in:
parent
4f2de3568f
commit
6f174aa85d
@ -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("");
|
||||
}
|
||||
|
@ -253,7 +253,6 @@ env_t *new_compilation_unit(CORD *libname)
|
||||
{"base_name", "Path$base_name", "func(path:Path)->Text"},
|
||||
{"children", "Path$children", "func(path:Path, include_hidden=no)->[Path]"},
|
||||
{"create_directory", "Path$create_directory", "func(path:Path, permissions=0o644_i32)"},
|
||||
{"escape_text", "Path$escape_text", "func(text:Text)->Path"},
|
||||
{"exists", "Path$exists", "func(path:Path)->Bool"},
|
||||
{"extension", "Path$extension", "func(path:Path, full=yes)->Text"},
|
||||
{"files", "Path$children", "func(path:Path, include_hidden=no)->[Path]"},
|
||||
|
Loading…
Reference in New Issue
Block a user