34
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
|
34
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
|
+
+
+
+
+
+
+
+
+
-
+
|
## 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
- `convertto` and `convertfrom` to encode/decode similar to Tcl's `encoding`
command except using ICU routines (added in 9.0.1)
- `normalize` to convert a string to one of NFC, NFD, NFKC or NFKD forms
(added in 9.0.1)
```
icu detect ?DATA ?-all??
icu icuToTcl ICUENCODINGNAME
icu tclToIcu TCLENCODINGNAME
icu convertto -profile strict|replace ICUENCODINGNAME STRING
icu convertfrom -profile strict|replace ICUENCODINGNAME ENCODEDBINARY
icu normalize -profile strict|replace -mode nfc|nfd|nfkc|nfkd STRING
```
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.
The semantics of the other commands should be (hopefully) obvious.
Some caveats:
Some caveats regarding encoding detection:
- 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.
|
82
83
84
85
86
87
88
89
90
91
92
|
91
92
93
94
95
96
97
98
99
100
|
-
|
Combining the two is for a later time.
Like Tk, the build system is unaffected as the ICU libraries are
loaded only at runtime. This is intentional though there is a performance
cost associated with searching for the library. This is acceptable
as it will only be incurred on use of the `icu` command.
Code is in branch [apn-experiment-chardet](https://core.tcl-lang.org/tcl/timeline?r=apn-experiment-chardet).
|