aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/api.md71
-rw-r--r--api/paths.md28
-rw-r--r--api/paths.yaml25
3 files changed, 112 insertions, 12 deletions
diff --git a/api/api.md b/api/api.md
index eaf8da17..3af79d37 100644
--- a/api/api.md
+++ b/api/api.md
@@ -342,6 +342,49 @@ assert [x for x in Byte(2).to(5, step=2)] == [Byte(2), Byte(4)]
```
+# CString
+## CString.as_text
+
+```tomo
+CString.as_text : func(str: CString -> Text)
+```
+
+Convert a C string to Text.
+
+Argument | Type | Description | Default
+---------|------|-------------|---------
+str | `CString` | The C string. | -
+
+**Return:** The C string as a Text.
+
+
+**Example:**
+```tomo
+assert CString("Hello").as_text() == "Hello"
+
+```
+## CString.join
+
+```tomo
+CString.join : func(glue: CString, pieces: [CString] -> CString)
+```
+
+Join a list of C strings together with a separator.
+
+Argument | Type | Description | Default
+---------|------|-------------|---------
+glue | `CString` | The C joiner used to between elements. | -
+pieces | `[CString]` | A list of C strings to join. | -
+
+**Return:** A C string of the joined together bits.
+
+
+**Example:**
+```tomo
+assert CString(",").join([CString("a"), CString("b")]) == CString("a,b")
+
+```
+
# Int
## Int.abs
@@ -2565,14 +2608,14 @@ path | `Path` | The path of the file. | -
```tomo
# Safely handle file not being readable:
if lines := (./file.txt).by_line()
-for line in lines
-say(line.upper())
+ for line in lines
+ say(line.upper())
else
-say("Couldn't read file!")
+ say("Couldn't read file!")
# Assume the file is readable and error if that's not the case:
for line in (/dev/stdin).by_line()!
-say(line.upper())
+ say(line.upper())
```
## Path.can_execute
@@ -3019,6 +3062,26 @@ path | `Path` | The path to check. | -
assert (./link).is_symlink() == yes
```
+## Path.lines
+
+```tomo
+Path.lines : func(path: Path -> [Text]?)
+```
+
+Returns a list with the lines of text in a file or returns none if the file could not be opened.
+
+Argument | Type | Description | Default
+---------|------|-------------|---------
+path | `Path` | The path of the file. | -
+
+**Return:** A list of the lines in a file or none if the file couldn't be read.
+
+
+**Example:**
+```tomo
+lines := (./file.txt).lines()!
+
+```
## Path.modified
```tomo
diff --git a/api/paths.md b/api/paths.md
index c69e91d9..07f0560b 100644
--- a/api/paths.md
+++ b/api/paths.md
@@ -108,14 +108,14 @@ path | `Path` | The path of the file. | -
```tomo
# Safely handle file not being readable:
if lines := (./file.txt).by_line()
-for line in lines
-say(line.upper())
+ for line in lines
+ say(line.upper())
else
-say("Couldn't read file!")
+ say("Couldn't read file!")
# Assume the file is readable and error if that's not the case:
for line in (/dev/stdin).by_line()!
-say(line.upper())
+ say(line.upper())
```
## Path.can_execute
@@ -562,6 +562,26 @@ path | `Path` | The path to check. | -
assert (./link).is_symlink() == yes
```
+## Path.lines
+
+```tomo
+Path.lines : func(path: Path -> [Text]?)
+```
+
+Returns a list with the lines of text in a file or returns none if the file could not be opened.
+
+Argument | Type | Description | Default
+---------|------|-------------|---------
+path | `Path` | The path of the file. | -
+
+**Return:** A list of the lines in a file or none if the file couldn't be read.
+
+
+**Example:**
+```tomo
+lines := (./file.txt).lines()!
+
+```
## Path.modified
```tomo
diff --git a/api/paths.yaml b/api/paths.yaml
index 532d9c71..8fbd18dc 100644
--- a/api/paths.yaml
+++ b/api/paths.yaml
@@ -107,14 +107,31 @@ Path.by_line:
example: |
# Safely handle file not being readable:
if lines := (./file.txt).by_line()
- for line in lines
- say(line.upper())
+ for line in lines
+ say(line.upper())
else
- say("Couldn't read file!")
+ say("Couldn't read file!")
# Assume the file is readable and error if that's not the case:
for line in (/dev/stdin).by_line()!
- say(line.upper())
+ say(line.upper())
+
+Path.lines:
+ short: return the lines in a file
+ description: >
+ Returns a list with the lines of text in a file or returns none if the file
+ could not be opened.
+ return:
+ type: '[Text]?'
+ description: >
+ A list of the lines in a file or none if the file couldn't be read.
+ args:
+ path:
+ type: 'Path'
+ description: >
+ The path of the file.
+ example: |
+ lines := (./file.txt).lines()!
Path.can_execute:
short: check execute permissions