# path.h ## Overview
API for path manipulation.
## Index
`TM_PATH_API_NAME`

`struct tm_path_api`
`extension()`
`extension_cstr()`
`strip_extension()`
`base()`
`base_cstr()`
`directory()`
`pop_last()`
`pop_first()`
`split_all()`
`join()`

## API
### `TM_PATH_API_NAME`
~~~c #define TM_PATH_API_NAME "tm_path_api" ~~~
### `struct tm_path_api`
API for path manipulation #### `extension()` ~~~c tm_str_t (*extension)(tm_str_t path); ~~~ Returns the file extension of the `path`, i.e. everything after the last ".". path | extension ---------------- | ------- "test.jpg" | ".jpg" "test" | (null) ".test" | ".test" ".test.jpg" | ".jpg" "a.b/test" | (null) "" | (null) (null) | (null) #### `extension_cstr()` ~~~c const char *(*extension_cstr)(const char *path); ~~~ As `extension()` but operates on C strings, instead of `tm_str_t`. #### `strip_extension()` ~~~c tm_str_t (*strip_extension)(tm_str_t path); ~~~ Returns the `path` without the file extension. Note that it is always true that: ~~~c path == strip_extension(path) + extension(path) ~~~ path | strip_extension ---------------- | ------- "test.jpg" | "test" "test" | "test" ".test" | "" ".test.jpg" | ".test" "a.b/test" | "a.b/test" "" | "" (null) | (null) #### `base()` ~~~c tm_str_t (*base)(tm_str_t path); ~~~ Returns the last element of the `path`. Trailing slashes are removed. If the path is empty, returns ".". If the path consists of just slashes, returns "/". path | base ---------------- | -------- "test.jpg" | "test.jpg" "a/b/c" | "c" "a/b/c/" | "c" "a/b/c///" | "c" "/" | "/" "////" | "/" "C:\" | "C:" "" | "." #### `base_cstr()` ~~~c const char *(*base_cstr)(const char *path); ~~~ As base, but operates on C strings, instead of `tm_str_t`. #### `directory()` ~~~c tm_str_t (*directory)(tm_str_t path); ~~~ Returns the "directory" of the `path`. I.e. everything before the `base()`. Trailing slashes are removed, unless the directory is the root directory. If there is no directory in the path or if the path is empty, returns ".". path | dir ---------------- | -------- "test.jpg" | "." "a/b/c" | "a/b" "a/b/c/" | "a/b" "a/b/c///" | "a/b" "/a" | "/" "/" | "/" "////" | "/" "C:\" | "." "" | "." #### `pop_last()` ~~~c tm_str_t (*pop_last)(tm_str_t *path); ~~~ Pops the last elements of the path. Returns `base()` and sets `path` to `directory()`. #### `pop_first()` ~~~c tm_str_t (*pop_first)(tm_str_t *path); ~~~ Pops the first element of the `path` and updates `path` to point to the rest of the elements. path | first | rest ---------------- | -------- | ---------- "test.jpg" | "test.jpg" | NULL "a/b/c" | "a" | "b/c" "a//b/c///" | "a" | "b/c///" "/a/b/c" | "/" | "a/b/c" "C:\a\b\c" | "C:" | "a\b\c" "/" | "/" | NULL "////" | "/" | NULL "" | "." | NULL #### `split_all()` ~~~c tm_str_t *(*split_all)(tm_str_t path, struct tm_temp_allocator_i *ta); ~~~ Splits the path into a `carray.inl` of `tm_str_t` representing the name of each directory and file. The array is allocated using `ta`. path | return value ---------------| -------------------- a/b/c/test.jpg | [a, b, c, test.jpeg] #### `join()` ~~~c tm_str_t (*join)(tm_str_t a, tm_str_t b, struct tm_temp_allocator_i *ta); ~~~ Joins the paths `a` and `b`. I.e., produces "a/b". Note that "/" is always used to join the paths, regardless of platform. The returned string is allocated using `ta`.