summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/pkstr.cpp31
-rw-r--r--src/pkstr.hpp20
3 files changed, 53 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1400a5..7ed862b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,6 +39,8 @@ set(PKE_SOURCE_FILES
src/asset-manager.cpp
src/physics.hpp
src/physics.cpp
+ src/pkstr.hpp
+ src/pkstr.cpp
src/player-input.hpp
src/player-input.cpp
src/plugins.hpp
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 */