Add Path.base_name(), Path.parent(), Path.extension()
This commit is contained in:
parent
8423a7ed07
commit
3081da3dd0
@ -323,6 +323,25 @@ public Text_t Path$write_unique(Path_t path, Text_t text)
|
||||
return Text$format("%s", buf);
|
||||
}
|
||||
|
||||
public Path_t Path$parent(Path_t path)
|
||||
{
|
||||
return Text$replace(path, Pattern("{..}/{!/}{end}"), Text("@1"), Text("@"), false);
|
||||
}
|
||||
|
||||
public Text_t Path$base_name(Path_t path)
|
||||
{
|
||||
return Text$replace(path, Pattern("{..}/{!/}{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);
|
||||
else
|
||||
return Text("");
|
||||
}
|
||||
|
||||
public const TypeInfo Path$info = {
|
||||
.size=sizeof(Path_t),
|
||||
.align=__alignof__(Path_t),
|
||||
|
@ -33,6 +33,9 @@ Array_t Path$files(Path_t path, bool include_hidden);
|
||||
Array_t Path$subdirectories(Path_t path, bool include_hidden);
|
||||
Path_t Path$unique_directory(Path_t path);
|
||||
Text_t Path$write_unique(Path_t path, Text_t text);
|
||||
Path_t Path$parent(Path_t path);
|
||||
Text_t Path$base_name(Path_t path);
|
||||
Text_t Path$extension(Path_t path, bool full);
|
||||
|
||||
extern const TypeInfo Path$info;
|
||||
|
||||
|
@ -250,15 +250,18 @@ env_t *new_compilation_unit(CORD *libname)
|
||||
)},
|
||||
{"Path", Type(TextType, .lang="Path", .env=namespace_env(env, "Path")), "Text_t", "Text$info", TypedArray(ns_entry_t,
|
||||
{"append", "Path$append", "func(path:Path, text:Text, permissions=0o644_i32)"},
|
||||
{"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]"},
|
||||
{"is_directory", "Path$is_directory", "func(path:Path, follow_symlinks=yes)->Bool"},
|
||||
{"is_file", "Path$is_file", "func(path:Path, follow_symlinks=yes)->Bool"},
|
||||
{"is_socket", "Path$is_socket", "func(path:Path, follow_symlinks=yes)->Bool"},
|
||||
{"is_symlink", "Path$is_symlink", "func(path:Path)->Bool"},
|
||||
{"parent", "Path$parent", "func(path:Path)->Path"},
|
||||
{"read", "Path$read", "func(path:Path)->Text"},
|
||||
{"relative", "Path$relative", "func(path:Path, relative_to=(./))->Path"},
|
||||
{"remove", "Path$remove", "func(path:Path, ignore_missing=no)"},
|
||||
|
Loading…
Reference in New Issue
Block a user