diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-05-06 11:35:39 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-05-06 11:35:39 (GMT) |
commit | 9e781ffb02d3f384c1123ddcb6f96944cc4dc3ef (patch) | |
tree | d792e201c80cd14fc8eb261bd6c1c3d273b70190 | |
parent | 0616d450dae0ecb9edcee20854e9c4d327458c1a (diff) | |
download | tcl-9e781ffb02d3f384c1123ddcb6f96944cc4dc3ef.zip tcl-9e781ffb02d3f384c1123ddcb6f96944cc4dc3ef.tar.gz tcl-9e781ffb02d3f384c1123ddcb6f96944cc4dc3ef.tar.bz2 |
Make ?-stoponerror|-nothrow? argument first in stead of last for encoding convertto/convertfrom
-rw-r--r-- | generic/tclCmdAH.c | 16 | ||||
-rw-r--r-- | tests/cmdAH.test | 4 | ||||
-rw-r--r-- | tests/encoding.test | 58 | ||||
-rw-r--r-- | tests/safe.test | 8 |
4 files changed, 43 insertions, 43 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index cb5ef01..682ba3f 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -557,12 +557,12 @@ EncodingConvertfromObjCmd( encoding = Tcl_GetEncoding(interp, NULL); data = objv[1]; } else if ((unsigned)(objc - 3) < 2) { - if (Tcl_GetEncodingFromObj(interp, objv[1], &encoding) != TCL_OK) { + if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) { return TCL_ERROR; } - data = objv[2]; + data = objv[objc - 1]; if (objc > 3) { - stopOnError = Tcl_GetString(objv[3]); + stopOnError = Tcl_GetString(objv[1]); if (!stopOnError[0]) { #if TCL_MAJOR_VERSION < 9 && !defined(TCL_NO_DEPRECATED) stopOnError = NULL; @@ -582,7 +582,7 @@ EncodingConvertfromObjCmd( } } else { encConvFromError: - Tcl_WrongNumArgs(interp, 1, objv, "?encoding? data ?-stoponerror|-nothrow?"); + Tcl_WrongNumArgs(interp, 1, objv, "?-stoponerror|-nothrow? ?encoding? data"); return TCL_ERROR; } @@ -661,12 +661,12 @@ EncodingConverttoObjCmd( encoding = Tcl_GetEncoding(interp, NULL); data = objv[1]; } else if ((unsigned)(objc - 3) < 2) { - if (Tcl_GetEncodingFromObj(interp, objv[1], &encoding) != TCL_OK) { + if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) { return TCL_ERROR; } - data = objv[2]; + data = objv[objc - 1]; if (objc > 3) { - stopOnError = Tcl_GetString(objv[3]); + stopOnError = Tcl_GetString(objv[1]); if (!stopOnError[0]) { #if TCL_MAJOR_VERSION < 9 && !defined(TCL_NO_DEPRECATED) stopOnError = NULL; @@ -686,7 +686,7 @@ EncodingConverttoObjCmd( } } else { encConvToError: - Tcl_WrongNumArgs(interp, 1, objv, "?encoding? data ?-stoponerror|-nothrow?"); + Tcl_WrongNumArgs(interp, 1, objv, "?-stoponerror|-nothrow? ?encoding? data"); return TCL_ERROR; } diff --git a/tests/cmdAH.test b/tests/cmdAH.test index e9973a9..5cf8fac 100644 --- a/tests/cmdAH.test +++ b/tests/cmdAH.test @@ -178,7 +178,7 @@ test cmdAH-4.2 {Tcl_EncodingObjCmd} -returnCodes error -body { } -result {unknown or ambiguous subcommand "foo": must be convertfrom, convertto, dirs, names, or system} test cmdAH-4.3 {Tcl_EncodingObjCmd} -returnCodes error -body { encoding convertto -} -result {wrong # args: should be "encoding convertto ?encoding? data ?-stoponerror|-nothrow?"} +} -result {wrong # args: should be "encoding convertto ?-stoponerror|-nothrow? ?encoding? data"} test cmdAH-4.4 {Tcl_EncodingObjCmd} -returnCodes error -body { encoding convertto foo bar } -result {unknown encoding "foo"} @@ -200,7 +200,7 @@ test cmdAH-4.6 {Tcl_EncodingObjCmd} -setup { } -result 8C test cmdAH-4.7 {Tcl_EncodingObjCmd} -returnCodes error -body { encoding convertfrom -} -result {wrong # args: should be "encoding convertfrom ?encoding? data ?-stoponerror|-nothrow?"} +} -result {wrong # args: should be "encoding convertfrom ?-stoponerror|-nothrow? ?encoding? data"} test cmdAH-4.8 {Tcl_EncodingObjCmd} -returnCodes error -body { encoding convertfrom foo bar } -result {unknown encoding "foo"} diff --git a/tests/encoding.test b/tests/encoding.test index 5471e0b..91fb1ec 100644 --- a/tests/encoding.test +++ b/tests/encoding.test @@ -291,7 +291,7 @@ test encoding-11.9 {encoding: extended Unicode UTF-16} { test encoding-12.1 {LoadTableEncoding: normal encoding} { set x [encoding convertto iso8859-3 Ġ] - append x [encoding convertto iso8859-3 Õ -nothrow] + append x [encoding convertto -nothrow iso8859-3 Õ] append x [encoding convertfrom iso8859-3 Õ] } "Õ?Ġ" test encoding-12.2 {LoadTableEncoding: single-byte encoding} { @@ -340,67 +340,67 @@ test encoding-15.5 {UtfToUtfProc emoji character input} { } "4 😂" test encoding-15.6 {UtfToUtfProc emoji character output} { set x \uDE02\uD83D\uDE02\uD83D - set y [encoding convertto utf-8 \uDE02\uD83D\uDE02\uD83D -nothrow] + set y [encoding convertto -nothrow utf-8 \uDE02\uD83D\uDE02\uD83D] binary scan $y H* z list [string length $y] $z } {10 efbfbdf09f9882efbfbd} test encoding-15.7 {UtfToUtfProc emoji character output} { set x \uDE02\uD83D\uD83D - set y [encoding convertto utf-8 \uDE02\uD83D\uD83D -nothrow] + set y [encoding convertto -nothrow utf-8 \uDE02\uD83D\uD83D] binary scan $y H* z list [string length $x] [string length $y] $z } {3 9 efbfbdefbfbdefbfbd} test encoding-15.8 {UtfToUtfProc emoji character output} { set x \uDE02\uD83Dé - set y [encoding convertto utf-8 \uDE02\uD83Dé -nothrow] + set y [encoding convertto -nothrow utf-8 \uDE02\uD83Dé] binary scan $y H* z list [string length $x] [string length $y] $z } {3 8 efbfbdefbfbdc3a9} test encoding-15.9 {UtfToUtfProc emoji character output} { set x \uDE02\uD83DX - set y [encoding convertto utf-8 \uDE02\uD83DX -nothrow] + set y [encoding convertto -nothrow utf-8 \uDE02\uD83DX] binary scan $y H* z list [string length $x] [string length $y] $z } {3 7 efbfbdefbfbd58} test encoding-15.10 {UtfToUtfProc high surrogate character output} { set x \uDE02é - set y [encoding convertto utf-8 \uDE02é -nothrow] + set y [encoding convertto -nothrow utf-8 \uDE02é] binary scan $y H* z list [string length $x] [string length $y] $z } {2 5 efbfbdc3a9} test encoding-15.11 {UtfToUtfProc low surrogate character output} { set x \uDA02é - set y [encoding convertto utf-8 \uDA02é -nothrow] + set y [encoding convertto -nothrow utf-8 \uDA02é] binary scan $y H* z list [string length $x] [string length $y] $z } {2 5 efbfbdc3a9} test encoding-15.12 {UtfToUtfProc high surrogate character output} { set x \uDE02Y - set y [encoding convertto utf-8 \uDE02Y -nothrow] + set y [encoding convertto -nothrow utf-8 \uDE02Y] binary scan $y H* z list [string length $x] [string length $y] $z } {2 4 efbfbd59} test encoding-15.13 {UtfToUtfProc low surrogate character output} { set x \uDA02Y - set y [encoding convertto utf-8 \uDA02Y -nothrow] + set y [encoding convertto -nothrow utf-8 \uDA02Y] binary scan $y H* z list [string length $x] [string length $y] $z } {2 4 efbfbd59} test encoding-15.14 {UtfToUtfProc high surrogate character output} { set x \uDE02 - set y [encoding convertto utf-8 \uDE02 -nothrow] + set y [encoding convertto -nothrow utf-8 \uDE02] binary scan $y H* z list [string length $x] [string length $y] $z } {1 3 efbfbd} test encoding-15.15 {UtfToUtfProc low surrogate character output} { set x \uDA02 - set y [encoding convertto utf-8 \uDA02 -nothrow] + set y [encoding convertto -nothrow utf-8 \uDA02] binary scan $y H* z list [string length $x] [string length $y] $z } {1 3 efbfbd} test encoding-15.16 {UtfToUtfProc: Invalid 4-byte UTF-8, see [ed29806ba]} { set x \xF0\xA0\xA1\xC2 - set y [encoding convertfrom utf-8 \xF0\xA0\xA1\xC2 -nothrow] + set y [encoding convertfrom -nothrow utf-8 \xF0\xA0\xA1\xC2] list [string length $x] $y } "4 \xF0\xA0\xA1\xC2" test encoding-15.17 {UtfToUtfProc emoji character output} { @@ -458,10 +458,10 @@ test encoding-17.2 {UtfToUcs2Proc} -body { encoding convertfrom utf-16 [encoding convertto ucs-2 "\U460DC"] } -result "\uFFFD" test encoding-17.3 {UtfToUtf16Proc} -body { - encoding convertto utf-16be "\uDCDC" -nothrow + encoding convertto -nothrow utf-16be "\uDCDC" } -result "\xFF\xFD" test encoding-17.4 {UtfToUtf16Proc} -body { - encoding convertto utf-16le "\uD8D8" -nothrow + encoding convertto -nothrow utf-16le "\uD8D8" } -result "\xFD\xFF" test encoding-18.1 {TableToUtfProc} { @@ -580,52 +580,52 @@ test encoding-24.4 {Parse valid or invalid utf-8} { string length [encoding convertfrom utf-8 "\xC0\x80"] } 1 test encoding-24.5 {Parse valid or invalid utf-8} { - string length [encoding convertfrom utf-8 "\xC0\x81" -nothrow] + string length [encoding convertfrom -nothrow utf-8 "\xC0\x81"] } 2 test encoding-24.6 {Parse valid or invalid utf-8} { - string length [encoding convertfrom utf-8 "\xC1\xBF" -nothrow] + string length [encoding convertfrom -nothrow utf-8 "\xC1\xBF"] } 2 test encoding-24.7 {Parse valid or invalid utf-8} { string length [encoding convertfrom utf-8 "\xC2\x80"] } 1 test encoding-24.8 {Parse valid or invalid utf-8} { - string length [encoding convertfrom utf-8 "\xE0\x80\x80" -nothrow] + string length [encoding convertfrom -nothrow utf-8 "\xE0\x80\x80"] } 3 test encoding-24.9 {Parse valid or invalid utf-8} { - string length [encoding convertfrom utf-8 "\xE0\x9F\xBF" -nothrow] + string length [encoding convertfrom -nothrow utf-8 "\xE0\x9F\xBF"] } 3 test encoding-24.10 {Parse valid or invalid utf-8} { string length [encoding convertfrom utf-8 "\xE0\xA0\x80"] } 1 test encoding-24.11 {Parse valid or invalid utf-8} { - string length [encoding convertfrom utf-8 "\xEF\xBF\xBF" -nothrow] + string length [encoding convertfrom -nothrow utf-8 "\xEF\xBF\xBF"] } 1 test encoding-24.12 {Parse valid or invalid utf-8} { - string length [encoding convertfrom utf-8 "\xC0\x80" -stoponerror] + string length [encoding convertfrom -stoponerror utf-8 "\xC0\x80"] } 1 test encoding-24.13 {Parse valid or invalid utf-8} -body { - encoding convertfrom utf-8 "\xC0\x81" -stoponerror + encoding convertfrom -stoponerror utf-8 "\xC0\x81" } -returnCodes 1 -result {unexpected byte at index 0: 'À' (\xC0)} test encoding-24.14 {Parse valid or invalid utf-8} -body { - encoding convertfrom utf-8 "\xC1\xBF" -stoponerror + encoding convertfrom -stoponerror utf-8 "\xC1\xBF" } -returnCodes 1 -result {unexpected byte at index 0: 'Á' (\xC1)} test encoding-24.15 {Parse valid or invalid utf-8} { - string length [encoding convertfrom utf-8 "\xC2\x80" -stoponerror] + string length [encoding convertfrom -stoponerror utf-8 "\xC2\x80"] } 1 test encoding-24.16 {Parse valid or invalid utf-8} -body { - encoding convertfrom utf-8 "Z\xE0\x80" -stoponerror + encoding convertfrom -stoponerror utf-8 "Z\xE0\x80" } -returnCodes 1 -result {unexpected byte at index 1: 'à' (\xE0)} test encoding-24.17 {Parse valid or invalid utf-8} -constraints testbytestring -body { - encoding convertto utf-8 [testbytestring "Z\u4343\x80"] -stoponerror + encoding convertto -stoponerror utf-8 [testbytestring "Z\u4343\x80"] } -returnCodes 1 -result {expected byte sequence but character 1 was '䍃' (U+004343)} test encoding-24.18 {Parse valid or invalid utf-8} -constraints testbytestring -body { - encoding convertto utf-8 [testbytestring "Z\xE0\x80"] -stoponerror + encoding convertto -stoponerror utf-8 [testbytestring "Z\xE0\x80"] } -result "Z\xC3\xA0\xE2\x82\xAC" test encoding-24.19 {Parse valid or invalid utf-8} -constraints testbytestring -body { - encoding convertto utf-8 [testbytestring "Z\xE0\x80xxxxxx"] -stoponerror + encoding convertto -stoponerror utf-8 [testbytestring "Z\xE0\x80xxxxxx"] } -result "Z\xC3\xA0\xE2\x82\xACxxxxxx" test encoding-24.20 {Parse valid or invalid utf-8} -constraints testbytestring -body { - encoding convertto utf-8 "ZX\uD800" -stoponerror + encoding convertto -stoponerror utf-8 "ZX\uD800" } -returnCodes 1 -match glob -result "unexpected character at index 2: '\uD800' (U+00D800)" file delete [file join [temporaryDirectory] iso2022.txt] @@ -781,7 +781,7 @@ test encoding-28.0 {all encodings load} -body { set string hello foreach name [encoding names] { incr count - encoding convertto $name $string -nothrow + encoding convertto -nothrow $name $string # discard the cached internal representation of Tcl_Encoding # Unfortunately, without this, encoding 2-1 fails. diff --git a/tests/safe.test b/tests/safe.test index e7e427b..2ea32f5 100644 --- a/tests/safe.test +++ b/tests/safe.test @@ -1269,7 +1269,7 @@ test safe-11.7 {testing safe encoding} -setup { interp eval $i encoding convertfrom } -returnCodes error -cleanup { safe::interpDelete $i -} -result {wrong # args: should be "encoding convertfrom ?encoding? data ?-stoponerror|-nothrow?"} +} -result {wrong # args: should be "encoding convertfrom ?-stoponerror|-nothrow? ?encoding? data"} test safe-11.7.1 {testing safe encoding} -setup { set i [safe::interpCreate] } -body { @@ -1278,7 +1278,7 @@ test safe-11.7.1 {testing safe encoding} -setup { } -returnCodes ok -match glob -cleanup { unset -nocomplain m o safe::interpDelete $i -} -result {wrong # args: should be "encoding convertfrom ?encoding? data ?-stoponerror|-nothrow?" +} -result {wrong # args: should be "encoding convertfrom ?-stoponerror|-nothrow? ?encoding? data" while executing "encoding convertfrom" invoked from within @@ -1291,7 +1291,7 @@ test safe-11.8 {testing safe encoding} -setup { interp eval $i encoding convertto } -returnCodes error -cleanup { safe::interpDelete $i -} -result {wrong # args: should be "encoding convertto ?encoding? data ?-stoponerror|-nothrow?"} +} -result {wrong # args: should be "encoding convertto ?-stoponerror|-nothrow? ?encoding? data"} test safe-11.8.1 {testing safe encoding} -setup { set i [safe::interpCreate] } -body { @@ -1300,7 +1300,7 @@ test safe-11.8.1 {testing safe encoding} -setup { } -returnCodes ok -match glob -cleanup { unset -nocomplain m o safe::interpDelete $i -} -result {wrong # args: should be "encoding convertto ?encoding? data ?-stoponerror|-nothrow?" +} -result {wrong # args: should be "encoding convertto ?-stoponerror|-nothrow? ?encoding? data" while executing "encoding convertto" invoked from within |