diff --git a/babel-input-stream.lisp b/babel-input-stream.lisp
deleted file mode 100644
index 9d76686..0000000
--- a/babel-input-stream.lisp
+++ /dev/null
@@ -1,65 +0,0 @@
-;;
-;; babel-stream - charset encoding/decoding layer for cl-stream
-;;
-;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
-
-(in-package :babel-stream)
-
-(defclass babel-input-stream (babel-stream input-stream)
- ((bytes :initform (make-array '(8) :element-type '(unsigned-byte 8))
- :reader stream-bytes
- :type (array (unsigned-byte 8)))
- (bytes-length :initform 0
- :accessor stream-bytes-length
- :type fixnum+)))
-
-(defmethod stream-read ((stream babel-input-stream))
- (let* ((underlying-stream (stream-underlying-stream stream))
- (bytes (stream-bytes stream))
- (encoding (stream-external-format stream))
- (mapping (babel::lookup-mapping babel::*string-vector-mappings*
- encoding)))
- (loop
- (multiple-value-bind (element state) (stream-read
- underlying-stream)
- (case state
- ((nil)
- (setf (aref bytes (stream-bytes-length stream)) element)
- (incf (stream-bytes-length stream))
- (handler-case
- (let ((string (make-string 1)))
- (when (= 1 (funcall (the function (babel::decoder mapping))
- bytes 0 (stream-bytes-length stream)
- string 0))
- (setf (stream-bytes-length stream) 0)
- (return (values (char string 0) nil))))
- (babel-encodings:end-of-input-in-character ())))
- ((:eof)
- (return (values nil :eof)))
- ((:non-blocking)
- (return (values nil :non-blocking)))
- (otherwise
- (error 'stream-input-error :stream stream)))))))
-
-(defun babel-input-stream (stream &optional (external-format :utf-8))
- (make-instance 'babel-input-stream
- :external-format external-format
- :stream stream))
-
-#+test
-(let ((s (make-instance 'babel-input-stream
- :stream (fd-stream:fd-input-stream 0))))
- (read-line s))
diff --git a/babel-io-stream.lisp b/babel-io-stream.lisp
deleted file mode 100644
index f2c9778..0000000
--- a/babel-io-stream.lisp
+++ /dev/null
@@ -1,27 +0,0 @@
-;;
-;; babel-stream - charset encoding/decoding layer for cl-stream
-;;
-;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
-
-(in-package :babel-stream)
-
-(defclass babel-io-stream (babel-input-stream babel-output-stream)
- ())
-
-(defun babel-io-stream (stream &optional (external-format :utf-8))
- (make-instance 'babel-io-stream
- :external-format external-format
- :stream stream))
diff --git a/babel-output-stream.lisp b/babel-output-stream.lisp
deleted file mode 100644
index 88c8be3..0000000
--- a/babel-output-stream.lisp
+++ /dev/null
@@ -1,62 +0,0 @@
-;;
-;; babel-stream - charset encoding/decoding layer for cl-stream
-;;
-;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
-
-(in-package :babel-stream)
-
-(defclass babel-output-stream (babel-stream output-stream)
- ())
-
-(defmethod stream-clear-output ((stream babel-output-stream))
- (stream-clear-output (stream-underlying-stream stream)))
-
-(defmethod stream-finish-output ((stream babel-output-stream))
- (stream-finish-output (stream-underlying-stream stream)))
-
-(defmethod stream-flush-output ((stream babel-output-stream))
- (stream-flush-output (stream-underlying-stream stream)))
-
-(defmethod stream-open-p ((stream babel-output-stream))
- (stream-open-p (stream-underlying-stream stream)))
-
-(defmethod stream-write ((stream babel-output-stream) (element fixnum))
- (assert (typep element '(unsigned-byte 8)))
- (write (stream-underlying-stream stream) element))
-
-(defmethod stream-write ((stream babel-output-stream)
- (element character))
- (let* ((encoding (stream-external-format stream))
- (mapping (babel::lookup-mapping babel::*string-vector-mappings*
- encoding))
- (string (make-string 1 :initial-element element))
- (bytes (make-array '(8) :element-type '(unsigned-byte 8)))
- (length (funcall (the function (babel::encoder mapping))
- string 0 1 bytes 0)))
- (write-sequence bytes
- :stream (stream-underlying-stream stream)
- :end length)))
-
-(defun babel-output-stream (stream &optional (external-format :utf-8))
- (make-instance 'babel-output-stream
- :external-format external-format
- :stream stream))
-
-#+test
-(let ((s (make-instance 'babel-output-stream
- :stream (fd-stream:fd-output-stream 1))))
- (write-sequence s "Hello, world ! ÉÀÖÛŸ")
- (flush s))
diff --git a/babel-stream.asd b/babel-stream.asd
deleted file mode 100644
index 3cd70c4..0000000
--- a/babel-stream.asd
+++ /dev/null
@@ -1,39 +0,0 @@
-;;
-;; babel-stream - charset encoding/decoding layer for cl-stream
-;;
-;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
-
-(in-package :common-lisp-user)
-
-(defpackage :babel-stream.system
- (:use :common-lisp :asdf))
-
-(in-package :babel-stream.system)
-
-(defsystem :babel-stream
- :name "babel-stream"
- :author "Thomas de Grivel <thoxdg@gmail.com>"
- :version "0.1"
- :description "Charset encoding/decoding layer for cl-stream"
- :depends-on ("babel"
- "cl-stream")
- :components
- ((:file "package")
- (:file "babel-input-stream" :depends-on ("babel-stream"))
- (:file "babel-io-stream" :depends-on ("babel-input-stream"
- "babel-output-stream"))
- (:file "babel-output-stream" :depends-on ("babel-stream"))
- (:file "babel-stream" :depends-on ("package"))))
diff --git a/babel-stream.lisp b/babel-stream.lisp
deleted file mode 100644
index df54125..0000000
--- a/babel-stream.lisp
+++ /dev/null
@@ -1,77 +0,0 @@
-;;
-;; babel-stream - charset encoding/decoding layer for cl-stream
-;;
-;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
-;;
-;; Permission to use, copy, modify, and distribute this software for any
-;; purpose with or without fee is hereby granted, provided that the above
-;; copyright notice and this permission notice appear in all copies.
-;;
-;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-;;
-
-(in-package :babel-stream)
-
-(defclass babel-stream (stream)
- ((underlying-stream :initarg :stream
- :accessor stream-underlying-stream
- :type stream)
- (external-format :initarg :external-format
- :initform :utf-8
- :accessor stream-external-format
- :type symbol)))
-
-(defmethod initialize-instance :after ((stream babel-stream)
- &rest initargs
- &key &allow-other-keys)
- (declare (ignore initargs))
- (assert (equal '(unsigned-byte 8)
- (stream-element-type (stream-underlying-stream stream)))))
-
-(defmethod stream-close ((stream babel-stream))
- (stream-close (stream-underlying-stream stream)))
-
-(defmethod stream-element-type ((stream babel-stream))
- 'character)
-
-(defclass babel-input-stream (babel-stream input-stream)
- ((bytes :initform (make-array '(8) :element-type '(unsigned-byte 8))
- :reader stream-bytes
- :type (array (unsigned-byte 8)))
- (bytes-length :initform 0
- :accessor stream-bytes-length
- :type fixnum+)))
-
-(defmethod stream-read ((stream babel-input-stream))
- (let* ((underlying-stream (stream-underlying-stream stream))
- (bytes (stream-bytes stream))
- (encoding (stream-external-format stream))
- (mapping (babel::lookup-mapping babel::*string-vector-mappings*
- encoding)))
- (loop
- (multiple-value-bind (element state) (stream-read
- underlying-stream)
- (case state
- ((nil)
- (setf (aref bytes (stream-bytes-length stream)) element)
- (incf (stream-bytes-length stream))
- (handler-case
- (let ((string (make-string 1)))
- (when (= 1 (funcall (the function (babel::decoder mapping))
- bytes 0 (stream-bytes-length stream)
- string 0))
- (setf (stream-bytes-length stream) 0)
- (return (values (char string 0) nil))))
- (babel-encodings:end-of-input-in-character ())))
- ((:eof)
- (return (values nil :eof)))
- ((:non-blocking)
- (return (values nil :non-blocking)))
- (otherwise
- (error 'stream-input-error :stream stream)))))))
diff --git a/package.lisp b/package.lisp
index 588acb9..b819837 100644
--- a/package.lisp
+++ b/package.lisp
@@ -1,5 +1,5 @@
;;
-;; babel-stream - charset encoding/decoding layer for cl-stream
+;; utf8-stream - charset encoding/decoding layer for cl-stream
;;
;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
;;
@@ -18,15 +18,13 @@
(in-package :common-lisp-user)
-(defpackage :babel-stream
+(defpackage :utf8-stream
(:use
:common-lisp
:cl-stream)
#.(cl-stream:shadowing-import-from)
- (:shadow
- #:stream-external-format)
(:export
- #:babel-input-stream
- #:babel-io-stream
- #:babel-output-stream
- #:babel-stream))
+ #:utf8-input-stream
+ #:utf8-io-stream
+ #:utf8-output-stream
+ #:utf8-stream))
diff --git a/utf8-input-stream.lisp b/utf8-input-stream.lisp
new file mode 100644
index 0000000..2e127c3
--- /dev/null
+++ b/utf8-input-stream.lisp
@@ -0,0 +1,59 @@
+;;
+;; utf8-stream - charset encoding/decoding layer for cl-stream
+;;
+;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
+;;
+;; Permission to use, copy, modify, and distribute this software for any
+;; purpose with or without fee is hereby granted, provided that the above
+;; copyright notice and this permission notice appear in all copies.
+;;
+;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+;;
+
+(in-package :utf8-stream)
+
+(defclass utf8-input-stream (utf8-stream buffered-input-stream)
+ ()
+ (:default-initargs :input-buffer-size 8))
+
+(defun encode (stream character)
+ (let* ((mapping (mapping stream))
+ (string (make-string 1 :initial-element character))
+ (bytes (stream-input-buffer stream))
+ (length (funcall (the function (babel::encoder mapping))
+ string 0 1 bytes 0)))
+ (setf (stream-input-index stream) 0
+ (stream-input-length stream) length))
+ nil)
+
+(defmethod stream-fill-input-buffer ((stream utf8-input-stream))
+ (multiple-value-bind (element state)
+ (stream-read (stream-underlying-stream stream))
+ (case state
+ ((nil)
+ (encode stream element)
+ nil)
+ ((:eof) :eof)
+ ((:non-blocking) :non-blocking)
+ (otherwise
+ (error 'stream-input-error :stream stream)))))
+
+(defun utf8-input-stream (stream &optional (format :utf-8))
+ (make-instance 'utf8-input-stream
+ :format format
+ :stream stream))
+
+#+test
+(let ((s (make-instance 'utf8-input-stream
+ :stream (fd-stream:fd-input-stream 0))))
+ (read-line s))
+
+(defmethod stream-read-line ((stream utf8-stream))
+ (stream-read-until (babel-stream:babel-input-stream stream)
+ #\Newline))
diff --git a/utf8-io-stream.lisp b/utf8-io-stream.lisp
new file mode 100644
index 0000000..e0d6b07
--- /dev/null
+++ b/utf8-io-stream.lisp
@@ -0,0 +1,27 @@
+;;
+;; utf8-stream - charset encoding/decoding layer for cl-stream
+;;
+;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
+;;
+;; Permission to use, copy, modify, and distribute this software for any
+;; purpose with or without fee is hereby granted, provided that the above
+;; copyright notice and this permission notice appear in all copies.
+;;
+;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+;;
+
+(in-package :utf8-stream)
+
+(defclass utf8-io-stream (utf8-input-stream utf8-output-stream)
+ ())
+
+(defun utf8-io-stream (stream &optional (format :utf-8))
+ (make-instance 'utf8-io-stream
+ :external-format format
+ :stream stream))
diff --git a/utf8-output-stream.lisp b/utf8-output-stream.lisp
new file mode 100644
index 0000000..a1679ec
--- /dev/null
+++ b/utf8-output-stream.lisp
@@ -0,0 +1,77 @@
+;;
+;; utf8-stream - charset encoding/decoding layer for cl-stream
+;;
+;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
+;;
+;; Permission to use, copy, modify, and distribute this software for any
+;; purpose with or without fee is hereby granted, provided that the above
+;; copyright notice and this permission notice appear in all copies.
+;;
+;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+;;
+
+(in-package :utf8-stream)
+
+(defclass utf8-output-stream (utf8-stream output-stream)
+ ((bytes :initform (make-array '(8) :element-type '(unsigned-byte 8))
+ :reader stream-bytes
+ :type (array (unsigned-byte 8)))
+ (bytes-length :initform 0
+ :accessor stream-bytes-length
+ :type fixnum+)))
+
+(defmethod stream-clear-output ((stream utf8-output-stream))
+ (stream-clear-output (stream-underlying-stream stream)))
+
+(defmethod stream-finish-output ((stream utf8-output-stream))
+ (stream-finish-output (stream-underlying-stream stream)))
+
+(defmethod stream-flush ((stream utf8-output-stream))
+ (stream-flush (stream-underlying-stream stream)))
+
+(defmethod stream-flush-output ((stream utf8-output-stream))
+ (stream-flush-output (stream-underlying-stream stream)))
+
+(defmethod stream-open-p ((stream utf8-output-stream))
+ (stream-open-p (stream-underlying-stream stream)))
+
+(defmethod stream-write ((stream utf8-output-stream)
+ (element character))
+ (stream-write (stream-underlying-stream stream) element))
+
+(defun decode (stream bytes)
+ (let* ((mapping (mapping stream))
+ (string (make-string 1)))
+ (when (= 1 (funcall (the function (babel::decoder mapping))
+ bytes 0 (stream-bytes-length stream)
+ string 0))
+ (setf (stream-bytes-length stream) 0)
+ (stream-write (stream-underlying-stream stream)
+ (char string 0)))))
+
+(defmethod stream-write ((stream utf8-output-stream)
+ (element integer))
+ (assert (typep element '(unsigned-byte 8)))
+ (let ((bytes (stream-bytes stream)))
+ (setf (aref bytes (stream-bytes-length stream)) element)
+ (incf (stream-bytes-length stream))
+ (handler-case
+ (decode stream bytes)
+ (babel-encodings:end-of-input-in-character ()))))
+
+(defun utf8-output-stream (stream &optional (format :utf-8))
+ (make-instance 'utf8-output-stream
+ :format format
+ :stream stream))
+
+#+test
+(let ((s (make-instance 'utf8-output-stream
+ :stream (fd-stream:fd-output-stream 1))))
+ (write-sequence s "Hello, world ! ÉÀÖÛŸ")
+ (flush s))
diff --git a/utf8-stream.asd b/utf8-stream.asd
new file mode 100644
index 0000000..e2c10c8
--- /dev/null
+++ b/utf8-stream.asd
@@ -0,0 +1,39 @@
+;;
+;; utf8-stream - UTF-8 for cl-stream using babel
+;;
+;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
+;;
+;; Permission to use, copy, modify, and distribute this software for any
+;; purpose with or without fee is hereby granted, provided that the above
+;; copyright notice and this permission notice appear in all copies.
+;;
+;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+;;
+
+(in-package :common-lisp-user)
+
+(defpackage :utf8-stream.system
+ (:use :common-lisp :asdf))
+
+(in-package :utf8-stream.system)
+
+(defsystem :utf8-stream
+ :name "utf8-stream"
+ :author "Thomas de Grivel <thoxdg@gmail.com>"
+ :version "0.1"
+ :description "UTF-8 for cl-stream using babel"
+ :depends-on ("babel"
+ "cl-stream")
+ :components
+ ((:file "package")
+ (:file "utf8-input-stream" :depends-on ("utf8-stream"))
+ (:file "utf8-io-stream" :depends-on ("utf8-input-stream"
+ "utf8-output-stream"))
+ (:file "utf8-output-stream" :depends-on ("utf8-stream"))
+ (:file "utf8-stream" :depends-on ("package"))))
diff --git a/utf8-stream.lisp b/utf8-stream.lisp
new file mode 100644
index 0000000..196157e
--- /dev/null
+++ b/utf8-stream.lisp
@@ -0,0 +1,43 @@
+;;
+;; utf8-stream - charset encoding/decoding layer for cl-stream
+;;
+;; Copyright 2017,2018 Thomas de Grivel <thoxdg@gmail.com>
+;;
+;; Permission to use, copy, modify, and distribute this software for any
+;; purpose with or without fee is hereby granted, provided that the above
+;; copyright notice and this permission notice appear in all copies.
+;;
+;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+;;
+
+(in-package :utf8-stream)
+
+(defclass utf8-stream (ub8-stream)
+ ((underlying-stream :initarg :stream
+ :accessor stream-underlying-stream
+ :type character-stream)
+ (encoding :initarg :format
+ :initform :utf-8
+ :accessor stream-encoding
+ :type symbol)
+ (mapping)))
+
+(defmethod stream-close ((stream utf8-stream))
+ (stream-close (stream-underlying-stream stream)))
+
+(defmethod stream-open-p ((stream utf8-stream))
+ (stream-open-p (stream-underlying-stream stream)))
+
+(defun mapping (stream)
+ (if (slot-boundp stream 'mapping)
+ (slot-value stream 'mapping)
+ (setf (slot-value stream 'mapping)
+ (let ((encoding (stream-encoding stream)))
+ (babel::lookup-mapping babel::*string-vector-mappings*
+ encoding)))))