Commit edcdf463 authored by Antoine Martin's avatar Antoine Martin
Browse files

Try different encodings if UTF8 fails

parent 72af2c05
......@@ -65,13 +65,19 @@
asd-file)))))
(defun file-to-string (pathname)
(with-open-file (file pathname)
;; #### TODO: rather than replacing unsupported characters with a '?',
;; catch the error try again with :EXTERNAL-FORMAT :LATIN-1
;; (format of most of the offending READMEs)
;; If that fails too, then replace with '?' as a last resort move.
(alexandria:read-file-into-string
file
:external-format '(:utf-8 :replacement #\?))))
(handler-case
(alexandria:read-file-into-string
file
:external-format :utf-8)
(error ()
(handler-case
(alexandria:read-file-into-string
file
:external-format :latin-1)
(error ()
(alexandria:read-file-into-string
file
:external-format '(:utf-8 :replacement #\?))))))))
(defmacro read-write-file ((pathname content stream) &body body)
`(let ((,content (file-to-string ,pathname)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment