Function: nxml-detect-coding-system
nxml-detect-coding-system is a byte-compiled function defined in
nxml-enc.el.gz.
Signature
(nxml-detect-coding-system LIMIT)
Source Code
;; Defined in /usr/src/emacs/lisp/nxml/nxml-enc.el.gz
(&optional limit)) ; autoloaded
(defun nxml-detect-coding-system (limit)
(if (< limit (+ (point) 2))
(if (eq (char-after) 0) 'no-conversion 'utf-8)
(let ((first-two-chars (list (char-after)
(char-after (1+ (point))))))
(cond ((equal first-two-chars '(#xFE #xFF))
(and (coding-system-p 'utf-16-be) 'utf-16-be))
((equal first-two-chars '(#xFF #xFE))
(and (coding-system-p 'utf-16-le) 'utf-16-le))
((memq 0 first-two-chars)
;; Certainly not well-formed XML;
;; perhaps UTF-16 without BOM.
;; In any case, we can't handle it.
;; no-conversion gives the user a chance to fix it.
'no-conversion)
;; There are other things we might try here in the future
;; eg UTF-8 BOM, UTF-16 with no BOM
;; translate to EBCDIC
(t
(let ((enc-pos (xmltok-get-declared-encoding-position limit)))
(cond ((consp enc-pos)
(or (nxml-mime-charset-coding-system
(buffer-substring-no-properties (car enc-pos)
(cdr enc-pos)))
;; We have an encoding whose name we don't recognize.
;; What to do?
;; raw-text seems the best bet: since we got
;; the XML decl it must be a superset of ASCII,
;; so we don't need to go to no-conversion
'raw-text))
(enc-pos 'utf-8)
;; invalid XML declaration
(t nil))))))))