summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-12-07 23:12:29 -0500
committerJonathan Bradley <jcb@pikum.xyz>2023-12-07 23:12:29 -0500
commitb6e7a0c2f7ef0bcb6d5ed0806c851b5312a68b13 (patch)
tree567cad562b39d296c3b56cdd17a45d0df74a254b /src
parent8bbe530d7e5162ed47977c0381e61ed68c8f8ada (diff)
add pkstr
Diffstat (limited to 'src')
-rw-r--r--src/pkstr.cpp31
-rw-r--r--src/pkstr.hpp20
2 files changed, 51 insertions, 0 deletions
diff --git a/src/pkstr.cpp b/src/pkstr.cpp
new file mode 100644
index 0000000..10e656c
--- /dev/null
+++ b/src/pkstr.cpp
@@ -0,0 +1,31 @@
+
+#include "pkstr.hpp"
+#include <cstring>
+
+pkstr to_pkstr(char *s) {
+ return pkstr {
+ .length = static_cast<int64_t>(strlen(s)),
+ .val = s,
+ };
+}
+
+pkstr to_pkstr(const cpkstr &s) {
+ return pkstr {
+ .length = s.length,
+ .val = const_cast<char *>(s.val),
+ };
+}
+
+cpkstr to_cpkstr(const char *s) {
+ return cpkstr {
+ .length = static_cast<int64_t>(strlen(s)),
+ .val = s,
+ };
+}
+
+cpkstr to_cpkstr(const pkstr &s) {
+ return cpkstr {
+ .length = s.length,
+ .val = s.val,
+ };
+}
diff --git a/src/pkstr.hpp b/src/pkstr.hpp
new file mode 100644
index 0000000..0f2fb0d
--- /dev/null
+++ b/src/pkstr.hpp
@@ -0,0 +1,20 @@
+#ifndef PKE_STRING_HPP
+#define PKE_STRING_HPP
+
+#include <cstdint>
+
+struct pkstr {
+ int64_t length = 0;
+ char *val = nullptr;
+};
+struct cpkstr {
+ int64_t length = 0;
+ const char *val = nullptr;
+};
+
+pkstr to_pkstr(char *s);
+pkstr to_pkstr(const cpkstr &s);
+cpkstr to_cpkstr(const char *s);
+cpkstr to_cpkstr(const pkstr &s);
+
+#endif /* PKE_STRING_HPP */