Skip to content
Tcl Source Code Changes To Migrating scripts to Tcl 9
Login

Changes To Migrating scripts to Tcl 9

Changes to "Migrating scripts to Tcl 9" between 2024-06-18 02:25:30 and 2024-06-18 02:38:56

︙
273
274
275
276
277
278
279
280



















281
282
283
284
285
286
287
273
274
275
276
277
278
279

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305







-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








```
source -encoding [encoding system] file.tcl
```

For me, this is according where Windows is moving.
If I create nowdays a file using the Windows editor application, it is encoded in UTF-8.
With older WIndows versions, this was cp1252.
With older Windows versions, this was cp1252.

One effect of this is that a file written by a 8.x application using
the default encoding will not be readable by a 9.x application unless
the channel is explicitly configured to use the original encoding.
Unfortunately, there is no way to know the original default encoding.
A **guess** may be made by checking the Windows registry; something
along the lines of (error checking ignored)

```
package require registry
set winCodePage [registry get {HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage} ACP]
set tclName cp[format %u $winCodePage]
if {$tclName in [encoding names]} {
    fconfigure $chan -encoding $tclName
} else {
    ...try some other method...
}
```

## Full Unicode support

In Tcl 8, characters outside the BMP were stored as a surrogate pair
and effectively treated as a string of length 2. This is no longer
the case in Tcl 9 which has full support for the entire Unicode range
and will (correctly) treat these characters as strings of length 1.
︙