diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-10-05 20:54:59 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-10-05 20:54:59 (GMT) |
commit | 4c7dfbd2035566869dc42c11a0650a49908896c5 (patch) | |
tree | f1c8da853b66ad681fa1598f07b0b565259648ab /win/tclWin32Dll.c | |
parent | 37ebaa2f324dfb5cb3e9813d6d2bc5916e823643 (diff) | |
download | tcl-4c7dfbd2035566869dc42c11a0650a49908896c5.zip tcl-4c7dfbd2035566869dc42c11a0650a49908896c5.tar.gz tcl-4c7dfbd2035566869dc42c11a0650a49908896c5.tar.bz2 |
Better implementations of Tcl_WinTCharToUtf() and Tcl_WinUtfToTChar(). They don't make any assumption on whether encodings are initialized, or specific win32 handling of special characters.
Diffstat (limited to 'win/tclWin32Dll.c')
-rw-r--r-- | win/tclWin32Dll.c | 53 |
1 files changed, 4 insertions, 49 deletions
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index a85dd0c..ca1c856 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -33,10 +33,6 @@ static int platformId; /* Running under NT, or 95/98? */ #define cpuid __asm __emit 0fh __asm __emit 0a2h #endif -#if TCL_UTF_MAX < 4 -static Tcl_Encoding winTCharEncoding = NULL; -#endif - /* * The following declaration is for the VC++ DLL entry point. */ @@ -201,8 +197,6 @@ TclWinInit( if (platformId == VER_PLATFORM_WIN32_WINDOWS) { Tcl_Panic("Windows 9x is not a supported platform"); } - - TclWinResetInterfaces(); } /* @@ -282,10 +276,6 @@ TclWinNoBackslash( void TclpSetInterfaces(void) { -#if TCL_UTF_MAX < 4 - TclWinResetInterfaces(); - winTCharEncoding = Tcl_GetEncoding(NULL, "unicode"); -#endif } /* @@ -313,8 +303,6 @@ TclWinEncodingsCleanup(void) { MountPointMap *dlIter, *dlIter2; - TclWinResetInterfaces(); - /* * Clean up the mount point map. */ @@ -348,12 +336,6 @@ TclWinEncodingsCleanup(void) void TclWinResetInterfaces(void) { -#if TCL_UTF_MAX < 4 - if (winTCharEncoding != NULL) { - Tcl_FreeEncoding(winTCharEncoding); - winTCharEncoding = NULL; - } -#endif } /* @@ -565,22 +547,8 @@ Tcl_WinUtfToTChar( Tcl_DString *dsPtr) /* Uninitialized or free DString in which the * converted string is stored. */ { -#if TCL_UTF_MAX > 3 - TCHAR *wp; - int size = MultiByteToWideChar(CP_UTF8, 0, string, len, 0, 0); - Tcl_DStringInit(dsPtr); - Tcl_DStringSetLength(dsPtr, 2*size+2); - 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 */ - Tcl_DStringSetLength(dsPtr, 2*size); - wp[size] = 0; - return wp; -#else - return (TCHAR *) Tcl_UtfToExternalDString(winTCharEncoding, - string, len, dsPtr); -#endif + return Tcl_UtfToUniCharDString(string, len, dsPtr); } char * @@ -591,26 +559,13 @@ Tcl_WinTCharToUtf( Tcl_DString *dsPtr) /* Uninitialized or free DString in which the * converted string is stored. */ { -#if TCL_UTF_MAX > 3 - char *p; - int size; - 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+1); - 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 */ - Tcl_DStringSetLength(dsPtr, size); - p[size] = 0; - return p; -#else - return Tcl_ExternalToUtfDString(winTCharEncoding, - (const char *) string, len, dsPtr); -#endif + return Tcl_UniCharToUtfDString(string, len, dsPtr); } /* |