summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-11-13 12:36:34 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-11-13 12:36:34 (GMT)
commitf60bcc7e1e3aa3950d481d08d057361da75ee3cf (patch)
treee2413eb6ee919aee9d3ad9db39107c717a11e19c /generic/tclEncoding.c
parent6e5c5c71b7d5c65534f127236932dfbaf58493d4 (diff)
downloadtcl-f60bcc7e1e3aa3950d481d08d057361da75ee3cf.zip
tcl-f60bcc7e1e3aa3950d481d08d057361da75ee3cf.tar.gz
tcl-f60bcc7e1e3aa3950d481d08d057361da75ee3cf.tar.bz2
Simplify TIP #656: "A revised proposal for encodings". Make TCL_ENCODING_PROFILE_??? values the same as in Tcl 9.0 after TIP #657: Make "-profile strict" the default in Tcl 9.0
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c67
1 files changed, 3 insertions, 64 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index e461db2..262dd01 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -192,7 +192,7 @@ Tcl_Encoding tclUtf8Encoding = NULL;
* Names of encoding profiles and corresponding integer values.
* Keep alphabetical order for error messages.
*/
-static struct TclEncodingProfiles {
+static const struct TclEncodingProfiles {
const char *name;
int value;
} encodingProfiles[] = {
@@ -201,10 +201,10 @@ static struct TclEncodingProfiles {
{"tcl8", TCL_ENCODING_PROFILE_TCL8},
};
#define PROFILE_STRICT(flags_) \
- (ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT)
+ ((flags_) & TCL_ENCODING_PROFILE_STRICT)
#define PROFILE_REPLACE(flags_) \
- (ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE)
+ ((ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) && !PROFILE_STRICT(flags_))
#define UNICODE_REPLACE_CHAR ((Tcl_UniChar)0xFFFD)
#define SURROGATE(c_) (((c_) & ~0x7FF) == 0xD800)
@@ -1229,10 +1229,6 @@ Tcl_ExternalToUtfDString(
* Possible flags values:
* target encoding. It should be composed by OR-ing the following:
* - *At most one* of TCL_ENCODING_PROFILE{DEFAULT,TCL8,STRICT}
- * - TCL_ENCODING_STOPONERROR: Backward compatibility. Sets the profile
- * to TCL_ENCODING_PROFILE_STRICT overriding any specified profile flags
- * Any other flag bits will cause an error to be returned (for future
- * compatibility)
*
* Results:
* The return value is one of
@@ -1535,8 +1531,6 @@ Tcl_UtfToExternalDString(
* the source buffer are invalid or cannot be represented in the
* target encoding. It should be composed by OR-ing the following:
* - *At most one* of TCL_ENCODING_PROFILE_*
- * - TCL_ENCODING_STOPONERROR: Backward compatibility. Sets the profile
- * to TCL_ENCODING_PROFILE_STRICT overriding any specified profile flags
*
* Results:
* The return value is one of
@@ -2459,7 +2453,6 @@ BinaryProc(
if (dstLen < 0) {
dstLen = 0;
}
- flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_CHAR_LIMIT) && srcLen > *dstCharsPtr) {
srcLen = *dstCharsPtr;
}
@@ -2527,7 +2520,6 @@ UtfToUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
- flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= 6;
}
@@ -2743,7 +2735,6 @@ Utf32ToUtfProc(
int result, numChars, charLimit = INT_MAX;
int ch = 0, bytesLeft = srcLen % 4;
- flags = TclEncodingSetProfileFlags(flags);
flags |= PTR2INT(clientData);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
@@ -2900,7 +2891,6 @@ UtfToUtf32Proc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
- flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -2998,7 +2988,6 @@ Utf16ToUtfProc(
int result, numChars, charLimit = INT_MAX;
unsigned short ch = 0;
- flags = TclEncodingSetProfileFlags(flags);
flags |= PTR2INT(clientData);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
@@ -3159,7 +3148,6 @@ UtfToUtf16Proc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
- flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -3265,7 +3253,6 @@ UtfToUcs2Proc(
int result, numChars, len;
Tcl_UniChar ch = 0;
- flags = TclEncodingSetProfileFlags(flags);
flags |= PTR2INT(clientData);
srcStart = src;
srcEnd = src + srcLen;
@@ -3375,7 +3362,6 @@ TableToUtfProc(
const unsigned short *pageZero;
TableEncodingData *dataPtr = (TableEncodingData *)clientData;
- flags = TclEncodingSetProfileFlags(flags);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
}
@@ -3508,7 +3494,6 @@ TableFromUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
- flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -3609,7 +3594,6 @@ Iso88591ToUtfProc(
const char *dstEnd, *dstStart;
int result, numChars, charLimit = INT_MAX;
- flags = TclEncodingSetProfileFlags(flags);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
}
@@ -3694,7 +3678,6 @@ Iso88591FromUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
- flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -3834,7 +3817,6 @@ EscapeToUtfProc(
int state, result, numChars, charLimit = INT_MAX;
const char *dstStart, *dstEnd;
- flags = TclEncodingSetProfileFlags(flags);
if (flags & TCL_ENCODING_CHAR_LIMIT) {
charLimit = *dstCharsPtr;
}
@@ -4056,7 +4038,6 @@ EscapeFromUtfProc(
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
- flags = TclEncodingSetProfileFlags(flags);
if ((flags & TCL_ENCODING_END) == 0) {
srcClose -= TCL_UTF_MAX;
}
@@ -4505,48 +4486,6 @@ TclEncodingProfileIdToName(
/*
*------------------------------------------------------------------------
*
- * TclEncodingSetProfileFlags --
- *
- * Maps the flags supported in the encoding C API's to internal flags.
- *
- * For backward compatibility reasons, TCL_ENCODING_STOPONERROR is
- * is mapped to the TCL_ENCODING_PROFILE_STRICT overwriting any profile
- * specified.
- *
- * If no profile or an invalid profile is specified, it is set to
- * the default.
- *
- * Results:
- * Internal encoding flag mask.
- *
- * Side effects:
- * None.
- *
- *------------------------------------------------------------------------
- */
-int TclEncodingSetProfileFlags(int flags)
-{
- if (flags & TCL_ENCODING_STOPONERROR) {
- ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_STRICT);
- } else {
- int profile = ENCODING_PROFILE_GET(flags);
- switch (profile) {
- case TCL_ENCODING_PROFILE_TCL8:
- case TCL_ENCODING_PROFILE_STRICT:
- case TCL_ENCODING_PROFILE_REPLACE:
- break;
- case 0: /* Unspecified by caller */
- default:
- ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_TCL8);
- break;
- }
- }
- return flags;
-}
-
-/*
- *------------------------------------------------------------------------
- *
* TclGetEncodingProfiles --
*
* Get the list of supported encoding profiles.