diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-05-17 16:13:55 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-05-17 16:13:55 -0400 |
| commit | 13e7d04a74f7ad0b9b9dc96f681d091b65dce5ec (patch) | |
| tree | 321c63e528b939beab2f6f2c46192ab507546735 /src/stdlib | |
| parent | 8febea9aebe05644731bb68c297d3d13649a8dcb (diff) | |
Add `modules.ini` file for import aliases, as well as default aliases
for the built-in modules.
Diffstat (limited to 'src/stdlib')
| -rw-r--r-- | src/stdlib/paths.c | 13 | ||||
| -rw-r--r-- | src/stdlib/paths.h | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 6b16916c..5047d615 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -609,20 +609,25 @@ public Text_t Path$extension(Path_t path, bool full) return Text$from_str(extension); } -public Path_t Path$with_component(Path_t path, Text_t component) +public Path_t Path$child(Path_t path, Text_t name) { - if (Text$has(component, Text("/")) || Text$has(component, Text(";"))) - fail("Path component has invalid characters: ", component); + if (Text$has(name, Text("/")) || Text$has(name, Text(";"))) + fail("Path name has invalid characters: ", name); Path_t result = { .type.$tag=path.type.$tag, .components=path.components, }; LIST_INCREF(result.components); - List$insert(&result.components, &component, I(0), sizeof(Text_t)); + List$insert(&result.components, &name, I(0), sizeof(Text_t)); clean_components(&result.components); return result; } +public Path_t Path$sibling(Path_t path, Text_t name) +{ + return Path$child(Path$parent(path), name); +} + public Path_t Path$with_extension(Path_t path, Text_t extension, bool replace) { if (path.components.length == 0) diff --git a/src/stdlib/paths.h b/src/stdlib/paths.h index 31d676b7..4f94d3e4 100644 --- a/src/stdlib/paths.h +++ b/src/stdlib/paths.h @@ -51,7 +51,8 @@ Path_t Path$write_unique_bytes(Path_t path, List_t bytes); Path_t Path$parent(Path_t path); Text_t Path$base_name(Path_t path); Text_t Path$extension(Path_t path, bool full); -Path_t Path$with_component(Path_t path, Text_t component); +Path_t Path$child(Path_t path, Text_t name); +Path_t Path$sibling(Path_t path, Text_t name); Path_t Path$with_extension(Path_t path, Text_t extension, bool replace); Path_t Path$current_dir(void); Closure_t Path$by_line(Path_t path); |
