diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 00:50:18 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-23 00:50:18 +0000 |
| commit | 8cb7089b2eb09d40d9497cea40d088d94676a8c6 (patch) | |
| tree | d4a2a33fe35807abc0cdeeb0be93edcbe75a4996 /docs/std/path.md | |
| parent | 3a4a72a38675893c3a1854d05c72b957a6bd9364 (diff) | |
More docs, check 'docs/std'.
Diffstat (limited to 'docs/std/path.md')
| -rw-r--r-- | docs/std/path.md | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/docs/std/path.md b/docs/std/path.md new file mode 100644 index 0000000..0be30fd --- /dev/null +++ b/docs/std/path.md @@ -0,0 +1,58 @@ +# Standard Library: Path (`std/path.zc`) + +`Path` provides cross-platform file path manipulation utilities. It wraps a `String` and handles separators (slash vs backslash) intelligently, though currently biased towards Unix defaults pending full Windows support integration. + +## Usage + +```zc +import "std/path.zc" + +fn main() { + var p = Path::new("/home/user"); + var full_path = p.join("docs/file.txt"); + + println "Full path: {full_path.c_str()}"; + + if (full_path.extension().is_some()) { + println "Extension: {full_path.extension().unwrap()}"; + } +} +``` + +## Structure + +```zc +struct Path { + str: String; +} +``` + +## Methods + +### Construction + +| Method | Signature | Description | +| :--- | :--- | :--- | +| **new** | `Path::new(s: char*) -> Path` | Creates a new Path from a C string. | +| **from_string** | `Path::from_string(s: String) -> Path` | Creates a Path taking ownership of a String. | + +### Manipulation + +| Method | Signature | Description | +| :--- | :--- | :--- | +| **join** | `join(self, other: char*) -> Path` | Joins the current path with `other` using the correct separator. Returns a new Path. | +| **clone** | `clone(self) -> Path` | Creates a deep copy of the Path. | + +### Parsing + +| Method | Signature | Description | +| :--- | :--- | :--- | +| **extension** | `extension(self) -> Option<String>` | Returns the file extension (without the dot), or `None` if no extension. | +| **file_name** | `file_name(self) -> Option<String>` | Returns the last component of the path. | +| **parent** | `parent(self) -> Option<Path>` | Returns the path without its final component. | + +### Access + +| Method | Signature | Description | +| :--- | :--- | :--- | +| **c_str** | `c_str(self) -> char*` | Returns a pointer to the underlying C string. | |
