Read a file character by character/UTF8: Difference between revisions
Content deleted Content added
→{{header|Tcl}}: Added zkl |
→{{header|zkl}}: Added example |
||
Line 667: | Line 667: | ||
ValueError : Invalid UTF-8 string |
ValueError : Invalid UTF-8 string |
||
</pre> |
</pre> |
||
If you wish to push a UTF-8 stream through one or more functions, you can a similar state machine (which, unfortunately, has a slightly different syntax): |
|||
<lang zkl>fcn readUTF8(chars){ // transform UTF-8 character stream |
|||
s:=vm.arglist.concat(); |
|||
try{ s.len(8); return(s) } |
|||
catch{ if(s.len()>6) throw(__exception) } // 6 bytes max for UTF-8 |
|||
return(Void.Read,1,True,True); // read 1 char, complain on EoS, retry w/char appended to parameters |
|||
}</lang> |
|||
<lang zkl>w.pump(3,List,readUTF8,"print")</lang> |
|||
{{out}}<pre>-->€123</pre> |
|||
and returns a list of UTF characters. |
|||
{{omit from|AWK}} |
{{omit from|AWK}} |