summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhershey <hershey>1999-06-15 22:06:17 (GMT)
committerhershey <hershey>1999-06-15 22:06:17 (GMT)
commit1b1bab45a700c36f964cdbd1a79045e914e0aa96 (patch)
treefd497b035bc7c04b8ad71eadb4eef2f2f144244d
parent2008a70f51dba5c3a581c7498dd8762ad5d6d7ac (diff)
downloadtcl-1b1bab45a700c36f964cdbd1a79045e914e0aa96.zip
tcl-1b1bab45a700c36f964cdbd1a79045e914e0aa96.tar.gz
tcl-1b1bab45a700c36f964cdbd1a79045e914e0aa96.tar.bz2
beefed up the string object tests
-rw-r--r--generic/tclStringObj.c140
-rw-r--r--generic/tclTestObj.c17
-rw-r--r--tests/stringObj.test162
3 files changed, 180 insertions, 139 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 09cfc4c..e00b02a 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -1,29 +1,31 @@
/*
* tclStringObj.c --
*
- * This file contains procedures that implement string operations
- * on Tcl objects. To do this efficiently (i.e. to allow many
- * appends to be done to an object without constantly reallocating
- * the space for the string representation) we overallocate the
- * space for the string and use the internal representation to keep
- * track of the extra space. Objects with this internal
- * representation are called "expandable string objects".
- *
- * Since some string operations work with UTF strings and others require Unicode
- format, the string obeject type stores one or both formats. If the object is
- created with a Unicode string, then UTF form is not stored until it is
- required by a string operation. The string object always stores the number of
- characters, so if the object is created with a UTF string, we automatically
- convert it to unicode (as this costs little more than
-
-A Unicode string
- * is an internationalized string. Conceptually, a Unicode string is an
- * array of 16-bit quantities organized as a sequence of properly formed
- * UTF-8 characters. There is a one-to-one map between Unicode and UTF
- * characters. The Unicode ojbect is opitmized for the case where each UTF
- * char in a string is only one byte. In this case, we store the value of
- * numChars, but we don't copy the bytes to the unicodeObj->chars. Before
- * accessing obj->chars, check if unicodeObj->numChars == obj->length.
+ * This file contains procedures that implement string operations on Tcl
+ * objects. Some string operations work with UTF strings and others
+ * require Unicode format. Functions that require knowledge of the width
+ * of each character, such as indexing, operate on Unicode data.
+ *
+ * A Unicode string is an internationalized string. Conceptually, a
+ * Unicode string is an array of 16-bit quantities organized as a sequence
+ * of properly formed UTF-8 characters. There is a one-to-one map between
+ * Unicode and UTF characters. Because Unicode characters have a fixed
+ * width, operations such as indexing operate on Unicode data. The String
+ * ojbect is opitmized for the case where each UTF char in a string is
+ * only one byte. In this case, we store the value of numChars, but we
+ * don't store the Unicode data (unless Tcl_GetUnicode is explicitly
+ * called).
+ *
+ * The String object type stores one or both formats. The default
+ * behavior is to store UTF. Once Unicode is calculated by a function, it
+ * is stored in the internal rep for future access (without an additional
+ * O(n) cost).
+ *
+ * To allow many appends to be done to an object without constantly
+ * reallocating the space for the string or Unicode representation, we
+ * allocate double the space for the string or Unicode and use the
+ * internal representation to keep track of how much space is used
+ * vs. allocated.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright (c) 1999 by Scriptics Corporation.
@@ -31,8 +33,7 @@ A Unicode string
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.9 1999/06/15 03:14:44 hershey Exp $
- */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.10 1999/06/15 22:06:17 hershey Exp $ */
#include "tclInt.h"
@@ -80,7 +81,7 @@ Tcl_ObjType tclStringType = {
* shrinking of the UTF and Unicode reps of the String object with fewer
* mallocs. To optimize string length and indexing operations, this
* structure also stores the number of characters (same of UTF and Unicode!)
- * once that value has been computede.
+ * once that value has been computed.
*/
typedef struct String {
@@ -321,12 +322,6 @@ Tcl_GetCharLength(objPtr)
SetStringFromAny(NULL, objPtr);
stringPtr = GET_STRING(objPtr);
-/* if (objPtr->bytes == NULL) { */
-/* printf("called Tcl_GetCharLength with unicode str.\n"); */
-/* } else { */
-/* printf("called Tcl_GetCharLength with str = %s\n", objPtr->bytes); */
-/* } */
-
/*
* If numChars is unknown, then calculate the number of characaters
* while populating the Unicode string.
@@ -395,12 +390,6 @@ Tcl_GetUniChar(objPtr, index)
SetStringFromAny(NULL, objPtr);
stringPtr = GET_STRING(objPtr);
-/* if (objPtr->bytes == NULL) { */
-/* printf("called Tcl_GetUniChar with unicode str.\n"); */
-/* } else { */
-/* printf("called Tcl_GetUniChar with str = %s\n", objPtr->bytes); */
-/* } */
-
if (stringPtr->numChars == -1) {
/*
@@ -419,7 +408,6 @@ Tcl_GetUniChar(objPtr, index)
stringPtr = GET_STRING(objPtr);
}
if (stringPtr->uallocated == 0) {
- char *bytes;
/*
* All of the characters in the Utf string are 1 byte chars,
@@ -427,8 +415,7 @@ Tcl_GetUniChar(objPtr, index)
* and convert the index'th byte to a Unicode character.
*/
- bytes = Tcl_GetString(objPtr);
- Tcl_UtfToUniChar(&bytes[index], &unichar);
+ Tcl_UtfToUniChar(&objPtr->bytes[index], &unichar);
} else {
unichar = stringPtr->unicode[index];
}
@@ -463,12 +450,6 @@ Tcl_GetUnicode(objPtr)
SetStringFromAny(NULL, objPtr);
stringPtr = GET_STRING(objPtr);
-/* if (objPtr->bytes == NULL) { */
-/* printf("called Tcl_GetUnicode with unicode str.\n"); */
-/* } else { */
-/* printf("called Tcl_GetUnicode with str = %s\n", objPtr->bytes); */
-/* } */
-
if ((stringPtr->numChars == -1) || (stringPtr->uallocated == 0)) {
/*
@@ -557,8 +538,9 @@ Tcl_GetRange(objPtr, first, last)
* can set it's numChars field.
*/
-/* stringPtr = GET_STRING(newObjPtr); */
-/* stringPtr->numChars = last-first+1; */
+ SetStringFromAny(NULL, newObjPtr);
+ stringPtr = GET_STRING(newObjPtr);
+ stringPtr->numChars = last-first+1;
} else {
newObjPtr = Tcl_NewUnicodeObj(stringPtr->unicode + first,
last-first+1);
@@ -622,7 +604,6 @@ Tcl_SetStringObj(objPtr, bytes, length)
length = (bytes? strlen(bytes) : 0);
}
TclInitStringRep(objPtr, bytes, length);
-/* printf("called Tcl_SetStringObj with str = %s\n", objPtr->bytes); */
}
/*
@@ -684,7 +665,6 @@ Tcl_SetObjLength(objPtr, length)
if (objPtr->bytes != NULL) {
memcpy((VOID *) new, (VOID *) objPtr->bytes,
(size_t) objPtr->length);
-/* new[objPtr->length] = 0; */
Tcl_InvalidateStringRep(objPtr);
}
objPtr->bytes = new;
@@ -891,7 +871,7 @@ Tcl_AppendObjToObj(objPtr, appendObjPtr)
Tcl_Obj *appendObjPtr; /* Object to append. */
{
String *stringPtr;
- int length;
+ int length, numChars, allOneByteChars;
char *bytes;
SetStringFromAny(NULL, objPtr);
@@ -931,11 +911,28 @@ Tcl_AppendObjToObj(objPtr, appendObjPtr)
}
/*
- * Append to objPtr's UTF string rep.
+ * Append to objPtr's UTF string rep. If we know the number of
+ * characters in both objects before appending, then set the combined
+ * number of characters in the final (appended-to) object.
*/
+ allOneByteChars = 0;
+ numChars = stringPtr->numChars;
+ if ((numChars >= 0) && (appendObjPtr->typePtr == &tclStringType)) {
+ stringPtr = GET_STRING(appendObjPtr);
+ if (stringPtr->numChars >= 0) {
+ numChars += stringPtr->numChars;
+ allOneByteChars = 1;
+ }
+ }
+
bytes = Tcl_GetStringFromObj(appendObjPtr, &length);
AppendUtfToUtfRep(objPtr, bytes, length);
+
+ if (allOneByteChars) {
+ stringPtr = GET_STRING(objPtr);
+ stringPtr->numChars = numChars;
+ }
}
/*
@@ -973,7 +970,10 @@ AppendUnicodeToUnicodeRep(objPtr, unicode, appendNumChars)
stringPtr = GET_STRING(objPtr);
/*
- * Make the buffer big enough for the result.
+ * If not enough space has been allocated for the unicode rep,
+ * reallocate the internal rep object with double the amount of
+ * space needed, so the unicode string can grow without being
+ * reallocated.
*/
numChars = stringPtr->numChars + appendNumChars;
@@ -1124,14 +1124,12 @@ AppendUtfToUtfRep(objPtr, bytes, numBytes)
/*
* There isn't currently enough space in the string
- * representation so allocate additional space. If the current
- * string representation isn't empty (i.e. it looks like we're
- * doing a series of appends) then overallocate the space so
- * that we won't have to do as much reallocation in the future.
+ * representation so allocate additional space. Overallocate the
+ * space by doubling it so that we won't have to do as much
+ * reallocation in the future.
*/
- Tcl_SetObjLength(objPtr,
- (oldLength == 0) ? newLength : 2*newLength);
+ Tcl_SetObjLength(objPtr, 2*newLength);
} else {
/*
@@ -1313,13 +1311,21 @@ FillUnicodeRep(objPtr)
if (uallocated > stringPtr->uallocated) {
/*
- * If not enought space has been allocated for the unicode rep,
- * reallocate the internal rep object with double the amount of
- * space needed, so the unicode string can grow without being
- * reallocated.
+ * If not enough space has been allocated for the unicode rep,
+ * reallocate the internal rep object.
+ */
+
+ /*
+ * There isn't currently enough space in the Unicode
+ * representation so allocate additional space. If the current
+ * Unicode representation isn't empty (i.e. it looks like we've
+ * done some appends) then overallocate the space so
+ * that we won't have to do as much reallocation in the future.
*/
- uallocated *= 2;
+ if (stringPtr->uallocated > 0) {
+ uallocated *= 2;
+ }
stringPtr = (String *) ckrealloc((char*) stringPtr,
STRING_SIZE(uallocated));
stringPtr->uallocated = uallocated;
@@ -1359,8 +1365,7 @@ FillUnicodeRep(objPtr)
static void
DupStringInternalRep(srcPtr, copyPtr)
register Tcl_Obj *srcPtr; /* Object with internal rep to copy. Must
- * have an internal representation of type
- * "expandable string". */
+ * have an internal rep of type "String". */
register Tcl_Obj *copyPtr; /* Object with internal rep to set. Must
* not currently have an internal rep.*/
{
@@ -1388,6 +1393,7 @@ DupStringInternalRep(srcPtr, copyPtr)
copyStringPtr->unicode[srcStringPtr->numChars] = 0;
}
copyStringPtr->numChars = srcStringPtr->numChars;
+ copyStringPtr->allocated = srcStringPtr->allocated;
/*
* Tricky point: the string value was copied by generic object
diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c
index 259fcbd..2733a8c 100644
--- a/generic/tclTestObj.c
+++ b/generic/tclTestObj.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclTestObj.c,v 1.5 1999/06/15 03:14:45 hershey Exp $
+ * RCS: @(#) $Id: tclTestObj.c,v 1.6 1999/06/15 22:06:17 hershey Exp $
*/
#include "tclInt.h"
@@ -883,7 +883,7 @@ TeststringobjCmd(clientData, interp, objc, objv)
TestString *strPtr;
static char *options[] = {
"append", "appendstrings", "get", "get2", "length", "length2",
- "set", "set2", "setlength", (char *) NULL
+ "set", "set2", "setlength", "ualloc", (char *) NULL
};
if (objc < 3) {
@@ -1032,6 +1032,19 @@ TeststringobjCmd(clientData, interp, objc, objv)
Tcl_SetObjLength(varPtr[varIndex], length);
}
break;
+ case 9: /* ualloc */
+ if (objc != 3) {
+ goto wrongNumArgs;
+ }
+ if (varPtr[varIndex] != NULL) {
+ strPtr = (TestString *)
+ (varPtr[varIndex])->internalRep.otherValuePtr;
+ length = (int) strPtr->uallocated;
+ } else {
+ length = -1;
+ }
+ Tcl_SetIntObj(Tcl_GetObjResult(interp), length);
+ break;
}
return TCL_OK;
diff --git a/tests/stringObj.test b/tests/stringObj.test
index 49af6e4..3ea2573 100644
--- a/tests/stringObj.test
+++ b/tests/stringObj.test
@@ -12,7 +12,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: stringObj.test,v 1.5 1999/06/15 03:22:31 hershey Exp $
+# RCS: @(#) $Id: stringObj.test,v 1.6 1999/06/15 22:06:18 hershey Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
source [file join [pwd] [file dirname [info script]] defs.tcl]
@@ -165,20 +165,30 @@ test stringObj-6.8 {Tcl_AppendStringsToObj procedure, object totally empty} {
list [teststringobj length2 1] [teststringobj get 1]
} {0 {}}
-test stringObj-7.1 {ConvertToStringType procedure} {
+test stringObj-7.1 {SetStringFromAny procedure} {
testobj freeallvars
teststringobj set2 1 [list a b]
teststringobj append 1 x -1
list [teststringobj length 1] [teststringobj length2 1] \
[teststringobj get 1]
} {4 8 {a bx}}
-test stringObj-7.2 {ConvertToStringType procedure, null object} {
+test stringObj-7.2 {SetStringFromAny procedure, null object} {
testobj freeallvars
testobj newobj 1
teststringobj appendstrings 1 {}
list [teststringobj length 1] [teststringobj length2 1] \
[teststringobj get 1]
} {0 0 {}}
+test stringObj-7.3 {SetStringFromAny called with non-string obj} {
+ set x 2345
+ list [incr x] [testobj objtype $x] [string index $x end] \
+ [testobj objtype $x]
+} {2346 int 6 string}
+test stringObj-7.4 {SetStringFromAny called with string obj} {
+ set x "abcdef"
+ list [string length $x] [testobj objtype $x] \
+ [string length $x] [testobj objtype $x]
+} {6 string 6 string}
test stringObj-8.1 {DupStringInternalRep procedure} {
testobj freeallvars
@@ -186,31 +196,32 @@ test stringObj-8.1 {DupStringInternalRep procedure} {
teststringobj append 1 abcde -1
testobj duplicate 1 2
list [teststringobj length 1] [teststringobj length2 1] \
+ [teststringobj ualloc 1] [teststringobj get 1] \
[teststringobj length 2] [teststringobj length2 2] \
- [teststringobj get 2]
-} {5 10 5 5 abcde}
-test string-8.2 {DupUnicodeInternalRep, mixed width chars} {testobj} {
+ [teststringobj ualloc 2] [teststringobj get 2]
+} {5 10 0 abcde 5 5 0 abcde}
+test stringObj-8.2 {DupUnicodeInternalRep, mixed width chars} {
set x abcï¿®ghi
string length $x
set y $x
list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
[set y] [testobj objtype $x] [testobj objtype $y]
} {string string abcï¿®ghi®¿ï abcï¿®ghi string string}
-test string-8.3 {DupUnicodeInternalRep, mixed width chars} {testobj} {
+test stringObj-8.3 {DupUnicodeInternalRep, mixed width chars} {
set x abcï¿®ghi
set y $x
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x "®¿ï"] \
[set y] [testobj objtype $x] [testobj objtype $y]
} {string string abcï¿®ghi®¿ï abcï¿®ghi string string}
-test string-8.4 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
+test stringObj-8.4 {DupUnicodeInternalRep, all byte-size chars} {
set x abcdefghi
string length $x
set y $x
list [testobj objtype $x] [testobj objtype $y] [append x jkl] \
[set y] [testobj objtype $x] [testobj objtype $y]
} {string string abcdefghijkl abcdefghi string string}
-test string-8.5 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
+test stringObj-8.5 {DupUnicodeInternalRep, all byte-size chars} {
set x abcdefghi
set y $x
string length $x
@@ -218,14 +229,14 @@ test string-8.5 {DupUnicodeInternalRep, all byte-size chars} {testobj} {
[set y] [testobj objtype $x] [testobj objtype $y]
} {string string abcdefghijkl abcdefghi string string}
-test string-9.1 {TclAppendObjToObj, mixed src & dest} {testobj} {
+test stringObj-9.1 {TclAppendObjToObj, mixed src & dest} {
set x abcï¿®ghi
set y ®¿ï
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
[set y] [testobj objtype $x] [testobj objtype $y]
-} {string none abcï¿®ghi®¿ï ®¿ï string string}
-test string-9.2 {TclAppendObjToObj, mixed src & dest} {testobj} {
+} {string none abcï¿®ghi®¿ï ®¿ï string none}
+test stringObj-9.2 {TclAppendObjToObj, mixed src & dest} {
set x abcï¿®ghi
string length $x
list [testobj objtype $x] [append x $x] [testobj objtype $x] \
@@ -233,54 +244,54 @@ test string-9.2 {TclAppendObjToObj, mixed src & dest} {testobj} {
} {string abcï¿®ghiabcï¿®ghi string\
abcï¿®ghiabcï¿®ghiabcï¿®ghiabcï¿®ghi\
string}
-test string-9.3 {TclAppendObjToObj, mixed src & 1-byte dest} {testobj} {
+test stringObj-9.3 {TclAppendObjToObj, mixed src & 1-byte dest} {
set x abcdefghi
set y ®¿ï
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
[set y] [testobj objtype $x] [testobj objtype $y]
-} {string none abcdefghi®¿ï ®¿ï string string}
-test string-9.4 {TclAppendObjToObj, 1-byte src & dest} {testobj} {
+} {string none abcdefghi®¿ï ®¿ï string none}
+test stringObj-9.4 {TclAppendObjToObj, 1-byte src & dest} {
set x abcdefghi
set y jkl
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
[set y] [testobj objtype $x] [testobj objtype $y]
-} {string none abcdefghijkl jkl string string}
-test string-9.5 {TclAppendObjToObj, 1-byte src & dest} {testobj} {
+} {string none abcdefghijkl jkl string none}
+test stringObj-9.5 {TclAppendObjToObj, 1-byte src & dest} {
set x abcdefghi
string length $x
list [testobj objtype $x] [append x $x] [testobj objtype $x] \
[append x $x] [testobj objtype $x]
} {string abcdefghiabcdefghi string abcdefghiabcdefghiabcdefghiabcdefghi\
string}
-test string-9.6 {TclAppendObjToObj, 1-byte src & mixed dest} {testobj} {
+test stringObj-9.6 {TclAppendObjToObj, 1-byte src & mixed dest} {
set x abcï¿®ghi
set y jkl
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
[set y] [testobj objtype $x] [testobj objtype $y]
-} {string none abcï¿®ghijkl jkl string string}
-test string-9.7 {TclAppendObjToObj, integer src & dest} {testobj} {
+} {string none abcï¿®ghijkl jkl string none}
+test stringObj-9.7 {TclAppendObjToObj, integer src & dest} {
set x [expr {4 * 5}]
set y [expr {4 + 5}]
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
[testobj objtype $x] [append x $y] [testobj objtype $x] \
[testobj objtype $y]
} {int int 209 string 2099 string int}
-test string-9.8 {TclAppendObjToObj, integer src & dest} {testobj} {
+test stringObj-9.8 {TclAppendObjToObj, integer src & dest} {
set x [expr {4 * 5}]
list [testobj objtype $x] [append x $x] [testobj objtype $x] \
[append x $x] [testobj objtype $x]
} {int 2020 string 20202020 string}
-test string-9.9 {TclAppendObjToObj, integer src & 1-byte dest} {testobj} {
+test stringObj-9.9 {TclAppendObjToObj, integer src & 1-byte dest} {
set x abcdefghi
set y [expr {4 + 5}]
string length $x
list [testobj objtype $x] [testobj objtype $y] [append x $y] \
[set y] [testobj objtype $x] [testobj objtype $y]
} {string int abcdefghi9 9 string int}
-test string-9.10 {TclAppendObjToObj, integer src & mixed dest} {testobj} {
+test stringObj-9.10 {TclAppendObjToObj, integer src & mixed dest} {
set x abcï¿®ghi
set y [expr {4 + 5}]
string length $x
@@ -288,71 +299,82 @@ test string-9.10 {TclAppendObjToObj, integer src & mixed dest} {testobj} {
[set y] [testobj objtype $x] [testobj objtype $y]
} {string int abcï¿®ghi9 9 string int}
-test string-10.1 {SetStringFromAny called with non-string obj} {testobj} {
- set x 2345
- list [incr x] [testobj objtype $x] [string index $x end] \
- [testobj objtype $x]
-} {2346 int 6 string}
-test string-10.2 {SetStringFromAny called with string obj} {testobj} {
+test stringObj-10.1 {Tcl_GetRange with all byte-size chars} {
set x "abcdef"
- list [string length $x] [testobj objtype $x] \
- [string length $x] [testobj objtype $x]
-} {6 string 6 string}
+ list [testobj objtype $x] [set y [string range $x 1 end-1]] \
+ [testobj objtype $x] [testobj objtype $y]
+} {none bcde string string}
+test stringObj-10.2 {Tcl_GetRange with some mixed width chars} {
+ set x "abcïïdef"
+ list [testobj objtype $x] [set y [string range $x 1 end-1]] \
+ [testobj objtype $x] [testobj objtype $y]
+} {none bcïïde string string}
+test stringObj-10.3 {Tcl_GetRange with some mixed width chars} {
+ set x "abcïïdef"
+ string length $x
+ list [testobj objtype $x] [set y [string range $x 1 end-1]] \
+ [testobj objtype $x] [testobj objtype $y]
+} {string bcïïde string string}
+test stringObj-10.4 {Tcl_GetRange with some mixed width chars} {
+ set a "ïa¿b®cï¿d®"
+ set result [list]
+ while {[string length $a] > 0} {
+ set a [string range $a 1 end-1]
+ lappend result $a
+ }
+ set result
+} {a¿b®cï¿d ¿b®cï¿ b®cï ®c {}}
-test string-11.1 {UpdateStringOfString} {testobj} {
+test stringObj-11.1 {UpdateStringOfString} {
set x 2345
list [string index $x end] [testobj objtype $x] [incr x] \
[testobj objtype $x]
} {5 string 2346 int}
-test string-12.1 {TclGetUniCharFromObj with byte-size chars} {
- string index "abcdefghi" 0
-} "a"
-test string-12.2 {TclGetUniCharFromObj with byte-size chars} {
- string index "abcdefghi" 3
-} "d"
-test string-12.3 {TclGetUniCharFromObj with byte-size chars} {
- string index "abcdefghi" end
-} "i"
-test string-12.4 {TclGetUniCharFromObj with mixed width chars} {
+test stringObj-12.1 {Tcl_GetUniChar with byte-size chars} {
+ set x "abcdefghi"
+ list [string index $x 0] [string index $x 1]
+} {a b}
+test stringObj-12.2 {Tcl_GetUniChar with byte-size chars} {
+ set x "abcdefghi"
+ list [string index $x 3] [string index $x end]
+} {d i}
+test stringObj-12.3 {Tcl_GetUniChar with byte-size chars} {
+ set x "abcdefghi"
+ list [string index $x end] [string index $x end-1]
+} {i h}
+test stringObj-12.4 {Tcl_GetUniChar with mixed width chars} {
string index "ïa¿b®c®¿dï" 0
} "ï"
-test string-12.5 {TclGetUniCharFromObj} {
- string index "ïa¿b®c®¿dï" 4
-} "®"
-test string-12.6 {TclGetUniCharFromObj} {
+test stringObj-12.5 {Tcl_GetUniChar} {
+ set x "ïa¿b®c®¿dï"
+ list [string index $x 4] [string index $x 0]
+} {® ï}
+test stringObj-12.6 {Tcl_GetUniChar} {
string index "ïa¿b®cï¿d®" end
} "®"
-test string-13.1 {TclGetUnicodeLengthFromObj with byte-size chars} {
- string length ""
-} 0
-test string-13.2 {TclGetUnicodeLengthFromObj with byte-size chars} {
+test stringObj-13.1 {Tcl_GetCharLength with byte-size chars} {
+ set a ""
+ list [string length $a] [string length $a]
+} {0 0}
+test stringObj-13.2 {Tcl_GetCharLength with byte-size chars} {
string length "a"
} 1
-test string-13.3 {TclGetUnicodeLengthFromObj with byte-size chars} {
- string length "abcdef"
-} 6
-test string-13.4 {TclGetUnicodeLengthFromObj with mixed width chars} {
+test stringObj-13.3 {Tcl_GetCharLength with byte-size chars} {
+ set a "abcdef"
+ list [string length $a] [string length $a]
+} {6 6}
+test stringObj-13.4 {Tcl_GetCharLength with mixed width chars} {
string length "®"
} 1
-test string-13.5 {TclGetUnicodeLengthFromObj with mixed width chars} {
+test stringObj-13.5 {Tcl_GetCharLength with mixed width chars} {
string length "○○"
} 6
-test string-13.6 {TclGetUnicodeLengthFromObj with mixed width chars} {
- string length "ïa¿b®cï¿d®"
-} 10
-
-test string-14.1 {TclGetRangeFromObj with all byte-size chars} {testobj} {
- set x "abcdef"
- list [testobj objtype $x] [set y [string range $x 1 end-1]] \
- [testobj objtype $x] [testobj objtype $y]
-} {none bcde string none}
-test string-14.2 {TclGetRangeFromObj with some mixed width chars} {testobj} {
- set x "abcïïdef"
- list [testobj objtype $x] [set y [string range $x 1 end-1]] \
- [testobj objtype $x] [testobj objtype $y]
-} {none bcïïde string string}
+test stringObj-13.6 {Tcl_GetCharLength with mixed width chars} {
+ set a "ïa¿b®cï¿d®"
+ list [string length $a] [string length $a]
+} {10 10}
testobj freeallvars