summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-02-24 19:08:21 +0100
committerTyge Løvset <[email protected]>2021-02-24 19:08:21 +0100
commit1745da92874e1799c7d60f6e6810b398e9ab9f15 (patch)
treee2fcb84239a7e6a0711304fdf28618344cf7507e /docs
parent46552181642b8ee52bc1a6e426c31b5c65aea499 (diff)
downloadSTC-modified-1745da92874e1799c7d60f6e6810b398e9ab9f15.tar.gz
STC-modified-1745da92874e1799c7d60f6e6810b398e9ab9f15.zip
More docs and some file renames.
Diffstat (limited to 'docs')
-rw-r--r--docs/ccommon_api.md21
-rw-r--r--docs/cstr_api.md5
2 files changed, 12 insertions, 14 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index ed8ae3d4..4c40c998 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -1,6 +1,6 @@
# STC [ccommon](../stc/ccommon.h): Common definitions and handy macros
-The following handy macros are completely safe to use, i.e. they have no side-effects.
+The following handy macros are safe to use, i.e. have no side-effects.
### c_init, c_emplace_items
**c_init** declares and initializes any container with an array of elements. **c_emplace_items** adds elements to any existing container:
@@ -50,27 +50,26 @@ c_foreach (i, csset_x, it, csset_x_end(&set)) printf(" %d", *i.ref);
```
### c_withfile, c_breakwith
-Simplifies reading a file. Use **c_breakwith** if you need to break out of the block. Example:
+Simplifies reading a file. Use only **c_breakwith** to break out of the block if needed. Example:
```c
-// Put each line of a text file into a vector of strings
+// Load each line of a text file into a vector of strings
#include <errno.h>
#include <stc/cstr.h>
#include <stc/cvec.h>
using_cvec_str();
-cvec_str // on return, check global errno variable for errors
-readFile(const char* name) {
+cvec_str readFile(const char* name) {
cvec_str vec = cvec_str_init();
- // Next line handles declaring, opening, and closing a FILE*
- c_withfile (f, fopen(name, "r")) {
- cstr_t line = cstr_inits;
- while (cstr_getline(&line, f))
+ // Next line declares, opens, and closes the FILE*
+ c_withfile (fp, fopen(name, "r")) {
+ cstr_t line = cstr_init();
+ while (cstr_getline(&line, fp))
cvec_str_emplace_back(&vec, line.str);
cstr_del(&line);
}
- return vec;
+ return vec; // receiver should check errno variable
}
```
@@ -94,4 +93,4 @@ Memory allocator for the entire library. Macros can be overloaded by the user.
### c_swap, c_arraylen
- **c_swap(type, x, y)**: Simple macro for swapping internals of two objects.
-- **c_arraylen(array)**: Return number of elements in an array, e.g. `int array[] = {1, 2, 3, 4};
+- **c_arraylen(array)**: Return number of elements in an array, e.g. `int array[] = {1, 2, 3, 4};`
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index de20e89e..11cd1214 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -91,7 +91,7 @@ Helper methods, used by other container types.
| Type name | Type definition | Used to represent... |
|:------------------|:---------------------------------|:-------------------------|
-| `cstr, cstr_t` | `struct { const char *str; }` | The string type |
+| `cstr` | `struct { const char *str; }` | The string type |
| `cstr_value_t` | `char` | The string element type |
| `cstr_iter_t` | `struct { cstr_value_t *ref; }` | cstr iterator |
@@ -99,8 +99,7 @@ Helper methods, used by other container types.
| Name | Value |
|:------------------|:-----------------|
-| `cstr_inits` | `{...}` |
-| `cstr_npos` | `-1ull` |
+| `cstr_npos` | `(-1ull)` |
## Example
```c