Overview
| Artifact ID: | b3d088ecab858738ad9226b3aef77d657d097dee6a80bbcfd67a720089ac95bb |
|---|---|
| Ticket: | 81242a48c80efaecf2c70271cafa2c2a0a3bf126
Documentation for Tcl_UtfAtIndex() is incorrect |
| User & Date: | jan.nijtmans on 2020-05-12 13:20:04 |
Changes
- assignee changed to: "jan.nijtmans"
- icomment:
OK, build failures can be seen here: [https://travis-ci.org/github/tcltk/tcl/jobs/685533037https://travis-ci.org/github/tcltk/tcl/jobs/685533037]. The reason for the test failures are that sequences of 3 continuation bytes (e.g. \xA0\xA0\xA0) don't work well. If they are preceded by e.g. \xF2, it's a valid 4-byte sequence according to TIP #389. But Tcl_UtfNext() doesn't have access to src[-1]. Tcl_UtfToUniChar() has access to its previous bytes, because it uses chPtr to store the previous result of Tcl_UtfToUniChar(). If the previous result was an upper surrogate, Tcl_UtfToUniChar() can conclude - in this case - that it's handling a valid 4-byte UTF-8 sequence. Tcl_UtfNext() cannot do that. So, how should we fix this documentation? The easiest fix is saying "is equivalent to calling -\fBTcl_UtfToUniChar\fR \fIindex\fR times". Still that's not 100% correct: In the TIP #389 implementation, Tcl_UtfAtIndex() executes Tcl_UtfToUniChar() one additional time when it detects that index points in the middle of a character >U+FFFF. So, next experiment: What happens if we don't do the extra call to Tcl_UtfToUniChar() any more? If that works, the documentation change is easy. If it cannot be done, the description becomes a little bit more complicated. When this documentation was written, surrogates didn't exist yet in the Unicode standard. Code points > U+FFFF didn't exist yet either. So, it's very understandable no-one noticed this up to now: Tcl never supported code points > U+FFFF either.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"