Skip to content
Browse files

fix file contents for non-ascii characters

  • Loading branch information...
1 parent 38e9eef commit 2409b384ce470503735015727b3246d11f0e3804 @hanshuebner committed Aug 2, 2011
Showing with 12 additions and 6 deletions.
  1. +12 −6 src/utils/utils.lisp
View
18 src/utils/utils.lisp
@@ -566,12 +566,18 @@ it is assumed that the string specifies the MIME type."
nconc (list key (eval value))))
#-allegro
-(defun file-contents (pathname &key (element-type '(unsigned-byte 8)))
- (with-open-file (s pathname :element-type element-type)
- (let ((result
- (make-array (file-length s) :element-type element-type)))
- (read-sequence result s)
- result)))
+(defun file-contents (pathname &key (element-type '(unsigned-byte 8)) (external-format :utf-8))
+ (cond
+ ((equal element-type '(unsigned-byte 8))
+ (with-open-file (s pathname :element-type element-type)
+ (let ((result
+ (make-array (file-length s) :element-type element-type)))
+ (read-sequence result s)
+ result)))
+ ((equal element-type 'character)
+ (alexandria:read-file-into-string pathname :external-format external-format))
+ (t
+ (error "unsupported element type ~A for file-contents" element-type))))
(defun class-subclasses (class)
"Return a list of the names of all subclasses of a given class."

0 comments on commit 2409b38

Please sign in to comment.
Something went wrong with that request. Please try again.