From 294e93c3a838f9f3feca559666876356bff3c620 Mon Sep 17 00:00:00 2001 From: David Lichteblau Date: Mon, 19 May 2008 23:58:58 +0200 Subject: [PATCH] moved find-output-encoding to closure-common, thanks to Nathan Bird --- package.lisp | 1 + ystream.lisp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/package.lisp b/package.lisp index a12980e..ec24b42 100644 --- a/package.lisp +++ b/package.lisp @@ -65,6 +65,7 @@ ;; ystream.lisp #:ystream #:ystream-encoding + #:find-output-encoding #:close-ystream #:ystream-write-rune #:ystream-write-rod diff --git a/ystream.lisp b/ystream.lisp index eafabdc..6ad3e0b 100644 --- a/ystream.lisp +++ b/ystream.lisp @@ -25,6 +25,27 @@ (defmacro until (test &body body) `(do () (,test) ,@body)) +(defun find-output-encoding (name) + (when (stringp name) + (setf name (find-symbol (string-upcase name) :keyword))) + (cond + ((null name) + (warn "Unknown encoding ~A, falling back to UTF-8" name) + :utf-8) + ((find name '(:utf-8 :utf_8 :utf8)) + :utf-8) + #-rune-is-character + (t + (warn "Unknown encoding ~A, falling back to UTF-8" name) + :utf-8) + #+rune-is-character + (t + (handler-case + (babel-encodings:get-character-encoding name) + (error () + (warn "Unknown encoding ~A, falling back to UTF-8" name) + :utf-8))))) + ;;; ystream ;;; +- encoding-ystream ;;; | +- octet-vector-ystream