summaryrefslogtreecommitdiffstats
path: root/generic/tclStringObj.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-08-21 21:43:16 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-08-21 21:43:16 (GMT)
commitc42f34e33320fc95bf80bdca0da2bae7bebbbe0f (patch)
treee045a34d312e2e08725507f0d2e43c6d65bc400a /generic/tclStringObj.c
parent64a63fa7c5594097d782968787ad37e46f9e4f5e (diff)
parent916d72ec1ce61ebd585a78c6a9565f5c49bb8d24 (diff)
downloadtcl-c42f34e33320fc95bf80bdca0da2bae7bebbbe0f.zip
tcl-c42f34e33320fc95bf80bdca0da2bae7bebbbe0f.tar.gz
tcl-c42f34e33320fc95bf80bdca0da2bae7bebbbe0f.tar.bz2
Merge 8.7
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r--generic/tclStringObj.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 86b3937..7ce1cdc 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -68,6 +68,9 @@ static int SetStringFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static void SetUnicodeObj(Tcl_Obj *objPtr,
const Tcl_UniChar *unicode, int numChars);
static int UnicodeLength(const Tcl_UniChar *unicode);
+#if !defined(TCL_NO_DEPRECATED)
+static int UTF16Length(const unsigned short *unicode);
+#endif
static void UpdateStringOfString(Tcl_Obj *objPtr);
#if (TCL_UTF_MAX) > 3 && !defined(TCL_NO_DEPRECATED)
static void DupUTF16StringInternalRep(Tcl_Obj *objPtr,
@@ -562,6 +565,10 @@ Tcl_NewUnicodeObj(
TclNewObj(objPtr);
TclInvalidateStringRep(objPtr);
+ if (numChars < 0) {
+ numChars = UTF16Length(unicode);
+ }
+
String *stringPtr = (String *)ckalloc((offsetof(String, unicode)
+ sizeof(unsigned short)) + numChars * sizeof(unsigned short));
memcpy(stringPtr->unicode, unicode, numChars * sizeof(unsigned short));
@@ -974,6 +981,7 @@ Tcl_GetUnicodeFromObj(
}
#endif
+#if !defined(TCL_NO_DEPRECATED)
unsigned short *
TclGetUnicodeFromObj(
Tcl_Obj *objPtr, /* The object to find the unicode string
@@ -984,7 +992,11 @@ TclGetUnicodeFromObj(
{
String *stringPtr;
+#if TCL_UTF_MAX > 3
+ SetUTF16StringFromAny(NULL, objPtr);
+#else
SetStringFromAny(NULL, objPtr);
+#endif
stringPtr = GET_STRING(objPtr);
if (lengthPtr != NULL) {
@@ -992,6 +1004,7 @@ TclGetUnicodeFromObj(
}
return stringPtr->unicode;
}
+#endif
/*
*----------------------------------------------------------------------
@@ -1451,14 +1464,7 @@ Tcl_SetUnicodeObj(
String *stringPtr;
if (numChars < 0) {
- numChars = 0;
-
- if (unicode) {
- while (numChars >= 0 && unicode[numChars] != 0) {
- numChars++;
- }
- }
- stringCheckLimits(numChars);
+ numChars = UTF16Length(unicode);
}
/*
@@ -1479,6 +1485,21 @@ Tcl_SetUnicodeObj(
TclInvalidateStringRep(objPtr);
stringPtr->allocated = numChars;
}
+
+static int
+UTF16Length(
+ const unsigned short *ucs2Ptr)
+{
+ int numChars = 0;
+
+ if (ucs2Ptr) {
+ while (numChars >= 0 && ucs2Ptr[numChars] != 0) {
+ numChars++;
+ }
+ }
+ stringCheckLimits(numChars);
+ return numChars;
+}
#endif
static int
@@ -1723,7 +1744,7 @@ Tcl_AppendUnicodeToObj(
return;
}
- SetStringFromAny(NULL, objPtr);
+ SetUTF16StringFromAny(NULL, objPtr);
stringPtr = GET_STRING(objPtr);
stringPtr = stringAttemptRealloc(stringPtr, stringPtr->numChars + length);
memcpy(&stringPtr->unicode[stringPtr->numChars], unicode, length);