summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorPierre-Yves Rollo <dev@pyrollo.com>2019-09-10 15:11:26 +0200
committerSmallJoker <SmallJoker@users.noreply.github.com>2019-11-03 11:45:33 +0100
commit72416a6a1f75d56abfad0f486e57fd32579b3604 (patch)
tree2ff2978c1aec4ee6548474b8c65d3c96bab5b05f /src/util
parent8697090b3564b508af50d40068a61db280f714a6 (diff)
downloadminetest-72416a6a1f75d56abfad0f486e57fd32579b3604.tar.gz
minetest-72416a6a1f75d56abfad0f486e57fd32579b3604.tar.bz2
minetest-72416a6a1f75d56abfad0f486e57fd32579b3604.zip
Formspec: add hypertext element
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string.cpp25
-rw-r--r--src/util/string.h11
2 files changed, 36 insertions, 0 deletions
diff --git a/src/util/string.cpp b/src/util/string.cpp
index 388e8d293..caaef9b30 100644
--- a/src/util/string.cpp
+++ b/src/util/string.cpp
@@ -947,3 +947,28 @@ std::wstring translate_string(const std::wstring &s) {
translate_all(s, i, res);
return res;
}
+
+/**
+ * Create a std::string from a irr::core:stringw.
+ */
+std::string strwtostr(const irr::core::stringw &str)
+{
+ std::string text = core::stringc(str.c_str()).c_str();
+ return text;
+}
+
+/**
+ * Create a irr::core:stringw from a std::string.
+ */
+irr::core::stringw strtostrw(const std::string &str)
+{
+ size_t size = str.size();
+ // s.size() doesn't include NULL terminator
+ wchar_t *text = new wchar_t[size + sizeof(wchar_t)];
+ const char *data = &str[0];
+
+ mbsrtowcs(text, &data, size, NULL);
+
+ text[size] = L'\0';
+ return text;
+}
diff --git a/src/util/string.h b/src/util/string.h
index ab9a4a6c8..3aa11080f 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "irrlichttypes_bloated.h"
+#include "irrString.h"
#include <cstdlib>
#include <string>
#include <cstring>
@@ -723,3 +724,13 @@ inline std::string str_join(const std::vector<std::string> &list,
}
return oss.str();
}
+
+/**
+ * Create a std::string from a irr::core::stringw.
+ */
+std::string strwtostr(const irr::core::stringw &str);
+
+/**
+ * Create a irr::core:stringw from a std::string.
+ */
+irr::core::stringw strtostrw(const std::string &str);