Coverage report: /home/ellis/.stash/quicklisp/dists/ultralisp/software/cl-babel-babel-20240610131823/src/external-format.lisp
Kind | Covered | All | % |
expression | 0 | 57 | 0.0 |
branch | 0 | 2 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
3
;;; external-format.lisp --- External format classes and functions.
5
;;; Copyright (C) 2007, Luis Oliveira <loliveira@common-lisp.net>
7
;;; Permission is hereby granted, free of charge, to any person
8
;;; obtaining a copy of this software and associated documentation
9
;;; files (the "Software"), to deal in the Software without
10
;;; restriction, including without limitation the rights to use, copy,
11
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
12
;;; of the Software, and to permit persons to whom the Software is
13
;;; furnished to do so, subject to the following conditions:
15
;;; The above copyright notice and this permission notice shall be
16
;;; included in all copies or substantial portions of the Software.
18
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
;;; DEALINGS IN THE SOFTWARE.
29
(defvar *default-eol-style*
32
"The end-of-line style used by external formats if none is
33
explicitly given. Depends on the OS the code is compiled on.")
36
"Possible end-of-line styles."
37
'(member :cr :lf :crlf))
39
(defclass external-format ()
40
((encoding :initarg :encoding :reader external-format-encoding
41
:type character-encoding)
42
(eol-style :initarg :eol-style :reader external-format-eol-style
43
:type eol-style :initform *default-eol-style*))
45
"An EXTERNAL-FORMAT consists in a combination of a Babel
46
CHARACTER-ENCODING and an end-of-line style."))
48
(defmethod print-object ((ef external-format) stream)
49
(print-unreadable-object (ef stream :type t :identity t)
50
(format stream "~A ~A"
51
(enc-name (external-format-encoding ef))
52
(external-format-eol-style ef))))
54
;;; This interface is still somewhat sketchy. The rest of Babel
55
;;; doesn't really understand external formats, for instance.
56
(defun make-external-format (encoding &key (eol-style *default-eol-style*))
57
(check-type eol-style eol-style)
58
(make-instance 'external-format
59
:encoding (get-character-encoding encoding)
60
:eol-style eol-style))
62
(defun ensure-external-format (thing)
64
(external-format thing)
65
(character-encoding (make-instance 'external-format :encoding thing))
66
(symbol (make-external-format thing))
67
(list (apply #'make-external-format thing))))
69
(defun external-format-equal (ef1 ef2)
70
(and (eq (external-format-encoding ef1) (external-format-encoding ef2))
71
(eq (external-format-eol-style ef1) (external-format-eol-style ef2))))
73
(declaim (inline lookup-mapping))
74
(defun lookup-mapping (ht encoding)
75
"HT should be an hashtable created by
76
INSTANTIATE-CONCRETE-MAPPINGS. ENCODING should be either an
77
external format, an encoding object or a keyword symbol
78
denoting a character encoding name or one of its aliases."
79
(or (etypecase encoding
81
(gethash encoding ht))
82
(babel-encodings::concrete-mapping
85
(gethash (enc-name encoding) ht))
87
(gethash (enc-name (external-format-encoding encoding)) ht)))
88
(error "~S is not a valid encoding designator" encoding)))