Read a file character by character/UTF8: Difference between revisions
Read a file character by character/UTF8 (view source)
Revision as of 01:41, 4 August 2018
, 5 years agoAdded eof handling
m (Added eof handling) |
|||
Line 635:
-- headb = first byte of utf-8 character:
headb = getc(fn)
if headb=-1 then return -1 end if
res = ""&headb
Line 707 ⟶ 708:
close(fn)
fn = open("test.txt","r")
for i=1 to
object res = get_one_utf8_char(fn)
if string(res) then
Line 717 ⟶ 718:
printf(1,"char %d is %d bytes\n",{i,length(res)})
end if
elsif res=-1 then
printf(1,"char %d - EOF\n",i)
exit
else
printf(1,"char %d - INVALID_UTF8\n",i)
exit
end if
Line 730 ⟶ 734:
char 3 is 3 bytes
char 4 is 3 bytes
char 5 - EOF
</pre>
|