[Mew-dist 543] field canonicalization

Kazu Yamamoto 山本和彦 kazu at example.com
1997年 3月 1日 (土) 14:35:17 JST


'("xxx")' という文字列を扱うために、mew-header-delete-comment が送られ
て来ましたが、本質的に問題を解決してないように思います。たぶん、このパッ
チだと以下の文字列をうまく取り扱えないでしょう。

'"Winnie (The) Pooh" (loves "honey") @ (somewhere in) England'

というわけで、こんな関数にしました。1.54 にそのまま入れると、おかしく
なりますが、遊びたい人はどうぞ。

;; Get a canonical syntax
;;
;; '"Winnie (The) Pooh" (loves "honey") @ (somewhere in) England'
;; ->
;; '"Winnie (The) Pooh"@England'
;;
(defun mew-header-syntax (string)
  (let* ((i 0) (len (length string))
         (par-cnt 0) (ret-cnt 0)
         (ret (make-string len ?x))
         quoted c)
    (while (< i len)
      (setq c (aref string i))
      (cond
       ;; SPC - 32, quote - 34, ( - 40, ) - 41
       (quoted
        (if (eq c 34) (setq quoted nil))
        (aset ret ret-cnt c)
        (setq ret-cnt (1+ ret-cnt))
        )
       ((> par-cnt 0)
        (cond
         ((eq c 40) (setq par-cnt (1+ par-cnt)))
         ((eq c 41) (setq par-cnt (1- par-cnt)))
         )
        )
       ((eq c 40) (setq par-cnt 1))
       ((eq c ?\n))
       ((eq c ?\t))
       ((eq c 32))
       (t 
        (if (eq c 34) (setq quoted t))
        (aset ret ret-cnt c)
        (setq ret-cnt (1+ ret-cnt))
        )
       )
      (setq i (1+ i))
      )
    (substring ret 0 ret-cnt)
    ))

--かず



Mew-dist メーリングリストの案内