summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2018-10-05 21:22:53 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2018-10-05 21:22:53 (GMT)
commit7a674da778ae7cadb94d9d7f8ba8304878f08ce5 (patch)
treec139a1ba9e84f04b212dfbe183f606b7f2d1d05a
parent54f90bae0f0c285817c762b1ed1d1c411767df62 (diff)
parent70fb513ba373191dc686f86cbd4b087abfa08316 (diff)
downloadtcl-7a674da778ae7cadb94d9d7f8ba8304878f08ce5.zip
tcl-7a674da778ae7cadb94d9d7f8ba8304878f08ce5.tar.gz
tcl-7a674da778ae7cadb94d9d7f8ba8304878f08ce5.tar.bz2
Merge 8.7
-rw-r--r--generic/tclStubInit.c53
-rw-r--r--win/tclWin32Dll.c49
2 files changed, 12 insertions, 90 deletions
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index b13aaf5..4ddce68 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -12,6 +12,10 @@
#include "tclInt.h"
#include "tommath.h"
+#ifdef __CYGWIN__
+# include <wchar.h>
+#endif
+
#ifdef __GNUC__
#pragma GCC dependency "tcl.decls"
#pragma GCC dependency "tclInt.decls"
@@ -100,31 +104,8 @@ Tcl_WinUtfToTChar(
int len,
Tcl_DString *dsPtr)
{
- WCHAR *wp, *p;
- int size = MultiByteToWideChar(CP_UTF8, 0, string, len, 0, 0);
-
Tcl_DStringInit(dsPtr);
- Tcl_DStringSetLength(dsPtr, 2*size+2);
- p = wp = (WCHAR *)Tcl_DStringValue(dsPtr);
- MultiByteToWideChar(CP_UTF8, 0, string, len, wp, size+1);
- if (len == -1) --size; /* account for 0-byte at string end */
-
- /* It turns out that MultiByteToWideChar() cannot handle the 'modified'
- * UTF-8 as used by Tcl. Every sequence of 0xC0 followed by 0x80 will
- * be translated to two 0xfffd characters. This results in a test-failure
- * of the registry-6.20 test-case. The simplest solution is to search for
- * those two 0xfffd characters and replace them by a \u0000 character. */
- while (p < wp + size - 1) {
- if (p[0] == 0xfffd && p[1] == 0xfffd) {
- memmove(p+1, p+2, sizeof(WCHAR) * (p - wp + size - 2));
- p[0] = '\0';
- ++p; --size;
- }
- ++p;
- }
- Tcl_DStringSetLength(dsPtr, 2*size);
- wp[size] = 0;
- return (char *) wp;
+ return (char *)Tcl_UtfToUniCharDString(string, len, dsPtr);
}
char *
@@ -133,31 +114,13 @@ Tcl_WinTCharToUtf(
int len,
Tcl_DString *dsPtr)
{
- char *p;
- int size, i = 0;
-
if (len > 0) {
len /= 2;
+ } else if (len == -1) {
+ len = wcslen((wchar_t *)string);
}
- size = WideCharToMultiByte(CP_UTF8, 0, string, len, 0, 0, NULL, NULL);
Tcl_DStringInit(dsPtr);
- Tcl_DStringSetLength(dsPtr, size+8); /* Add some spare, in case of NULL-bytes */
- p = (char *)Tcl_DStringValue(dsPtr);
- WideCharToMultiByte(CP_UTF8, 0, string, len, p, size, NULL, NULL);
- if (len == -1) --size; /* account for 0-byte at string end */
- while (i < size) {
- if (!p[i]) {
- /* Output contains '\0'-byte, but Tcl expect two-bytes: C0 80 */
- memmove(p+i+2, p+i+1, size-i-1);
- memcpy(p + i++, "\xC0\x80", 2);
- Tcl_DStringSetLength(dsPtr, ++size + 1);
- p = (char *)Tcl_DStringValue(dsPtr);
- }
- ++i;
- }
- Tcl_DStringSetLength(dsPtr, size);
- p[size] = 0;
- return p;
+ return Tcl_UniCharToUtfDString((Tcl_UniChar *)string, len, dsPtr);
}
#if defined(TCL_WIDE_INT_IS_LONG)
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c
index 60edbab..1a33514 100644
--- a/win/tclWin32Dll.c
+++ b/win/tclWin32Dll.c
@@ -471,31 +471,8 @@ Tcl_WinUtfToTChar(
Tcl_DString *dsPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
- TCHAR *wp, *p;
- int size = MultiByteToWideChar(CP_UTF8, 0, string, len, 0, 0);
-
Tcl_DStringInit(dsPtr);
- Tcl_DStringSetLength(dsPtr, 2*size+2);
- p = wp = (TCHAR *)Tcl_DStringValue(dsPtr);
- MultiByteToWideChar(CP_UTF8, 0, string, len, wp, size+1);
- if (len == -1) --size; /* account for 0-byte at string end */
-
- /* It turns out that MultiByteToWideChar() cannot handle the 'modified'
- * UTF-8 as used by Tcl. Every sequence of 0xC0 followed by 0x80 will
- * be translated to two 0xfffd characters. This results in a test-failure
- * of the registry-6.20 test-case. The simplest solution is to search for
- * those two 0xfffd characters and replace them by a \u0000 character. */
- while (p < wp + size - 1) {
- if (p[0] == 0xfffd && p[1] == 0xfffd) {
- memmove(p+1, p+2, sizeof(TCHAR) * (p - wp + size - 2));
- p[0] = '\0';
- ++p; --size;
- }
- ++p;
- }
- Tcl_DStringSetLength(dsPtr, 2*size);
- wp[size] = 0;
- return wp;
+ return Tcl_UtfToUniCharDString(string, len, dsPtr);
}
char *
@@ -506,31 +483,13 @@ Tcl_WinTCharToUtf(
Tcl_DString *dsPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
- char *p;
- int size, i = 0;
-
if (len > 0) {
len /= 2;
+ } else if (len < 0) {
+ len = wcslen(string);
}
- size = WideCharToMultiByte(CP_UTF8, 0, string, len, 0, 0, NULL, NULL);
Tcl_DStringInit(dsPtr);
- Tcl_DStringSetLength(dsPtr, size+8); /* Add some spare, in case of NULL-bytes */
- p = (char *)Tcl_DStringValue(dsPtr);
- WideCharToMultiByte(CP_UTF8, 0, string, len, p, size, NULL, NULL);
- if (len == -1) --size; /* account for 0-byte at string end */
- while (i < size) {
- if (!p[i]) {
- /* Output contains '\0'-byte, but Tcl expect two-bytes: C0 80 */
- memmove(p+i+2, p+i+1, size-i-1);
- memcpy(p + i++, "\xC0\x80", 2);
- Tcl_DStringSetLength(dsPtr, ++size + 1);
- p = (char *)Tcl_DStringValue(dsPtr);
- }
- ++i;
- }
- Tcl_DStringSetLength(dsPtr, size);
- p[size] = 0;
- return p;
+ return Tcl_UniCharToUtfDString(string, len, dsPtr);
}
/*