(pgg-gpg-encrypt-region): Add --textmode to gpg args. From Mark D. Baushke.
[gnus] / lisp / parse-time.el
1 ;;; parse-time.el --- Parsing time strings
2
3 ;; Copyright (C) 1996, 2000, 2002 by Free Software Foundation, Inc.
4
5 ;; Author: Erik Naggum <erik@naggum.no>
6 ;; Keywords: util
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; With the introduction of the `encode-time', `decode-time', and
28 ;; `format-time-string' functions, dealing with time became simpler in
29 ;; Emacs.  However, parsing time strings is still largely a matter of
30 ;; heuristics and no common interface has been designed.
31
32 ;; `parse-time-string' parses a time in a string and returns a list of 9
33 ;; values, just like `decode-time', where unspecified elements in the
34 ;; string are returned as nil.  `encode-time' may be applied on these
35 ;; values to obtain an internal time value.
36
37 ;;; Code:
38
39 (eval-when-compile (require 'cl))       ;and ah ain't kiddin' 'bout it
40
41 (defvar parse-time-syntax (make-vector 256 nil))
42 (defvar parse-time-digits (make-vector 256 nil))
43
44 ;; Byte-compiler warnings
45 (defvar elt)
46 (defvar val)
47
48 (unless (aref parse-time-digits ?0)
49   (loop for i from ?0 to ?9
50     do (aset parse-time-digits i (- i ?0))))
51
52 (unless (aref parse-time-syntax ?0)
53   (loop for i from ?0 to ?9
54     do (aset parse-time-syntax i ?0))
55   (loop for i from ?A to ?Z
56     do (aset parse-time-syntax i ?A))
57   (loop for i from ?a to ?z
58     do (aset parse-time-syntax i ?a))
59   (aset parse-time-syntax ?+ 1)
60   (aset parse-time-syntax ?- -1)
61   (aset parse-time-syntax ?: ?d)
62   )
63
64 (defsubst digit-char-p (char)
65   (aref parse-time-digits char))
66
67 (defsubst parse-time-string-chars (char)
68   (aref parse-time-syntax char))
69
70 (put 'parse-error 'error-conditions '(parse-error error))
71 (put 'parse-error 'error-message "Parsing error")
72
73 (defsubst parse-integer (string &optional start end)
74   "[CL] Parse and return the integer in STRING, or nil if none."
75   (let ((integer 0)
76         (digit 0)
77         (index (or start 0))
78         (end (or end (length string))))
79     (when (< index end)
80       (let ((sign (aref string index)))
81         (if (or (eq sign ?+) (eq sign ?-))
82             (setq sign (parse-time-string-chars sign)
83                   index (1+ index))
84           (setq sign 1))
85         (while (and (< index end)
86                     (setq digit (digit-char-p (aref string index))))
87           (setq integer (+ (* integer 10) digit)
88                 index (1+ index)))