aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-01-29 14:03:27 +0100
committersfan5 <sfan5@live.de>2021-02-02 20:46:08 +0100
commitc834d2ab25694ef2d67dc24f85f304269d202c8e (patch)
treec62a57d0cdbca950b9c7cb1a58666b6b77760bc2 /src/util
parent5e392cf34f8e062dd0533619921223656e32598a (diff)
downloadminetest-c834d2ab25694ef2d67dc24f85f304269d202c8e.tar.gz
minetest-c834d2ab25694ef2d67dc24f85f304269d202c8e.tar.bz2
minetest-c834d2ab25694ef2d67dc24f85f304269d202c8e.zip
Drop wide/narrow conversion functions
The only valid usecase for these is interfacing with OS APIs that want a locale/OS-specific multibyte encoding. But they weren't used for that anywhere, instead UTF-8 is pretty much assumed when it comes to that. Since these are only a potential source of bugs and do not fulfil their purpose at all, drop them entirely.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string.cpp59
-rw-r--r--src/util/string.h28
2 files changed, 2 insertions, 85 deletions
diff --git a/src/util/string.cpp b/src/util/string.cpp
index 7e6d6d3b3..611ad35cb 100644
--- a/src/util/string.cpp
+++ b/src/util/string.cpp
@@ -175,62 +175,6 @@ wchar_t *utf8_to_wide_c(const char *str)
return ret_c;
}
-// You must free the returned string!
-// The returned string is allocated using new
-wchar_t *narrow_to_wide_c(const char *str)
-{
- wchar_t *nstr = nullptr;
-#if defined(_WIN32)
- int nResult = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) str, -1, 0, 0);
- if (nResult == 0) {
- errorstream<<"gettext: MultiByteToWideChar returned null"<<std::endl;
- } else {
- nstr = new wchar_t[nResult];
- MultiByteToWideChar(CP_UTF8, 0, (LPCSTR) str, -1, (WCHAR *) nstr, nResult);
- }
-#else
- size_t len = strlen(str);
- nstr = new wchar_t[len + 1];
-
- std::wstring intermediate = narrow_to_wide(str);
- memset(nstr, 0, (len + 1) * sizeof(wchar_t));
- memcpy(nstr, intermediate.c_str(), len * sizeof(wchar_t));
-#endif
-
- return nstr;
-}
-
-std::wstring narrow_to_wide(const std::string &mbs) {
-#ifdef __ANDROID__
- return utf8_to_wide(mbs);
-#else
- size_t wcl = mbs.size();
- Buffer<wchar_t> wcs(wcl + 1);
- size_t len = mbstowcs(*wcs, mbs.c_str(), wcl);
- if (len == (size_t)(-1))
- return L"<invalid multibyte string>";
- wcs[len] = 0;
- return *wcs;
-#endif
-}
-
-
-std::string wide_to_narrow(const std::wstring &wcs)
-{
-#ifdef __ANDROID__
- return wide_to_utf8(wcs);
-#else
- size_t mbl = wcs.size() * 4;
- SharedBuffer<char> mbs(mbl+1);
- size_t len = wcstombs(*mbs, wcs.c_str(), mbl);
- if (len == (size_t)(-1))
- return "Character conversion failed!";
-
- mbs[len] = 0;
- return *mbs;
-#endif
-}
-
std::string urlencode(const std::string &str)
{
@@ -757,7 +701,8 @@ void translate_string(const std::wstring &s, Translations *translations,
} else {
// This is an escape sequence *inside* the template string to translate itself.
// This should not happen, show an error message.
- errorstream << "Ignoring escape sequence '" << wide_to_narrow(escape_sequence) << "' in translation" << std::endl;
+ errorstream << "Ignoring escape sequence '"
+ << wide_to_utf8(escape_sequence) << "' in translation" << std::endl;
}
}
diff --git a/src/util/string.h b/src/util/string.h
index ec14e9a2d..d4afcaec8 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -73,16 +73,6 @@ std::string wide_to_utf8(const std::wstring &input);
// The returned string is allocated using new[]
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
-
-// You must free the returned string!
-// The returned string is allocated using new
-wchar_t *narrow_to_wide_c(const char *str);
-std::wstring narrow_to_wide(const std::string &mbs);
-std::string wide_to_narrow(const std::wstring &wcs);
-
std::string urlencode(const std::string &str);
std::string urldecode(const std::string &str);
u32 readFlagString(std::string str, const FlagDesc *flagdesc, u32 *flagmask);
@@ -355,11 +345,6 @@ inline s32 mystoi(const std::string &str, s32 min, s32 max)
return i;
}
-
-// MSVC2010 includes it's own versions of these
-//#if !defined(_MSC_VER) || _MSC_VER < 1600
-
-
/**
* Returns a 32-bit value reprensented by the string \p str (decimal).
* @see atoi(3) for further limitations
@@ -369,17 +354,6 @@ inline s32 mystoi(const std::string &str)
return atoi(str.c_str());
}
-
-/**
- * Returns s 32-bit value represented by the wide string \p str (decimal).
- * @see atoi(3) for further limitations
- */
-inline s32 mystoi(const std::wstring &str)
-{
- return mystoi(wide_to_narrow(str));
-}
-
-
/**
* Returns a float reprensented by the string \p str (decimal).
* @see atof(3)
@@ -389,8 +363,6 @@ inline float mystof(const std::string &str)
return atof(str.c_str());
}
-//#endif
-
#define stoi mystoi
#define stof mystof