<i>Tcl interface to stop on encoding errors</i> status still Open with 4 other changes
by
.
D 2021-03-31T19:28:53.773
J icomment Dear\sJan,\r\n\r\nfirst\sof\sall,\sthank\syou\sfor\sthe\simplementation.\r\nThat\sis\sgreat.\r\n\r\nHere\sis\san\sexample\swith\stwo\stwo-byte\sutf-8\ssequences,\swhere\sthe\slast\sbyte\sis\snot\stransmitted:\r\n\r\n<verbatim>\r\n%\scatch\s{encoding\sconvertfrom\sutf-8\s[string\srange\s[encoding\sconvertto\sutf-8\sÄÖ]\s0\send-1]\s-stoponerror}\se\sd\r\n1\r\n%\sset\sd\r\n-code\s1\r\n-level\s0\r\n-errorstack\s{INNER\s{invokeStk1\s::tcl::encoding::convertfrom\sutf-8\sÃÃ\s-stoponerror}}\r\n-errorcode\sNONE\r\n-errorinfo\s{unexpected\sbyte\sat\sindex\s2:\s'Ã'\s(\\xC3)\r\n\s\s\s\swhile\sexecuting\r\n"encoding\sconvertfrom\sutf-8\s[string\srange\s[encoding\sconvertto\sutf-8\sÄÖ]\s0\send-1]\s-stoponerror"}\r\n-errorline\s1\r\n</verbatim>\r\n\r\nThis\sis\sgreat.\r\n\r\nI\swould\sprefer\sto\sreturn\sthe\sposition\sindex\s(2)\sas\spart\sof\sthe\serror\scode\sto\smake\sit\smachine\sparsable\swithout\sparsing\san\serror\smessage.\r\n<B>Example\serror\scode\sproposal</B>:\s<I>[list\sENCODING\sSTOPONERROR\s$errorPosition]</I>\r\n\r\nSo,\sthe\sfollowing\scode\swould\sbe\spossible\swithout\sstring\sparsing\son\sthe\serror\smessage:\r\n<verbatim>\r\nproc\sreceive\s{data}\s{\r\n\s\s\s\s#\sThis\sis\san\seventual\sremainder\sof\sthe\slast\srun\r\n\s\s\s\sglobal\sunprocessedData\r\n\s\s\s\s#\sAppend\scurrent\sdata\schunk\sto\slast\sremainder\r\n\s\s\s\sappend\sunprocessedData\s$data\r\n\s\s\s\stry\s{\r\n\s\s\s\s\s\s\s\sset\sdataUTF8\s[encoding\sconvertfrom\sutf-8\s$unprocessedData\s-stoponerror]\r\n\s\s\s\s\s\s\s\sset\sunprocessedData\s""\r\n\s\s\s\s}\strap\s{ENCODING\sSTOPONERROR}\s{errorMessage\serrorDict}\s{\r\n\s\s\s\s\s\s\s\s#\sPartial\sreceive\r\n\s\s\s\s\s\s\s\sset\serrorPosition\s[lindex\s[dict\sget\s$errorDict\s-errorcode]\s2]\r\n\s\s\s\s\s\s\s\sset\sdataUTF8\s[encoding\sconvertfrom\sutf-8\s[string\srange\s$unprocessedData\s0\s$errorPosition-1]\r\n\s\s\s\s\s\s\s\sset\sunprocessedData\s[string\srange\s$unprocessedData\s$errorPosition\send]\r\n\s\s\s\s}\son\serror\s{\r\n\s\s\s\s\s\s\s\s#\shandle\sother\serrors\r\n\s\s\s\s}\r\n\s\s\s\s#\sprocess\sdataUTF8\r\n}\r\n</verbatim>\r\n\r\nThe\sidea\sis\sa\sreceiving\sroutine\sreceiving\sbinary\sdata\swhich\sis\san\sutf-8\sstream,\sbut\sthe\sreceived\slimits\smay\snot\smatch.\r\nThe\sreceive\sprocedure\sis\scalled\sfor\seach\sreceived\sdata\spackage\sand\smanages\sthe\sassembly\sto\sa\svalid\sutf-8\sstring\swithout\sloosing\sor\schanging\sdata\s(both\spossible\swithout\sflag\s-stoponerror).\r\n\r\nThank\syou\sagain,\sI\sappreciate,\r\nHarald\r\n\r\n<B>Note\s1</B>:\sOther\sinterfaces\sare\spossible,\sspecially\sthat\sthe\salready\sencoded\ssubstring\suntil\sthe\serror\sposition\smay\sbe\savailable\ssomehow,\sso\sit\sis\snot\snecessary\sto\sdo\sa\s2nd\scall\sto\s"encoding\sconvertfrom".\r\nBut\sthat\sis\sa\sdetail.\r\n\r\n<B>Note\s2</B>:\sI\sdid\snot\scheck\sfor\sa\spossible\spossix\serror\scode\swhich\smight\sbe\smore\sappropriate.\r\nThe\serror\scode\slist\sis\sjust\san\sexample.\r\n\r\n<B>Note\s3</B>:\sI\sdon't\ssee\sthe\sneed\sto\sgive\sthe\serror\sbyte\svalue\sin\sthe\serror\smessage.\r\nFor\sme,\sthe\serror\sposition\sin\sthe\ssource\sstring\sin\sthe\serror\scode\swould\sjust\sdo\sthe\sjob.\r\nIMHO\sthis\sis\sfor\sautomatic\sprocessing,\snot\sfor\sradable\stext.\r\n\r\n<B>Note\s4</B>:\sAs\sreadable\serror\smessage,\sI\swould\sprefer\sto\smention\sthe\sused\sencoding\sto\shave\ssomething\slike:\r\n"data\snot\sin\s'utf-8'\sformat".\r\n\r\n<B>Note\s5</B>:\sFor\sthe\srecords:\sTest\ssuite\sresults\swith\sMS-VC2015\s32\sbit\son\sMS-Win10\s64bit\sGER,\scompared\sto\stcl8.7a3:\r\n\r\nStill\sfailing\stests:\ssocket-14.11.0
J login oehhar
J mimetype text/x-fossil-wiki
J username oehhar
K 535705ffffffffffffffffffffffffffffffffff
U oehhar
Z c15d3ca80d664c6c5c1044778bc8be9c