Skip to content
Tcl Source Code Changes To Unsupported icu command
Login

Changes To Unsupported icu command

Changes to "Unsupported icu command" between 2024-06-16 12:02:43 and 2024-06-18 17:09:38

︙
35
36
37
38
39
40
41

























42
43


44
45
46
47
48
49
50
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66


67
68
69
70
71
72
73
74
75







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







## Specification

The `tcl::unsupported::icu` command ensemble includes subcommands

- `detect` to guess file encodings
- `icuToTcl` and `tclToIcu` to map ICU names to Tcl encoding names and vice versa

```
icu detect ?DATA ?-all??
icu icuToTcl ICUENCODINGNAME
icu tclToIcu TCLENCODINGNAME
```

With no arguments, `icu detect` returns names of all encodings known to ICU.
If `data` is specified, it should be a binary string and the commands
returns the ICU name of the most likely encoding.
If the `-all` option is specified, it returns a list of possible ICU encoding
names ordered by their confidence score (highest to lowest).
An empty string is returned if there nothing matches.

Some caveats:

- Does not give good results for shorter strings for obvious reasons.

- Best results if caller first checks for UTF-8 and then calls `icu detect`
since a false positive is very unlikely for UTF-8 while ICU often mistakes
UTF-8 for ISO8859-1. This is the strategy followed by the `tcl9migrate`
package.

- Additionally, when dealing with Windows file content, better to check
for UTF-8, followed by current code page, then `icu detect`.

These wrap the lower level ICU API which is internal use only at the moment and not
documented here.
The above commands wrap the lower level ICU API which is internal use
only at the moment and not documented here.

The command will be auto-loaded on first use.

The ICU libraries will not be shipped with Tcl and the functionality
will not be available on systems that do not have them installed.
This is acceptable because the intended use is on developer systems
used for porting scripts. On recent versions of Windows 10 and later,
︙