Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 34e77fdbc4c5ba9fc1634ca58f41111633f9e81d3326611e58e4171097ddaf87
Ticket: debd088e48998a758f2927b67c132341954428ea
llength split is different from string length
User & Date: jan.nijtmans on 2021-02-15 17:53:03
Changes

  1. icomment:
    @kyak: How about still using "split" but being able to handle codes > 0xFFFF:
    <pre>
    foreach char [split $str {}] {
    	scan $char %c code
    	if {$code > 0xFFFF} {
    		append result [format "\\U%06.6x" $code]
    		#append result [format "\\u%04.4x\\u%04.4x" [expr {(($code-0x10000)>>10)+0xD800}] [expr {(($code-0x10000)&0x3FF)+0xDC00}]]
    	} elseif {$code > 127} {
    		append result [format "\\u%04.4x3" $code]
    	} else {
    		append result $char
    	}
    }
    </pre>
    
    This way, you can handle codes > 0xFFFF separately, any way you like, either using the \U?????? syntax, or split it in surrogates.
    
    This will continue to work in Tcl 8.7 and Tcl 9.0 as well!
    
  2. login: "jan.nijtmans"
  3. mimetype: "text/x-fossil-wiki"