Skip to content
Snippets Groups Projects
Commit 678ea981 authored by Francois-Rene Rideau's avatar Francois-Rene Rideau
Browse files

Rename detect-encoding to detect-file-encoding to not clash with asdf.

Add more documentation. Move a variable around.
parent db760ff8
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,13 @@ ASDF-ENCODINGS
This library allows you to use ASDF with Lisp source files
that use an encoding different from either ASCII or UTF-8.
It depends on ASDF 2.21 or later (actually 2.20.7 or later).
It depends on ASDF 2.21 or later (actually 2.20.18 or later).
TODO:
(1) actually support more implementations.
(2) Add a test suite.
(3) Test it.
(4) Add more corner cases.
==== Exported Functionality ====
......@@ -30,3 +31,24 @@ function ENCODING-EXTERNAL-FORMAT (ENCODING &KEY (ON-ERROR *ON-UNSUPPORTED-ENCOD
the current implementation's CL:OPEN, CL:LOAD or CL:COMPILE-FILE functions.
If the encoding is not supported on this implementation, the ON-ERROR
argument, which is one of :ERROR, :WARN, NIL, specifies what to do.
variable *ON-UNSUPPORTED-ENCODING*
One of :error, :warn or nil,
specifies what to do when passed an unsupported encoding.
Defaults to :error.
function DETECT-FILE-ENCODING (PATHNAME)
This function takes a pathname designator,
and returns a portable encoding as detected by the file contents,
either an emacs-style -*- coding: foo -*- declaration,
or something deduced from the octet patterns in the file.
function NORMALIZE-ENCODING (ENCODING)
Given a portable encoding keyword, returns the normalized keyword
describing that encoding on the current implementations, if any,
or NIL if the encoding is not present on the implementation
(or not recognized by asdf-encodings).
function FIND-IMPLEMENTATION-ENCODING (ENCODING)
Given a normalized encoding keyword, returns
an external-format suitable for use on the current implementation, if any.
......@@ -2,6 +2,9 @@
(in-package :asdf-encodings)
(defvar *on-unsupported-encoding* :error
"One of :error, :warn or nil, specifies what to do when passed an unsupported encoding.")
(defun encoding-external-format (encoding &key (on-error *on-unsupported-encoding*))
(or (and (eq encoding :default) :default)
(find-implementation-encoding (or (normalize-encoding encoding) encoding))
......@@ -13,5 +16,5 @@
(defun register-asdf-encodings ()
(setf asdf:*encoding-external-format-hook* 'encoding-external-format
asdf:*encoding-detection-hook* 'detect-encoding)
asdf:*encoding-detection-hook* 'detect-file-encoding)
(values))
......@@ -153,7 +153,7 @@
((cdr (assoc "encoding" options :test 'equalp)))
((cdr (assoc "coding" options :test 'equalp)))))))
;;; Examine the 'file to determine the encoding.
;;; Examine the file to determine the encoding.
;;; In some cases the encoding can be determined
;;; from the coding of the file itself,
;;; otherwise it may be specified in a file options line
......@@ -162,7 +162,7 @@
;;; but is valid UTF-8 using then UTF-8 specific characters
;;; then :utf-8 is returned, otherwise :latin1 is returned.
(defun detect-encoding (file)
(defun detect-file-encoding (file)
(let ((initial-encoding nil)
(declared-encoding nil))
(with-open-file (s file :element-type '(unsigned-byte 8)
......
......@@ -4,9 +4,6 @@
(in-package :asdf-encodings)
(defvar *on-unsupported-encoding* :error
"One of :error, :warn or nil, specifies what to do when passed an unsupported encoding.")
(defparameter *encodings*
;; Define valid names for an encoding.
;; We prefer the main name in Wikipedia,
......
......@@ -6,6 +6,7 @@
(:use :cl)
(:export
#:encoding-external-format
#:*on-unsupported-encoding*
#:detect-file-encoding
#:normalize-encoding
#:find-implementation-encoding
#:*on-unsupported-encoding*))
#:find-implementation-encoding))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment