Mercurial > trustbridge
changeset 1158:ffdc8cba139a
(issue36) Add acp_to_wchar based on utf8_to_wchar
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 18 Sep 2014 15:43:48 +0200 (2014-09-18) |
parents | fd7d04bb37cb |
children | 0ddb173bcd8b |
files | common/strhelp.c common/strhelp.h packaging/desktopshellrun.cpp |
diffstat | 3 files changed, 39 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/common/strhelp.c Thu Sep 18 15:43:22 2014 +0200 +++ b/common/strhelp.c Thu Sep 18 15:43:48 2014 +0200 @@ -281,4 +281,29 @@ result[n] = 0; return result; } + +wchar_t +*acp_to_wchar (const char *string, size_t len) +{ + int n, ilen; + wchar_t *result; + + ilen = (int) len; + if (ilen < 0) + return NULL; + + n = MultiByteToWideChar (CP_ACP, 0, string, ilen, NULL, 0); + if (n < 0 || n + 1 < 0) + return NULL; + + result = xmalloc ((size_t)(n+1) * sizeof *result); + n = MultiByteToWideChar (CP_ACP, 0, string, ilen, result, n); + if (n < 0) + { + xfree (result); + return NULL; + } + result[n] = 0; + return result; +} #endif
--- a/common/strhelp.h Thu Sep 18 15:43:22 2014 +0200 +++ b/common/strhelp.h Thu Sep 18 15:43:48 2014 +0200 @@ -132,6 +132,16 @@ **/ wchar_t *utf8_to_wchar (const char *string, size_t len); +/** @brief convert a local 8 bit (acp) string to utf16 wchar + * + * @param[in] string acp string. Must be at least len characters long. + * @param[in] len number of characters to be converted. + * + * @returns pointer to a newly allocated wchar array. NULL on error. + * + **/ +wchar_t *acp_to_wchar (const char *string, size_t len); + /** @brief convert a utf16 string to utf8 * * @param[in] string utf16 string. Must be at least len characters long.
--- a/packaging/desktopshellrun.cpp Thu Sep 18 15:43:22 2014 +0200 +++ b/packaging/desktopshellrun.cpp Thu Sep 18 15:43:48 2014 +0200 @@ -273,7 +273,9 @@ goto done; } - wbuf = utf8_to_wchar((*stacktop)->text, strlen((*stacktop)->text)); + /* For unicodensis this has to be utf8 to wchar */ + + wbuf = acp_to_wchar((*stacktop)->text, strlen((*stacktop)->text)); if (!wbuf) { ERRORPRINTF ("Failed to convert argument to wchar. error = 0x%lx.", hr); @@ -282,7 +284,7 @@ if ((*stacktop)->next && (*stacktop)->next->text) { - params = utf8_to_wchar((*stacktop)->next->text, strlen((*stacktop)->next->text)); + params = acp_to_wchar((*stacktop)->next->text, strlen((*stacktop)->next->text)); } if (!shellexecute(shellDispatch, wbuf, params))