summaryrefslogtreecommitdiff
path: root/updater/str_utils.cpp
diff options
context:
space:
mode:
authorsje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2006-11-01 14:48:34 +0000
committersje <sje@4f64403b-2f21-0410-a795-97e2b3489a10>2006-11-01 14:48:34 +0000
commitd123e0ce94bf90b2adb0a4000930eb467e293226 (patch)
treed414dea59908105c4d2f256199a610e0a69c8690 /updater/str_utils.cpp
parenta13e82647294da4add976a24335fec50d7bfe905 (diff)
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@16 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'updater/str_utils.cpp')
-rw-r--r--updater/str_utils.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/updater/str_utils.cpp b/updater/str_utils.cpp
new file mode 100644
index 0000000..cadb7b8
--- /dev/null
+++ b/updater/str_utils.cpp
@@ -0,0 +1,99 @@
+#include "common.h"
+#include "str_utils.h"
+
+int code_page = CP_ACP;
+
+void set_codepage() {
+ if(ServiceExists(MS_LANGPACK_GETCODEPAGE))
+ code_page = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
+}
+
+char *w2u(const wchar_t *ws) {
+ if(ws) {
+ int size = WideCharToMultiByte(CP_UTF8, 0, ws, -1, 0, 0, 0, 0);
+ char *buff = (char *)malloc(size);
+ WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, 2048, 0, 0);
+ return buff;
+ } else
+ return 0;
+}
+
+wchar_t *u2w(const char *utfs) {
+ if(utfs) {
+ int size = MultiByteToWideChar(CP_UTF8, 0, utfs, -1, 0, 0);
+ wchar_t *buff = (wchar_t *)malloc(size * sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, utfs, -1, buff, size);
+ return buff;
+ } else
+ return 0;
+}
+
+wchar_t *a2w(const char *as) {
+ int code_page = CP_ACP;
+ if(ServiceExists(MS_LANGPACK_GETCODEPAGE)) code_page = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
+ int size = MultiByteToWideChar(code_page, 0, as, -1, 0, 0);
+ wchar_t *buff = (wchar_t *)malloc(size * sizeof(wchar_t));
+ MultiByteToWideChar(code_page, 0, as, -1, buff, size);
+ return buff;
+}
+
+char *w2a(const wchar_t *ws) {
+ int code_page = CP_ACP;
+ if(ServiceExists(MS_LANGPACK_GETCODEPAGE)) code_page = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
+ int size = WideCharToMultiByte(code_page, 0, ws, -1, 0, 0, 0, 0);
+ char *buff = (char *)malloc(size);
+ WideCharToMultiByte(code_page, 0, ws, -1, buff, 2048, 0, 0);
+ return buff;
+}
+
+char *t2a(const TCHAR *ts) {
+#ifdef _UNICODE
+ return w2a(ts);
+#else
+ return _strdup(ts);
+#endif
+}
+
+TCHAR *a2t(const char *as) {
+#ifdef _UNICODE
+ return a2w(as);
+#else
+ return _strdup(as);
+#endif
+}
+
+TCHAR *u2t(const char *utfs) {
+#ifdef _UNICODE
+ return u2w(utfs);
+#else
+ wchar_t *ws = u2w(utfs);
+ char *ret = w2a(ws);
+ free(ws);
+ return ret;
+#endif
+}
+
+char *t2u(const TCHAR *ts) {
+#ifdef _UNICODE
+ return w2u(ts);
+#else
+ wchar_t *ws = a2w(ts);
+ char *ret = w2u(ws);
+ free(ws);
+ return ret;
+#endif
+}
+
+char *u2a(const char *utfs) {
+ wchar_t *ws = u2w(utfs);
+ char *ret = w2a(ws);
+ free(ws);
+ return ret;
+}
+
+char *a2u(const char *as) {
+ wchar_t *ws = a2w(as);
+ char *ret = w2u(ws);
+ free(ws);
+ return ret;
+}