Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e7423af46b7b00fc6c37ea8495d1419e38de55ab
Ticket: 578030ffffffffffffffffffffffffffffffffff
Tcl_UniChar is only 16 bits
User & Date: keithp on 2002-07-09 23:15:32
Changes

  1. icomment:
    Logged In: YES 
    user_id=50020
    
    (section 2.2 of Unicode 3.0)
    
    "From the full range of 65536 code values, 63486 are
    available to represent characters with 16-bit code values
    and 2048 code values are available to represent and
    additional 1048544 characters through paired 16-bit code
    values.  These paired code values, or surrogates, will allow
    implementations access to additional characters in the
    future. <em>None of these surrogate pairs has been assigned
    in this version of the standard.</em>"
    
    In version 3.1 and 3.2, there have been significant
    additions to the Unicode standard, including many thousands
    of glyphs outside of what is now called the "basic
    multiligual plane" (BMP).  Several new encodings have been
    defined, the basic 16-bit encoding (UCS2) no longer provides
    the 1-value 1-codepoint mapping which Tcl assumes.
    
    The encoding standard hasn't changed, 3.0 explicitly allows
    for codepoints outside the BMP, what's changed is that there
    are now many defined codepoints in this extended range.
    
    If the intent is to have Tcl support Unicode, then there is
    no question that these additional codepoints must be
    representable, the only question is how to do so.  I
    recommend abandoing the 16 bit encoding as useless; it
    doesn't provide the 1-to-1 mapping which makes constant-time
    indexing trivial, and with surrogates, it requires more
    bytes on average to represent the same data than UTF-8.  You
    may still want to provide the existing 16-bit APIs for some
    level of binary compatibility; those APIs can use surrogates
    to ensure all Unicode codepoints are representable.  APIs
    involving a single codepoint should transition to using a
    new 32-bit datatype.
    
    Constant-time indexing can be implemented using indexes into
    the string, one trivial design would have a 32-bit index for
    each 256 codepoints.  That means locating a codepoint by
    index takes a table lookup to find the offset (constant
    time) and a search through that portion of the data (time
    bounded by a constant).\
    
    UTF-8 now specifies that up to 6 bytes may be required to
    hold a value.  Raising only that limit provides the minimum
    required functionality to use non-BMP glyphs in Tcl; I've
    implemented a modern X backend that can access non-BMP
    glyphs as long as the strings are never represented as
    arrays of Tcl_UniChars inside the interpreter.  The only
    difficulty there was that the internal UTF8 to UCS converter
    is defined to return a Tcl_UniChar and so I had to use a
    separate complete implementation.
    
    
  2. login: "keithp"
  3. mimetype: "text/plain"
  4. username: "keithp"