diff options
| author | 2026-11-11 05:31:06 +0000 | |
|---|---|---|
| committer | 2026-11-11 06:14:42 +0000 | |
| commit | 9e1d304cac5367c3dbb1ca14700736680bd3a804 (patch) | |
| tree | 31f328747acb934d365d423adfda144818ff5ad4 /03/src/string-view.h | |
| download | lab-01-05-master.tar.gz | |
Diffstat (limited to '03/src/string-view.h')
| -rw-r--r-- | 03/src/string-view.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/03/src/string-view.h b/03/src/string-view.h new file mode 100644 index 0000000..fa42d77 --- /dev/null +++ b/03/src/string-view.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // src/string-view.h | ||
| 2 | // | ||
| 3 | // Copyright (c) 2026 Martin Michalec <martin@michalec.dev> | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: MIT | ||
| 6 | // | ||
| 7 | // Commentary: | ||
| 8 | // | ||
| 9 | // Code: | ||
| 10 | |||
| 11 | #ifndef INCLUDED_STRING_VIEW_H | ||
| 12 | #define INCLUDED_STRING_VIEW_H | ||
| 13 | |||
| 14 | #include <stddef.h> | ||
| 15 | #include <stdbool.h> | ||
| 16 | |||
| 17 | struct string_view { | ||
| 18 | const char *begin; | ||
| 19 | const char *end; | ||
| 20 | }; | ||
| 21 | |||
| 22 | #define SVNULL ((struct string_view) {0}) | ||
| 23 | #define SVLEN string_view_length | ||
| 24 | #define SVFMT(SV) (int) SVLEN (SV), (SV).begin | ||
| 25 | #define SVCSTR string_view_from_cstr | ||
| 26 | #define SVDUP duplicate_string_view | ||
| 27 | #define SVDUP0 duplicate_string_view_as_cstr | ||
| 28 | #define SVSTRDUP string_view_strdup | ||
| 29 | #define SVCMP string_view_compare | ||
| 30 | #define SVSB(SB) ((struct string_view) { (SB).string, (SB).string + (SB).length }) | ||
| 31 | |||
| 32 | size_t string_view_length (struct string_view sv); | ||
| 33 | struct string_view string_view_from_cstr (const char *cstr); | ||
| 34 | struct string_view duplicate_string_view (struct string_view sv); | ||
| 35 | struct string_view duplicate_string_view_as_cstr (struct string_view sv); | ||
| 36 | struct string_view string_view_strdup (const char *cstr); | ||
| 37 | int string_view_compare (struct string_view lhs, struct string_view rhs); | ||
| 38 | bool string_view_starts_with (struct string_view sv, struct string_view prefix); | ||
| 39 | struct string_view string_view_dirname (struct string_view); | ||
| 40 | struct string_view string_view_basename (struct string_view); | ||
| 41 | struct string_view string_view_pop_up_to (struct string_view *, char); | ||
| 42 | struct string_view string_view_pop_n (struct string_view *, size_t n); | ||
| 43 | |||
| 44 | #endif // INCLUDED_STRING_VIEW_H | ||
| 45 | |||
| 46 | // src/string-view.h ends here | ||
