time-stamp: refactor for readability

* lisp/time-stamp.el (time-stamp-string-preprocess): Move all of the
big 'while' loop to the end of the function, to better expose its
structure of iterating over the format string.
This commit is contained in:
Stephen Gildea 2025-03-12 06:48:55 -07:00
parent 26f5e6339b
commit 1bfbaacc05

View file

@ -531,18 +531,13 @@ time is used. The time zone is determined by `time-stamp-time-zone'."
Optional second argument TIME is only for testing.
This is an internal routine implementing extensions to `format-time-string'
and all `time-stamp-format' compatibility."
(let ((fmt-len (length format))
(ind 0)
cur-char
(result ""))
(while (< ind fmt-len)
(setq cur-char (aref format ind))
(setq
result
(concat
result
(cond
((eq cur-char ?%)
(let*
((fmt-len (length format))
(ind 0)
cur-char
(result "")
(handle-one-conversion
(lambda ()
(let ((prev-char nil)
(field-width "")
field-result
@ -780,7 +775,17 @@ and all `time-stamp-format' compatibility."
(format (format "%%%s%c"
field-width
(if (numberp field-result) ?d ?s))
(or field-result ""))))
(or field-result "")))))) ;end of handle-one-conversion
;; iterate over the format string
(while (< ind fmt-len)
(setq cur-char (aref format ind))
(setq
result
(concat
result
(cond
((eq cur-char ?%)
(funcall handle-one-conversion))
(t
(char-to-string cur-char)))))
(setq ind (1+ ind)))