From 2b52563cd9298b172935339a2afd05d80dd07e4c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 9 Apr 2015 09:23:44 -0400 Subject: [PATCH] Split toUTF16() into a new file; other Windows text functions will also be there. --- text_windows.c | 18 ++++++++++++++++++ uipriv_windows.h | 2 +- util_windows.c | 16 ---------------- 3 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 text_windows.c diff --git a/text_windows.c b/text_windows.c new file mode 100644 index 00000000..e483a954 --- /dev/null +++ b/text_windows.c @@ -0,0 +1,18 @@ +// 9 april 2015 +#include "uipriv_windows.h" + +#define MBTWC(str, wstr, bufsiz) MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, bufsiz) + +WCHAR *toUTF16(const char *str) +{ + WCHAR *wstr; + int n; + + n = MBTWC(str, NULL, 0); + if (n == 0) + logLastError("error figuring out number of characters to convert to in toUTF16()"); + wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); + if (MBTWC(str, wstr, n) != n) + logLastError("error converting from UTF-8 to UTF-16 in toUTF16()"); + return wstr; +} diff --git a/uipriv_windows.h b/uipriv_windows.h index 5383b54e..99c742be 100644 --- a/uipriv_windows.h +++ b/uipriv_windows.h @@ -47,7 +47,7 @@ extern int nCmdShow; extern HFONT hMessageFont; extern HWND initialParent; -// util_windows.c +// text_windows.c extern WCHAR *toUTF16(const char *); // container_windows.c diff --git a/util_windows.c b/util_windows.c index 5034daed..4959a703 100644 --- a/util_windows.c +++ b/util_windows.c @@ -1,22 +1,6 @@ // 6 april 2015 #include "uipriv_windows.h" -#define MBTWC(str, wstr, bufsiz) MultiByteToWideChar(CP_UTF8, 0, str, -1, wstr, bufsiz) - -WCHAR *toUTF16(const char *str) -{ - WCHAR *wstr; - int n; - - n = MBTWC(str, NULL, 0); - if (n == 0) - logLastError("error figuring out number of characters to convert to in toUTF16()"); - wstr = (WCHAR *) uiAlloc(n * sizeof (WCHAR), "WCHAR[]"); - if (MBTWC(str, wstr, n) != n) - logLastError("error converting from UTF-8 to UTF-16 in toUTF16()"); - return wstr; -} - intmax_t uiWindowsWindowTextWidth(HWND hwnd) { int len;