X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/97d44922da3c22b3973f95892bfa2ee4afc0ceac..7c6317a0498b6690ea668909ac012cb45e6f809b:/lisp/calendar/parse-time.el diff --git a/lisp/calendar/parse-time.el b/lisp/calendar/parse-time.el index b2b065ab65..b62f9fa794 100644 --- a/lisp/calendar/parse-time.el +++ b/lisp/calendar/parse-time.el @@ -1,6 +1,6 @@ ;;; parse-time.el --- parsing time strings -;; Copyright (C) 1996, 2000-2015 Free Software Foundation, Inc. +;; Copyright (C) 1996, 2000-2016 Free Software Foundation, Inc. ;; Author: Erik Naggum ;; Keywords: util @@ -41,17 +41,16 @@ (defvar parse-time-val) (defsubst parse-time-string-chars (char) - (save-match-data - (let (case-fold-search str) - (cond ((eq char ?+) 1) - ((eq char ?-) -1) - ((eq char ?:) ?d) - ((string-match "[[:upper:]]" (setq str (string char))) ?A) - ((string-match "[[:lower:]]" str) ?a) - ((string-match "[[:digit:]]" str) ?0))))) + (cond ((<= ?a char ?z) ?a) + ((<= ?0 char ?9) ?0) + ((eq char ?+) 1) + ((eq char ?-) -1) + ((eq char ?:) ?d))) (defun parse-time-tokenize (string) - "Tokenize STRING into substrings." + "Tokenize STRING into substrings. +Each substring is a run of \"valid\" characters, i.e., lowercase +letters, digits, plus or minus signs or colons." (let ((start nil) (end (length string)) (all-digits nil) @@ -62,7 +61,8 @@ (while (and (< index end) ;Skip invalid characters. (not (setq c (parse-time-string-chars (aref string index))))) (cl-incf index)) - (setq start index all-digits (eq c ?0)) + (setq start index + all-digits (eq c ?0)) (while (and (< (cl-incf index) end) ;Scan valid characters. (setq c (parse-time-string-chars (aref string index)))) (setq all-digits (and all-digits (eq c ?0)))) @@ -146,8 +146,12 @@ ;;;###autoload (defun parse-time-string (string) "Parse the time-string STRING into (SEC MIN HOUR DAY MON YEAR DOW DST TZ). -The values are identical to those of `decode-time', but any values that are -unknown are returned as nil." +STRING should be on something resembling an RFC2822 string, a la +\"Fri, 25 Mar 2016 16:24:56 +0100\", but this function is +somewhat liberal in what format it accepts, and will attempt to +return a \"likely\" value even for somewhat malformed strings. +The values returned are identical to those of `decode-time', but +any values that are unknown are returned as nil." (let ((time (list nil nil nil nil nil nil nil nil nil)) (temp (parse-time-tokenize (downcase string)))) (while temp