(std11-next-field-head-regexp): New constant.
[elisp/apel.git] / std11.el
1 ;;; std11.el --- STD 11 parser for GNU Emacs
2
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
4
5 ;; Author:   MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: mail, news, RFC 822, STD 11
7 ;; Version: $Id: std11.el,v 0.2 1996-08-28 12:32:17 morioka Exp $
8
9 ;; This file is part of tl (Tiny Library).
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with This program; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 ;;; @ field
29 ;;;
30
31 (defconst std11-field-name-regexp "[!-9;-~]+")
32 (defconst std11-field-head-regexp
33   (concat "\\(" std11-field-name-regexp "\\):"))
34 (defconst std11-next-field-head-regexp
35   (concat "\n" std11-field-head-regexp))
36
37 (defun std11-field-end ()
38   (if (re-search-forward std11-next-field-head-regexp nil t)
39       (goto-char (match-beginning 0))
40     (if (re-search-forward "^$" nil t)
41         (goto-char (1- (match-beginning 0)))
42       (end-of-line)
43       ))
44   (point)
45   )
46
47
48 ;;; @ header
49 ;;;
50
51 (defun std11-header-string (pat &optional boundary)
52   (let ((case-fold-search t))
53     (save-excursion
54       (save-restriction
55         (std11-narrow-to-header boundary)
56         (goto-char (point-min))
57         (let (field header)
58           (while (re-search-forward std11-field-head-regexp nil t)
59             (setq field
60                   (buffer-substring (match-beginning 0) (std11-field-end)))
61             (if (string-match pat field)
62                 (setq header (concat header field "\n"))
63               ))
64           header)
65         ))))
66
67 (defun std11-header-string-except (pat &optional boundary)
68   (let ((case-fold-search t))
69     (save-excursion
70       (save-restriction
71         (std11-narrow-to-header boundary)
72         (goto-char (point-min))
73         (let (field header)
74           (while (re-search-forward std11-field-head-regexp nil t)
75             (setq field
76                   (buffer-substring (match-beginning 0) (std11-field-end)))
77             (if (not (string-match pat field))
78                 (setq header (concat header field "\n"))
79               ))
80           header)
81         ))))
82
83 (defun std11-narrow-to-header (&optional boundary)
84   (narrow-to-region
85    (goto-char (point-min))
86    (if (re-search-forward
87         (concat "^\\(" (regexp-quote (or boundary "")) "\\)?$")
88         nil t)
89        (match-beginning 0)
90      (point-max)
91      )))
92
93
94 ;;; @ end
95 ;;;
96
97 (provide 'std11)
98
99 ;;; std11.el ends here