]> git.lizzy.rs Git - minetest.git/blobdiff - src/util/string.h
Fix segfaults caused by the Environment not being initialized yet
[minetest.git] / src / util / string.h
index 72d3c6075b97dc0312659d98b01a80f41c674103..793baad0ea729f90c3731ea741bca26f2ca3fccf 100644 (file)
@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define TOSTRING(x) STRINGIFY(x)
 
 // Checks whether a byte is an inner byte for an utf-8 multibyte sequence
-#define IS_UTF8_MULTB_INNER(x) (((unsigned char)x >= 0x80) && ((unsigned char)x <= 0xc0))
+#define IS_UTF8_MULTB_INNER(x) (((unsigned char)x >= 0x80) && ((unsigned char)x < 0xc0))
 
 typedef std::map<std::string, std::string> StringMap;
 
@@ -47,6 +47,8 @@ struct FlagDesc {
 std::wstring utf8_to_wide(const std::string &input);
 std::string wide_to_utf8(const std::wstring &input);
 
+wchar_t *utf8_to_wide_c(const char *str);
+
 // NEVER use those two functions unless you have a VERY GOOD reason to
 // they just convert between wide and multibyte encoding
 // multibyte encoding depends on current locale, this is no good, especially on Windows
@@ -428,10 +430,12 @@ inline std::string wrap_rows(const std::string &from,
 
        size_t character_idx = 0;
        for (size_t i = 0; i < from.size(); i++) {
-               if (character_idx > 0 && character_idx % row_len == 0)
-                       to += '\n';
-               if (!IS_UTF8_MULTB_INNER(from[i]))
+               if (!IS_UTF8_MULTB_INNER(from[i])) {
+                       // Wrap string after last inner byte of char
+                       if (character_idx > 0 && character_idx % row_len == 0)
+                               to += '\n';
                        character_idx++;
+               }
                to += from[i];
        }