Skip to content

Commit 7faef9c

Browse files
author
jan.nijtmans
committed
Update documentation, matching current implementation
1 parent ba6fe47 commit 7faef9c

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

doc/encoding.n

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ formats.
2828
Performs one of several encoding related operations, depending on
2929
\fIoption\fR. The legal \fIoption\fRs are:
3030
.TP
31-
\fBencoding convertfrom\fR ?\fB-nocomplain\fR? ?\fB-failindex var\fR? ?\fB-strict\fR? ?\fIencoding\fR? \fIdata\fR
31+
\fBencoding convertfrom\fR ?\fB-nocomplain\fR|\fB-strict\fR|\fB-failindex var\fR? ?\fIencoding\fR? \fIdata\fR
3232
.
3333
Convert \fIdata\fR to a Unicode string from the specified \fIencoding\fR. The
3434
characters in \fIdata\fR are 8 bit binary data. The resulting
@@ -48,19 +48,19 @@ in case of a conversion error, the position of the input byte causing the error
4848
is returned in the given variable. The return value of the command are the
4949
converted characters until the first error position.
5050
In case of no error, the value \fI-1\fR is written to the variable. This option
51-
may not be used together with \fB-nocomplain\fR.
51+
may not be used together with \fB-nocomplain\fR or \fB-strict\fR.
5252
.PP
5353
The option \fB-nocomplain\fR has no effect and is available for compatibility with
5454
TCL 9. In TCL 9, the encoding command fails with an error on any encoding issue.
5555
This switch restores the TCL8.7 behaviour.
5656
.PP
5757
The \fB-strict\fR option follows more strict rules in conversion. For the \fButf-8\fR
58-
encoder, it disallows the the sequence \fB\\xC0\\x80\fR and noncharacters (which -
58+
encoder, it disallows invalid byte sequences and surrogates (which -
5959
otherwise - are just passed through).
6060
.VE "TCL8.7 TIP346, TIP607, TIP601"
6161
.RE
6262
.TP
63-
\fBencoding convertto\fR ?\fB-nocomplain\fR? ?\fB-failindex var\fR? ?\fB-strict\fR? ?\fIencoding\fR? \fIstring\fR
63+
\fBencoding convertto\fR ?\fB-nocomplain\fR|\fB-strict\fR|\fB-failindex var\fR? ?\fIencoding\fR? \fIstring\fR
6464
.
6565
Convert \fIstring\fR from Unicode to the specified \fIencoding\fR.
6666
The result is a sequence of bytes that represents the converted
@@ -81,15 +81,14 @@ in case of a conversion error, the position of the input character causing the e
8181
is returned in the given variable. The return value of the command are the
8282
converted bytes until the first error position. No error condition is raised.
8383
In case of no error, the value \fI-1\fR is written to the variable. This option
84-
may not be used together with \fB-nocomplain\fR.
84+
may not be used together with \fB-nocomplain\fR or \fB-strict\fR.
8585
.PP
8686
The option \fB-nocomplain\fR has no effect and is available for compatibility with
8787
TCL 9. In TCL 9, the encoding command fails with an error on any encoding issue.
8888
This switch restores the TCL8.7 behaviour.
8989
.PP
9090
The \fB-strict\fR option follows more strict rules in conversion. For the \fButf-8\fR
91-
encoder, it disallows the the sequence \fB\\xC0\\x80\fR and noncharacters (which -
92-
otherwise - are just passed through).
91+
encoder, it disallows surrogates (which - otherwise - are just passed through).
9392
.VE "TCL8.7 TIP346, TIP607, TIP601"
9493
.RE
9594
.TP

generic/tclCmdAH.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ EncodingConvertfromObjCmd(
610610
}
611611
} else {
612612
encConvFromError:
613-
Tcl_WrongNumArgs(interp, 1, objv, "?-nocomplain? ?-strict? ?-failindex var? ?encoding? data");
613+
Tcl_WrongNumArgs(interp, 1, objv, "?-nocomplain|-strict|-failindex var? ?encoding? data");
614614
return TCL_ERROR;
615615
}
616616

@@ -749,7 +749,7 @@ EncodingConverttoObjCmd(
749749
}
750750
} else {
751751
encConvToError:
752-
Tcl_WrongNumArgs(interp, 1, objv, "?-nocomplain? ?-strict? ?-failindex var? ?encoding? data");
752+
Tcl_WrongNumArgs(interp, 1, objv, "?-nocomplain|-strict|-failindex var? ?encoding? data");
753753
return TCL_ERROR;
754754
}
755755

tests/cmdAH.test

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ test cmdAH-4.2 {Tcl_EncodingObjCmd} -returnCodes error -body {
179179
} -result {unknown or ambiguous subcommand "foo": must be convertfrom, convertto, dirs, names, or system}
180180
test cmdAH-4.3 {Tcl_EncodingObjCmd} -returnCodes error -body {
181181
encoding convertto
182-
} -result {wrong # args: should be "encoding convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
182+
} -result {wrong # args: should be "encoding convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"}
183183
test cmdAH-4.4 {Tcl_EncodingObjCmd} -returnCodes error -body {
184184
encoding convertto foo bar
185185
} -result {unknown encoding "foo"}
@@ -201,7 +201,7 @@ test cmdAH-4.6 {Tcl_EncodingObjCmd} -setup {
201201
} -result 8C
202202
test cmdAH-4.7 {Tcl_EncodingObjCmd} -returnCodes error -body {
203203
encoding convertfrom
204-
} -result {wrong # args: should be "encoding convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
204+
} -result {wrong # args: should be "encoding convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"}
205205
test cmdAH-4.8 {Tcl_EncodingObjCmd} -returnCodes error -body {
206206
encoding convertfrom foo bar
207207
} -result {unknown encoding "foo"}
@@ -238,10 +238,10 @@ test cmdAH-4.13 {Tcl_EncodingObjCmd} -setup {
238238

239239
test cmdAH-4.14.1 {Syntax error, -nocomplain and -failindex, no encoding} -body {
240240
encoding convertfrom -nocomplain -failindex 2 ABC
241-
} -returnCodes 1 -result {wrong # args: should be "encoding convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
241+
} -returnCodes 1 -result {wrong # args: should be "encoding convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"}
242242
test cmdAH-4.14.2 {Syntax error, -nocomplain and -failindex, no encoding} -body {
243243
encoding convertto -nocomplain -failindex 2 ABC
244-
} -returnCodes 1 -result {wrong # args: should be "encoding convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
244+
} -returnCodes 1 -result {wrong # args: should be "encoding convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"}
245245
test cmdAH-4.15.1 {Syntax error, -failindex and -nocomplain, no encoding} -body {
246246
encoding convertfrom -failindex 2 -nocomplain ABC
247247
} -returnCodes 1 -result {unknown encoding "-nocomplain"}
@@ -250,40 +250,40 @@ test cmdAH-4.15.2 {Syntax error, -failindex and -nocomplain, no encoding} -body
250250
} -returnCodes 1 -result {unknown encoding "-nocomplain"}
251251
test cmdAH-4.16.1 {Syntax error, -nocomplain and -failindex, encoding} -body {
252252
encoding convertfrom -nocomplain -failindex 2 utf-8 ABC
253-
} -returnCodes 1 -result {wrong # args: should be "encoding convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
253+
} -returnCodes 1 -result {wrong # args: should be "encoding convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"}
254254
test cmdAH-4.16.2 {Syntax error, -nocomplain and -failindex, encoding} -body {
255255
encoding convertto -nocomplain -failindex 2 utf-8 ABC
256-
} -returnCodes 1 -result {wrong # args: should be "encoding convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
256+
} -returnCodes 1 -result {wrong # args: should be "encoding convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"}
257257
test cmdAH-4.17.1 {Syntax error, -failindex and -nocomplain, encoding} -body {
258258
encoding convertfrom -failindex 2 -nocomplain utf-8 ABC
259-
} -returnCodes 1 -result {wrong # args: should be "encoding convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
259+
} -returnCodes 1 -result {wrong # args: should be "encoding convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"}
260260
test cmdAH-4.17.2 {Syntax error, -failindex and -nocomplain, encoding} -body {
261261
encoding convertto -failindex 2 -nocomplain utf-8 ABC
262-
} -returnCodes 1 -result {wrong # args: should be "encoding convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
262+
} -returnCodes 1 -result {wrong # args: should be "encoding convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"}
263263
test cmdAH-4.18.1 {Syntax error, -failindex with no var, no encoding} -body {
264264
encoding convertfrom -failindex ABC
265-
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
265+
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"}
266266
test cmdAH-4.18.2 {Syntax error, -failindex with no var, no encoding (byte compiled)} -setup {
267267
proc encoding_test {} {
268268
encoding convertfrom -failindex ABC
269269
}
270270
} -body {
271271
# Compile and execute
272272
encoding_test
273-
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"} -cleanup {
273+
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"} -cleanup {
274274
rename encoding_test ""
275275
}
276276
test cmdAH-4.18.3 {Syntax error, -failindex with no var, no encoding} -body {
277277
encoding convertto -failindex ABC
278-
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
278+
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"}
279279
test cmdAH-4.18.4 {Syntax error, -failindex with no var, no encoding (byte compiled)} -setup {
280280
proc encoding_test {} {
281281
encoding convertto -failindex ABC
282282
}
283283
} -body {
284284
# Compile and execute
285285
encoding_test
286-
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"} -cleanup {
286+
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"} -cleanup {
287287
rename encoding_test ""
288288
}
289289
test cmdAH-4.19.1 {convertrom -failindex with correct data} -body {

tests/encoding.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,10 @@ test encoding-24.21 {Parse with -nocomplain but without providing encoding} {
681681
} 1
682682
test encoding-24.22 {Syntax error, two encodings} -body {
683683
encoding convertfrom iso8859-1 utf-8 "ZX\uD800"
684-
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
684+
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"}
685685
test encoding-24.23 {Syntax error, two encodings} -body {
686686
encoding convertto iso8859-1 utf-8 "ZX\uD800"
687-
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
687+
} -returnCodes 1 -result {wrong # args: should be "::tcl::encoding::convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"}
688688
test encoding-24.24 {Parse invalid utf-8 with -strict} -body {
689689
encoding convertfrom -strict utf-8 "\xC0\x80\x00\x00"
690690
} -returnCodes 1 -result {unexpected byte sequence starting at index 0: '\xC0'}

tests/safe.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ test safe-11.7 {testing safe encoding} -setup {
14731473
interp eval $i encoding convertfrom
14741474
} -returnCodes error -cleanup {
14751475
safe::interpDelete $i
1476-
} -result {wrong # args: should be "encoding convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
1476+
} -result {wrong # args: should be "encoding convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"}
14771477
test safe-11.7.1 {testing safe encoding} -setup {
14781478
set i [safe::interpCreate]
14791479
} -body {
@@ -1482,7 +1482,7 @@ test safe-11.7.1 {testing safe encoding} -setup {
14821482
} -match glob -cleanup {
14831483
unset -nocomplain m o
14841484
safe::interpDelete $i
1485-
} -result {wrong # args: should be "encoding convertfrom ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"
1485+
} -result {wrong # args: should be "encoding convertfrom ?-nocomplain|-strict|-failindex var? ?encoding? data"
14861486
while executing
14871487
"encoding convertfrom"
14881488
invoked from within
@@ -1495,7 +1495,7 @@ test safe-11.8 {testing safe encoding} -setup {
14951495
interp eval $i encoding convertto
14961496
} -returnCodes error -cleanup {
14971497
safe::interpDelete $i
1498-
} -result {wrong # args: should be "encoding convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"}
1498+
} -result {wrong # args: should be "encoding convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"}
14991499
test safe-11.8.1 {testing safe encoding} -setup {
15001500
set i [safe::interpCreate]
15011501
} -body {
@@ -1504,7 +1504,7 @@ test safe-11.8.1 {testing safe encoding} -setup {
15041504
} -match glob -cleanup {
15051505
unset -nocomplain m o
15061506
safe::interpDelete $i
1507-
} -result {wrong # args: should be "encoding convertto ?-nocomplain? ?-strict? ?-failindex var? ?encoding? data"
1507+
} -result {wrong # args: should be "encoding convertto ?-nocomplain|-strict|-failindex var? ?encoding? data"
15081508
while executing
15091509
"encoding convertto"
15101510
invoked from within

0 commit comments

Comments
 (0)