diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-07-11 07:18:07 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-07-11 07:18:07 (GMT) |
commit | c5ced4ccd624f5ba4d19277b7d2394b4e9c41f88 (patch) | |
tree | 7e49ddd6d6f020baa55baa85dfe175b836785f4a /generic | |
parent | a0676d22d0b93bc7c895eabce277cafd42d2a4de (diff) | |
download | tcl-c5ced4ccd624f5ba4d19277b7d2394b4e9c41f88.zip tcl-c5ced4ccd624f5ba4d19277b7d2394b4e9c41f88.tar.gz tcl-c5ced4ccd624f5ba4d19277b7d2394b4e9c41f88.tar.bz2 |
Rename UTF-related functions to "WChar" and "Char16" variants, more intuitive because they represent wchar_t and char16_t (since C++11) types in modern compilers.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tcl.decls | 12 | ||||
-rw-r--r-- | generic/tcl.h | 4 | ||||
-rw-r--r-- | generic/tclDecls.h | 54 | ||||
-rw-r--r-- | generic/tclIOSock.c | 2 | ||||
-rw-r--r-- | generic/tclInt.h | 2 | ||||
-rw-r--r-- | generic/tclMain.c | 2 | ||||
-rw-r--r-- | generic/tclPlatDecls.h | 10 | ||||
-rw-r--r-- | generic/tclStubInit.c | 10 | ||||
-rw-r--r-- | generic/tclUtf.c | 39 | ||||
-rw-r--r-- | generic/tclZipfs.c | 2 |
10 files changed, 76 insertions, 61 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls index 4fa2040..26a58dc 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -1198,7 +1198,7 @@ declare 335 { int Tcl_UtfToTitle(char *src) } declare 336 { - int Tcl_UtfToWChar(const char *src, unsigned short *chPtr) + int Tcl_UtfToChar16(const char *src, unsigned short *chPtr) } declare 337 { int Tcl_UtfToUpper(char *src) @@ -1253,11 +1253,11 @@ declare 353 { unsigned long numChars) } declare 354 { - char *Tcl_WCharToUtfDString(const unsigned short *uniStr, + char *Tcl_Char16ToUtfDString(const unsigned short *uniStr, int uniLength, Tcl_DString *dsPtr) } declare 355 { - unsigned short *Tcl_UtfToWCharDString(const char *src, + unsigned short *Tcl_UtfToChar16DString(const char *src, int length, Tcl_DString *dsPtr) } declare 356 { @@ -2392,14 +2392,14 @@ declare 645 { # TIP #548 declare 646 { - int Tcl_UtfToUniChar(const char *src, unsigned int *chPtr) + int Tcl_UtfToUniChar(const char *src, int *chPtr) } declare 647 { - char *Tcl_UniCharToUtfDString(const unsigned int *uniStr, + char *Tcl_UniCharToUtfDString(const int *uniStr, int uniLength, Tcl_DString *dsPtr) } declare 648 { - unsigned int *Tcl_UtfToUniCharDString(const char *src, + int *Tcl_UtfToUniCharDString(const char *src, int length, Tcl_DString *dsPtr) } diff --git a/generic/tcl.h b/generic/tcl.h index cd194d1..8828b79 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2154,7 +2154,7 @@ typedef struct Tcl_EncodingType { #if TCL_UTF_MAX > 4 /* - * unsigned int isn't 100% accurate as it should be a strict 4-byte value + * int isn't 100% accurate as it should be a strict 4-byte value * (perhaps wchar_t). 64-bit systems may have troubles. The size of this * value must be reflected correctly in regcustom.h and * in tclEncoding.c. @@ -2162,7 +2162,7 @@ typedef struct Tcl_EncodingType { * XXX: string rep that Tcl_UniChar represents. Changing the size * XXX: of Tcl_UniChar is /not/ supported. */ -typedef unsigned int Tcl_UniChar; +typedef int Tcl_UniChar; #else typedef unsigned short Tcl_UniChar; #endif diff --git a/generic/tclDecls.h b/generic/tclDecls.h index 9f8add6..3d8f959 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -1027,7 +1027,7 @@ EXTERN int Tcl_UtfToLower(char *src); /* 335 */ EXTERN int Tcl_UtfToTitle(char *src); /* 336 */ -EXTERN int Tcl_UtfToWChar(const char *src, +EXTERN int Tcl_UtfToChar16(const char *src, unsigned short *chPtr); /* 337 */ EXTERN int Tcl_UtfToUpper(char *src); @@ -1069,10 +1069,10 @@ EXTERN int Tcl_UniCharNcmp(const Tcl_UniChar *ucs, const Tcl_UniChar *uct, unsigned long numChars); /* 354 */ -EXTERN char * Tcl_WCharToUtfDString(const unsigned short *uniStr, +EXTERN char * Tcl_Char16ToUtfDString(const unsigned short *uniStr, int uniLength, Tcl_DString *dsPtr); /* 355 */ -EXTERN unsigned short * Tcl_UtfToWCharDString(const char *src, int length, +EXTERN unsigned short * Tcl_UtfToChar16DString(const char *src, int length, Tcl_DString *dsPtr); /* 356 */ EXTERN Tcl_RegExp Tcl_GetRegExpFromObj(Tcl_Interp *interp, @@ -1906,13 +1906,12 @@ EXTERN int Tcl_LinkArray(Tcl_Interp *interp, EXTERN int Tcl_GetIntForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr, int endValue, int *indexPtr); /* 646 */ -EXTERN int Tcl_UtfToUniChar(const char *src, - unsigned int *chPtr); +EXTERN int Tcl_UtfToUniChar(const char *src, int *chPtr); /* 647 */ -EXTERN char * Tcl_UniCharToUtfDString(const unsigned int *uniStr, +EXTERN char * Tcl_UniCharToUtfDString(const int *uniStr, int uniLength, Tcl_DString *dsPtr); /* 648 */ -EXTERN unsigned int * Tcl_UtfToUniCharDString(const char *src, int length, +EXTERN int * Tcl_UtfToUniCharDString(const char *src, int length, Tcl_DString *dsPtr); typedef struct { @@ -2285,7 +2284,7 @@ typedef struct TclStubs { char * (*tcl_UtfToExternalDString) (Tcl_Encoding encoding, const char *src, int srcLen, Tcl_DString *dsPtr); /* 333 */ int (*tcl_UtfToLower) (char *src); /* 334 */ int (*tcl_UtfToTitle) (char *src); /* 335 */ - int (*tcl_UtfToWChar) (const char *src, unsigned short *chPtr); /* 336 */ + int (*tcl_UtfToChar16) (const char *src, unsigned short *chPtr); /* 336 */ int (*tcl_UtfToUpper) (char *src); /* 337 */ int (*tcl_WriteChars) (Tcl_Channel chan, const char *src, int srcLen); /* 338 */ int (*tcl_WriteObj) (Tcl_Channel chan, Tcl_Obj *objPtr); /* 339 */ @@ -2303,8 +2302,8 @@ typedef struct TclStubs { int (*tcl_UniCharIsWordChar) (int ch); /* 351 */ int (*tcl_UniCharLen) (const Tcl_UniChar *uniStr); /* 352 */ int (*tcl_UniCharNcmp) (const Tcl_UniChar *ucs, const Tcl_UniChar *uct, unsigned long numChars); /* 353 */ - char * (*tcl_WCharToUtfDString) (const unsigned short *uniStr, int uniLength, Tcl_DString *dsPtr); /* 354 */ - unsigned short * (*tcl_UtfToWCharDString) (const char *src, int length, Tcl_DString *dsPtr); /* 355 */ + char * (*tcl_Char16ToUtfDString) (const unsigned short *uniStr, int uniLength, Tcl_DString *dsPtr); /* 354 */ + unsigned short * (*tcl_UtfToChar16DString) (const char *src, int length, Tcl_DString *dsPtr); /* 355 */ Tcl_RegExp (*tcl_GetRegExpFromObj) (Tcl_Interp *interp, Tcl_Obj *patObj, int flags); /* 356 */ TCL_DEPRECATED_API("Use Tcl_EvalTokensStandard") Tcl_Obj * (*tcl_EvalTokens) (Tcl_Interp *interp, Tcl_Token *tokenPtr, int count); /* 357 */ void (*tcl_FreeParse) (Tcl_Parse *parsePtr); /* 358 */ @@ -2595,9 +2594,9 @@ typedef struct TclStubs { int (*tcl_IsShared) (Tcl_Obj *objPtr); /* 643 */ int (*tcl_LinkArray) (Tcl_Interp *interp, const char *varName, void *addr, int type, int size); /* 644 */ int (*tcl_GetIntForIndex) (Tcl_Interp *interp, Tcl_Obj *objPtr, int endValue, int *indexPtr); /* 645 */ - int (*tcl_UtfToUniChar) (const char *src, unsigned int *chPtr); /* 646 */ - char * (*tcl_UniCharToUtfDString) (const unsigned int *uniStr, int uniLength, Tcl_DString *dsPtr); /* 647 */ - unsigned int * (*tcl_UtfToUniCharDString) (const char *src, int length, Tcl_DString *dsPtr); /* 648 */ + int (*tcl_UtfToUniChar) (const char *src, int *chPtr); /* 646 */ + char * (*tcl_UniCharToUtfDString) (const int *uniStr, int uniLength, Tcl_DString *dsPtr); /* 647 */ + int * (*tcl_UtfToUniCharDString) (const char *src, int length, Tcl_DString *dsPtr); /* 648 */ } TclStubs; extern const TclStubs *tclStubsPtr; @@ -3300,8 +3299,8 @@ extern const TclStubs *tclStubsPtr; (tclStubsPtr->tcl_UtfToLower) /* 334 */ #define Tcl_UtfToTitle \ (tclStubsPtr->tcl_UtfToTitle) /* 335 */ -#define Tcl_UtfToWChar \ - (tclStubsPtr->tcl_UtfToWChar) /* 336 */ +#define Tcl_UtfToChar16 \ + (tclStubsPtr->tcl_UtfToChar16) /* 336 */ #define Tcl_UtfToUpper \ (tclStubsPtr->tcl_UtfToUpper) /* 337 */ #define Tcl_WriteChars \ @@ -3336,10 +3335,10 @@ extern const TclStubs *tclStubsPtr; (tclStubsPtr->tcl_UniCharLen) /* 352 */ #define Tcl_UniCharNcmp \ (tclStubsPtr->tcl_UniCharNcmp) /* 353 */ -#define Tcl_WCharToUtfDString \ - (tclStubsPtr->tcl_WCharToUtfDString) /* 354 */ -#define Tcl_UtfToWCharDString \ - (tclStubsPtr->tcl_UtfToWCharDString) /* 355 */ +#define Tcl_Char16ToUtfDString \ + (tclStubsPtr->tcl_Char16ToUtfDString) /* 354 */ +#define Tcl_UtfToChar16DString \ + (tclStubsPtr->tcl_UtfToChar16DString) /* 355 */ #define Tcl_GetRegExpFromObj \ (tclStubsPtr->tcl_GetRegExpFromObj) /* 356 */ #define Tcl_EvalTokens \ @@ -4113,11 +4112,20 @@ extern const TclStubs *tclStubsPtr; #if TCL_UTF_MAX <= 4 # undef Tcl_UniCharToUtfDString -# define Tcl_UniCharToUtfDString Tcl_WCharToUtfDString +# define Tcl_UniCharToUtfDString Tcl_Char16ToUtfDString # undef Tcl_UtfToUniCharDString -# define Tcl_UtfToUniCharDString Tcl_UtfToWCharDString -# undef Tcl_UtfToUniChar -# define Tcl_UtfToUniChar Tcl_UtfToWChar +# define Tcl_UtfToUniCharDString Tcl_UtfToChar16DString +# undef Tcl_UtfToUniChar +# define Tcl_UtfToUniChar Tcl_UtfToChar16 +#endif +#if defined(USE_TCL_STUBS) +# define Tcl_WCharToUtfDString (sizeof(wchar_t) != sizeof(short) ? tclStubsPtr->tcl_UniCharToUtfDString : Tcl_Char16ToUtfDString) +# define Tcl_UtfToWCharDString (sizeof(wchar_t) != sizeof(short) ? tclStubsPtr->tcl_UtfToUniCharDString : Tcl_UtfToChar16DString) +# define Tcl_UtfToWChar (sizeof(wchar_t) != sizeof(short) ? tclStubsPtr->tcl_UtfToChar16 : Tcl_UtfToUniChar) +#else +# define Tcl_WCharToUtfDString (sizeof(wchar_t) != sizeof(short) ? Tcl_UniCharToUtfDString : Tcl_Char16ToUtfDString) +# define Tcl_UtfToWCharDString (sizeof(wchar_t) != sizeof(short) ? Tcl_UtfToUniCharDString : Tcl_UtfToChar16DString) +# define Tcl_UtfToWChar (sizeof(wchar_t) != sizeof(short) ? Tcl_UtfToChar16 : Tcl_UtfToUniChar) #endif /* diff --git a/generic/tclIOSock.c b/generic/tclIOSock.c index adf729a..e9f9066 100644 --- a/generic/tclIOSock.c +++ b/generic/tclIOSock.c @@ -35,7 +35,7 @@ gai_strerror( Tcl_DStringInit(&tsdPtr->errorMsg); tsdPtr->initialized = 1; } - Tcl_WCharToUtfDString(gai_strerrorW(code), -1, &tsdPtr->errorMsg); + Tcl_Char16ToUtfDString(gai_strerrorW(code), -1, &tsdPtr->errorMsg); return Tcl_DStringValue(&tsdPtr->errorMsg); } #endif diff --git a/generic/tclInt.h b/generic/tclInt.h index 5fc3b37..3dcfc13 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -4629,7 +4629,7 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file, #define TclUtfToUniChar(str, chPtr) \ ((((unsigned char) *(str)) < 0x80) ? \ ((*(chPtr) = (unsigned char) *(str)), 1) \ - : Tcl_UtfToWChar(str, chPtr)) + : Tcl_UtfToChar16(str, chPtr)) #endif /* diff --git a/generic/tclMain.c b/generic/tclMain.c index 4a66793..f789370 100644 --- a/generic/tclMain.c +++ b/generic/tclMain.c @@ -71,7 +71,7 @@ NewNativeObj( #ifdef UNICODE Tcl_DStringInit(&ds); - Tcl_WCharToUtfDString(string, length, &ds); + Tcl_Char16ToUtfDString(string, length, &ds); #else Tcl_ExternalToUtfDString(NULL, (char *) string, length, &ds); #endif diff --git a/generic/tclPlatDecls.h b/generic/tclPlatDecls.h index 42478ac..354d752 100644 --- a/generic/tclPlatDecls.h +++ b/generic/tclPlatDecls.h @@ -122,12 +122,10 @@ extern const TclPlatStubs *tclPlatStubsPtr; #undef Tcl_WinUtfToTChar #undef Tcl_WinTCharToUtf #ifdef _WIN32 -#define Tcl_WinUtfToTChar(string, len, dsPtr) ((Tcl_DStringInit(dsPtr), (string) != NULL) \ - ? (TCHAR *)Tcl_UtfToWCharDString((string), (len), (dsPtr)) \ - : ((void)(len), NULL)) -#define Tcl_WinTCharToUtf(string, len, dsPtr) ((Tcl_DStringInit(dsPtr), (string) != NULL) \ - ? (char *)Tcl_WCharToUtfDString((string), ((int)(len) >> 1), (dsPtr)) \ - : ((void)(len), NULL)) +#define Tcl_WinUtfToTChar(string, len, dsPtr) (Tcl_DStringInit(dsPtr), \ + (TCHAR *)Tcl_UtfToChar16DString((string), (len), (dsPtr))) +#define Tcl_WinTCharToUtf(string, len, dsPtr) (Tcl_DStringInit(dsPtr), \ + (char *)Tcl_Char16ToUtfDString((string), ((((len) + 2) >> 1) - 1), (dsPtr))) #endif #endif diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 8da0123..299a352 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -260,7 +260,7 @@ Tcl_WinUtfToTChar( if (!string) { return NULL; } - return (char *)Tcl_UtfToWCharDString(string, len, dsPtr); + return (char *)Tcl_UtfToChar16DString(string, len, dsPtr); } #undef Tcl_WinTCharToUtf char * @@ -273,7 +273,7 @@ Tcl_WinTCharToUtf( if (!string) { return NULL; } - return Tcl_WCharToUtfDString((const unsigned short *)string, len >> 1, dsPtr); + return Tcl_Char16ToUtfDString((const unsigned short *)string, len >> 1, dsPtr); } #endif /* !defined(TCL_NO_DEPRECATED) */ @@ -1338,7 +1338,7 @@ const TclStubs tclStubs = { Tcl_UtfToExternalDString, /* 333 */ Tcl_UtfToLower, /* 334 */ Tcl_UtfToTitle, /* 335 */ - Tcl_UtfToWChar, /* 336 */ + Tcl_UtfToChar16, /* 336 */ Tcl_UtfToUpper, /* 337 */ Tcl_WriteChars, /* 338 */ Tcl_WriteObj, /* 339 */ @@ -1356,8 +1356,8 @@ const TclStubs tclStubs = { Tcl_UniCharIsWordChar, /* 351 */ Tcl_UniCharLen, /* 352 */ Tcl_UniCharNcmp, /* 353 */ - Tcl_WCharToUtfDString, /* 354 */ - Tcl_UtfToWCharDString, /* 355 */ + Tcl_Char16ToUtfDString, /* 354 */ + Tcl_UtfToChar16DString, /* 355 */ Tcl_GetRegExpFromObj, /* 356 */ Tcl_EvalTokens, /* 357 */ Tcl_FreeParse, /* 358 */ diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 962a3e2..904da95 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -224,12 +224,12 @@ three: #undef Tcl_UniCharToUtfDString char * Tcl_UniCharToUtfDString( - const unsigned int *uniStr, /* Unicode string to convert to UTF-8. */ + const int *uniStr, /* Unicode string to convert to UTF-8. */ int uniLength, /* Length of Unicode string. */ Tcl_DString *dsPtr) /* UTF-8 representation of string is appended * to this previously initialized DString. */ { - const unsigned int *w, *wEnd; + const int *w, *wEnd; char *p, *string; int oldLength; @@ -237,6 +237,9 @@ Tcl_UniCharToUtfDString( * UTF-8 string length in bytes will be <= Unicode string length * 4. */ + if (uniStr == NULL) { + return NULL; + } if (uniLength < 0) { uniLength = 0; w = uniStr; @@ -260,9 +263,8 @@ Tcl_UniCharToUtfDString( return string; } -#undef Tcl_WCharToUtfDString char * -Tcl_WCharToUtfDString( +Tcl_Char16ToUtfDString( const unsigned short *uniStr, /* Utf-16 string to convert to UTF-8. */ int uniLength, /* Length of Utf-16 string. */ Tcl_DString *dsPtr) /* UTF-8 representation of string is appended @@ -276,6 +278,9 @@ Tcl_WCharToUtfDString( * UTF-8 string length in bytes will be <= Utf16 string length * 3. */ + if (uniStr == NULL) { + return NULL; + } if (uniLength < 0) { uniLength = 0; @@ -357,10 +362,10 @@ static const unsigned short cp1252[32] = { int Tcl_UtfToUniChar( register const char *src, /* The UTF-8 string. */ - register unsigned int *chPtr)/* Filled with the unsigned int represented by + register int *chPtr)/* Filled with the unsigned int represented by * the UTF-8 string. */ { - unsigned int byte; + int byte; /* * Unroll 1 to 4 byte UTF-8 sequences. @@ -438,9 +443,8 @@ Tcl_UtfToUniChar( return 1; } -#undef Tcl_UtfToWChar int -Tcl_UtfToWChar( +Tcl_UtfToChar16( const char *src, /* The UTF-8 string. */ unsigned short *chPtr)/* Filled with the unsigned short represented by * the UTF-8 string. */ @@ -558,7 +562,7 @@ Tcl_UtfToWChar( */ #undef Tcl_UtfToUniCharDString -unsigned int * +int * Tcl_UtfToUniCharDString( const char *src, /* UTF-8 string to convert to Unicode. */ int length, /* Length of UTF-8 string in bytes, or -1 for @@ -567,10 +571,13 @@ Tcl_UtfToUniCharDString( * appended to this previously initialized * DString. */ { - unsigned int ch = 0, *w, *wString; + int ch = 0, *w, *wString; const char *p, *end; int oldLength; + if (src == NULL) { + return NULL; + } if (length < 0) { length = strlen(src); } @@ -584,7 +591,7 @@ Tcl_UtfToUniCharDString( Tcl_DStringSetLength(dsPtr, oldLength + ((length + 1) * sizeof(unsigned int))); - wString = (unsigned int *) (Tcl_DStringValue(dsPtr) + oldLength); + wString = (int *) (Tcl_DStringValue(dsPtr) + oldLength); w = wString; p = src; @@ -609,9 +616,8 @@ Tcl_UtfToUniCharDString( return wString; } -#undef Tcl_UtfToWCharDString unsigned short * -Tcl_UtfToWCharDString( +Tcl_UtfToChar16DString( const char *src, /* UTF-8 string to convert to Unicode. */ int length, /* Length of UTF-8 string in bytes, or -1 for * strlen(). */ @@ -624,6 +630,9 @@ Tcl_UtfToWCharDString( const char *p, *end; int oldLength; + if (src == NULL) { + return NULL; + } if (length < 0) { length = strlen(src); } @@ -643,13 +652,13 @@ Tcl_UtfToWCharDString( p = src; end = src + length - 4; while (p < end) { - p += Tcl_UtfToWChar(p, &ch); + p += Tcl_UtfToChar16(p, &ch); *w++ = ch; } end += 4; while (p < end) { if (Tcl_UtfCharComplete(p, end-p)) { - p += Tcl_UtfToWChar(p, &ch); + p += Tcl_UtfToChar16(p, &ch); } else { ch = UCHAR(*p++); } diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 0dca6f1..3cb271b 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -4930,7 +4930,7 @@ TclZipfs_AppHook( Tcl_DString ds; Tcl_DStringInit(&ds); - archive = Tcl_WCharToUtfDString((*argvPtr)[1], -1, &ds); + archive = Tcl_Char16ToUtfDString((*argvPtr)[1], -1, &ds); #else /* !_WIN32 */ archive = (*argvPtr)[1]; #endif /* _WIN32 */ |