From b6e7a0c2f7ef0bcb6d5ed0806c851b5312a68b13 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Thu, 7 Dec 2023 23:12:29 -0500 Subject: add pkstr --- src/pkstr.cpp | 31 +++++++++++++++++++++++++++++++ src/pkstr.hpp | 20 ++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/pkstr.cpp create mode 100644 src/pkstr.hpp (limited to 'src') 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 + +pkstr to_pkstr(char *s) { + return pkstr { + .length = static_cast(strlen(s)), + .val = s, + }; +} + +pkstr to_pkstr(const cpkstr &s) { + return pkstr { + .length = s.length, + .val = const_cast(s.val), + }; +} + +cpkstr to_cpkstr(const char *s) { + return cpkstr { + .length = static_cast(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 + +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 */ -- cgit v1.2.3