X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=ew-unit.el;h=e7808539c401c488fd5d8500ac4d971128d68e51;hb=99c158b34f006c5840785347fc7e711a6b246c0c;hp=f706daff3fc34059fca0d7f72c4a69b62c3a30e4;hpb=12da2147d1b399e6771196980b4ff83f5c6c7ddc;p=elisp%2Fflim.git diff --git a/ew-unit.el b/ew-unit.el index f706daf..e780853 100644 --- a/ew-unit.el +++ b/ew-unit.el @@ -1,41 +1,14 @@ (require 'closure) (require 'ew-line) (require 'ew-quote) -(require 'mel) +(require 'ew-bq) (provide 'ew-unit) -(defconst ew-anchored-encoded-word-regexp - (concat "\\`" ew-encoded-word-regexp "\\'")) - -(defconst ew-b-regexp - (concat "\\`\\(" - "[A-Za-z0-9+/]" - "[A-Za-z0-9+/]" - "[A-Za-z0-9+/]" - "[A-Za-z0-9+/]" - "\\)*" - "[A-Za-z0-9+/]" - "[A-Za-z0-9+/]" - "\\(==\\|" - "[A-Za-z0-9+/]" - "[A-Za-z0-9+/=]" - "\\)\\'")) - -(defconst ew-q-regexp "\\`\\([^=?]\\|=[0-9A-Fa-f][0-9A-Fa-f]\\)*\\'") - -(defconst ew-byte-decoder-alist - '(("B" . ew-b-decode) - ("Q" . ew-q-decode))) - -(defconst ew-byte-checker-alist - '(("B" . ew-b-check) - ("Q" . ew-q-check))) - (defun ew-b-check (encoding encoded-text) (string-match ew-b-regexp encoded-text)) (defun ew-q-check (encoding encoded-text) (string-match ew-q-regexp encoded-text)) -(defun ew-eword-p (str) +(defsubst ew-eword-p (str) (let ((len (length str))) (and (<= 3 len) @@ -44,7 +17,7 @@ (eq (aref str (- len 2)) ??) (eq (aref str (1- len)) ?=)))) -(defun ew-decode-eword (str &optional eword-filter1 eword-filter2) +(defun ew-decode-eword (str) (if (string-match ew-anchored-encoded-word-regexp str) (let ((charset (match-string 1 str)) (encoding (match-string 2 str)) @@ -52,18 +25,16 @@ bdec cdec bcheck tmp) - (if (and (setq bdec (ew-byte-decoder encoding)) - (setq cdec (ew-char-decoder charset))) - (if (or (null (setq bcheck (ew-byte-checker encoding))) - (funcall bcheck encoding encoded-text)) - (progn - (setq tmp (closure-call cdec (funcall bdec encoded-text))) - (when eword-filter1 (setq tmp (closure-call eword-filter1 tmp))) - (setq tmp (ew-quote tmp)) - (when eword-filter2 (setq tmp (closure-call eword-filter2 tmp))) - tmp) - (ew-quote str)) - (ew-quote-eword charset encoding encoded-text))) + (if (or ew-permit-null-encoded-text + (< 0 (length encoded-text))) + (if (and (setq bdec (ew-byte-decoder encoding)) + (setq cdec (ew-char-decoder charset))) + (if (or (null (setq bcheck (ew-byte-checker encoding))) + (funcall bcheck encoding encoded-text)) + (ew-quote (closure-call cdec (funcall bdec encoded-text))) + (ew-quote str)) + (ew-quote-eword charset encoding encoded-text)) + (ew-quote str))) (ew-quote str))) (defun ew-byte-decoder (encoding) @@ -72,9 +43,6 @@ (defun ew-byte-checker (encoding) (cdr (assoc (upcase encoding) ew-byte-checker-alist))) -(defalias 'ew-b-decode 'base64-decode-string) -(defalias 'ew-q-decode 'q-encoding-decode-string) - (defun ew-char-decoder (charset) (let ((sym (intern (downcase charset)))) (when (mime-charset-to-coding-system sym 'LF)