Skip to content
Tcl Source Code Changes To UTF-8 String
Login

Changes To UTF-8 String

Changes to "UTF-8 String" between 2014-09-07 02:19:58 and 2014-09-07 02:28:07

︙
89
90
91
92
93
94
95
96
97




98
99





100


101

102
103
104
89
90
91
92
93
94
95


96
97
98
99
100

101
102
103
104
105
106
107
108

109
110
111
112







-
-
+
+
+
+

-
+
+
+
+
+

+
+
-
+



UTF-16 data from external sources, notably command line data on Windows.  On the
contrary, UTF-16 is a variable length encoding so the advantage for those operations
is at least diminished, if not lost.  If we must manage a variable-length encoding
anyway, we might as well just stick with one encoding for the simplicity that would
imply.  To the extent that might happen, many of the routines here would just become
deprecated legacy support routines.


---
There is no fully specified answer for efficient implementation of the string operations
currently performed using Tcl_UniChar arrays while keeping the data in Modified UTF-8.
The "rope" data structure may be helpful, or other indexing systems marking out
substrings to speed up random access to arbitrary indices.

Re "Other ways": One idea is to make the 'string rep' not a copy of the bytes in a different format, but some type of index over them, allowing (amortized) O(1) access to all characters despite the vari-length of UTF-8 encoding. While the idea of "ropes" has been thrown about it is not clear if that can be combined with the above or not.
Unicode normalization forms have not been address at all In Tcl's unicode string
handling.  In particular, canonically equivalent Unicode strings do not test as 
equal according to the [string equal] command.  These complications also undermine
the apparent efficiency value of a fixed-width encoding, decreasing the odds that the
Tcl_UniChar will play an important role going forward.

The current BMP limitation of Tcl strings has had another consequence in its
UTF-8 management.  The longest byte sequences decoded into codepoints have
Note further that Tcl 8 restricts UTF-8 to a maximum length of 3 bytes. This is in line with our restriction to the BMP. Covering the entire set of Unicode codepoints requires us to support UTF-8 to up to 4 characters (<b>#define TCL_UTF_MAX 4</b>).
length 3.  Covering the entire set of Unicode codepoints requires us to support UTF-8 to up to 4 characters (<b>#define TCL_UTF_MAX 4</b>).