Delete mmgeneric.el.
[elisp/flim.git] / ew-unit.el
1 (require 'closure)
2 (require 'ew-line)
3 (require 'ew-quote)
4 (require 'ew-bq)
5
6 (provide 'ew-unit)
7
8 (defun ew-b-check (encoding encoded-text) (string-match ew-b-regexp encoded-text))
9 (defun ew-q-check (encoding encoded-text) (string-match ew-q-regexp encoded-text))
10
11 (defsubst ew-eword-p (str)
12   (and (string-match ew-anchored-encoded-word-regexp str)
13        (or ew-permit-null-encoded-text
14            (< (match-beginning 3) (match-end 3)))))
15
16 (defun ew-decode-eword (str)
17   (if (string-match ew-anchored-encoded-word-regexp str)
18       (let ((charset (match-string 1 str))
19             (encoding (match-string 2 str))
20             (encoded-text (match-string 3 str))
21             bdec cdec
22             bcheck
23             tmp)
24         (if (or ew-permit-null-encoded-text
25                 (< 0 (length encoded-text)))
26             (if (and (setq bdec (ew-byte-decoder encoding))
27                      (setq cdec (ew-char-decoder charset)))
28                 (if (or (null (setq bcheck (ew-byte-checker encoding)))
29                         (funcall bcheck encoding encoded-text))
30                     (ew-quote (closure-call cdec (funcall bdec encoded-text)))
31                   (ew-quote str))
32               (ew-quote-eword charset encoding encoded-text))
33           (ew-quote str)))
34     (ew-quote str)))
35
36 (defun ew-byte-decoder (encoding)
37   (cdr (assoc (upcase encoding) ew-byte-decoder-alist)))
38
39 (defun ew-byte-checker (encoding)
40   (cdr (assoc (upcase encoding) ew-byte-checker-alist)))
41
42 (defun ew-char-decoder (charset)
43   (let ((sym (intern (downcase charset))))
44     (when (mime-charset-to-coding-system sym 'LF)
45       (closure-make
46        (lambda (str) (decode-mime-charset-string str sym 'LF))
47        sym))))