summaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-05-17 23:31:51 +0200
committerMichael Lutz <michi@icosahedron.de>2020-05-21 20:02:34 +0200
commitc082f570cebd237c35de9caa08fcc84a9c44e95d (patch)
tree7e0e85e1a3f14db83a82e4861899578c2383529d /src/string.cpp
parent808c8198d5ab61c457d0351ff7971b75ee17c10a (diff)
downloadopenttd-c082f570cebd237c35de9caa08fcc84a9c44e95d.tar.xz
Codechange: Use std::string when translating TTDP NewGRF string codes.
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp
index dea369037..90d287c9e 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -18,6 +18,7 @@
#include <stdarg.h>
#include <ctype.h> /* required for tolower() */
+#include <sstream>
#ifdef _MSC_VER
#include <errno.h> // required by vsnprintf implementation for MSVC
@@ -479,11 +480,13 @@ size_t Utf8Decode(WChar *c, const char *s)
/**
* Encode a unicode character and place it in the buffer.
+ * @tparam T Type of the buffer.
* @param buf Buffer to place character.
* @param c Unicode character to encode.
* @return Number of characters in the encoded sequence.
*/
-size_t Utf8Encode(char *buf, WChar c)
+template <class T>
+inline size_t Utf8Encode(T buf, WChar c)
{
if (c < 0x80) {
*buf = c;
@@ -510,6 +513,16 @@ size_t Utf8Encode(char *buf, WChar c)
return 1;
}
+size_t Utf8Encode(char *buf, WChar c)
+{
+ return Utf8Encode<char *>(buf, c);
+}
+
+size_t Utf8Encode(std::ostreambuf_iterator<char> &buf, WChar c)
+{
+ return Utf8Encode<std::ostreambuf_iterator<char> &>(buf, c);
+}
+
/**
* Properly terminate an UTF8 string to some maximum length
* @param s string to check if it needs additional trimming