aboutsummaryrefslogtreecommitdiff
path: root/02/src/string-view.h
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 05:31:06 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 06:14:42 +0000
commit9e1d304cac5367c3dbb1ca14700736680bd3a804 (patch)
tree31f328747acb934d365d423adfda144818ff5ad4 /02/src/string-view.h
downloadlab-01-05-master.tar.gz
publishHEADmaster
Diffstat (limited to '02/src/string-view.h')
-rw-r--r--02/src/string-view.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/02/src/string-view.h b/02/src/string-view.h
new file mode 100644
index 0000000..fa42d77
--- /dev/null
+++ b/02/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
17struct 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
32size_t string_view_length (struct string_view sv);
33struct string_view string_view_from_cstr (const char *cstr);
34struct string_view duplicate_string_view (struct string_view sv);
35struct string_view duplicate_string_view_as_cstr (struct string_view sv);
36struct string_view string_view_strdup (const char *cstr);
37int string_view_compare (struct string_view lhs, struct string_view rhs);
38bool string_view_starts_with (struct string_view sv, struct string_view prefix);
39struct string_view string_view_dirname (struct string_view);
40struct string_view string_view_basename (struct string_view);
41struct string_view string_view_pop_up_to (struct string_view *, char);
42struct 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