Author: Jan Nijtmans <[email protected]> State: Draft Type: Project Created: 30-Jul-2021 Post-History: Keywords: Tcl Tcl-Version: 8.7
This TIP proposes to add a "-failindex" option to encoding convertto/convertfrom.
The implementation depends on , the only change is that - when
this option is provided - the error-location can be found in a variable
in addition to being the last index of the
The following proposal was initiated by a post by Andreas Leitgeb 2021-05-12 on the core list:
The command is extended by a -failindex option:
encoding convertfrom ?-failindex posvar? ?encoding? data encoding convertto ?-failindex posvar? ?encoding? data
The distinct behaviour is as follows:
- No conversion error
- Option -failindex not given: Converted data returned as command result.
- Option -failindex given: Additionaly, the value -1 is written to the given variable in the caller scope.
- Conversion error present
- Option -failindex not given: In TCL 8.7, the data is converted with replacement characters as currently done. With TCL 9.x, an error message is thrown by the command (Error Code: EILSEQ).
- Option -failindex given: The converted data until the failed index is returned as command result. The position of the conversion error in the source string is written to the specified variable in the caller scope.
This specification is inspired by the already present option -failindex of the string is command.
Jan mentioned, that the implementation is not trivial, as the encoding ensemble is a partially compiled command.
Nevertheless, an implementation is tried in the branch
Note: there was a side discussion within the thread if an incomplete multi-byte sequence is an error or not. Unfortunately, the required detail about the reporting method of an incomplete multi-byte sequence was not solved. So, it is considered as an error within this alternate solution.
This document has been placed in the public domain.