Read a file character by character/UTF8: Difference between revisions

Content added Content deleted
m (→‎{{header|Python}}: Fixed language in template)
(→‎{{header|Common Lisp}}: Add Déjà Vu example)
Line 43:
while c
do (format t "~a" c)))</lang>
 
=={{header|Déjà Vu}}==
 
<lang dejavu>#helper function that deals with non-ASCII code points
local (read-utf8-char) file tmp:
!read-byte file
if = :eof dup:
drop
raise :unicode-error
resize-blob tmp ++ dup len tmp
set-to tmp
try:
return !decode!utf-8 tmp
catch unicode-error:
if < 3 len tmp:
raise :unicode-error
(read-utf8-char) file tmp
 
#reader function
read-utf8-char file:
!read-byte file
if = :eof dup:
return
local :tmp make-blob 1
set-to tmp 0
try:
return !decode!utf-8 tmp
catch unicode-error:
(read-utf8-char) file tmp
 
#if the module is used as a script, read from the file "input.txt",
#showing each code point separately
if = (name) :(main):
local :file !open :read "input.txt"
 
while true:
read-utf8-char file
if = :eof dup:
drop
!close file
return
!.</lang>
 
=={{header|Java}}==