diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-05 06:59:31 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-05 06:59:31 -0500 |
| commit | 91c8f727f6a5881adf40ebca48af4456ad14174c (patch) | |
| tree | d75893132b076669fed64e791722f833f6110ca5 /modules | |
| parent | e8bc93bafccc8067d3fc54c0d2cb508438455afe (diff) | |
refactor(calendar-sync): extract RFC 5545 continuation line unfolding
Deduplicated the folded-line handling loop from get-property and
get-all-property-lines into calendar-sync--unfold-continuation.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/calendar-sync.el | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/modules/calendar-sync.el b/modules/calendar-sync.el index f543ef97..1f79aa6b 100644 --- a/modules/calendar-sync.el +++ b/modules/calendar-sync.el @@ -607,21 +607,25 @@ Returns list of strings, each containing one VEVENT block." (push (buffer-substring-no-properties start (point)) events))))) (nreverse events))) +(defun calendar-sync--unfold-continuation (text value start) + "Unfold RFC 5545 continuation lines from TEXT starting at START. +VALUE is the initial content to append to. Continuation lines begin +with a space or tab after a newline. Returns (unfolded-value . new-pos)." + (while (and (< start (length text)) + (string-match "\n[ \t]\\([^\n]*\\)" text start) + (= (match-beginning 0) start)) + (setq value (concat value (match-string 1 text))) + (setq start (match-end 0))) + (cons value start)) + (defun calendar-sync--get-property (event property) "Extract PROPERTY value from EVENT string. Handles property parameters (e.g., DTSTART;TZID=America/Chicago:value). Handles multi-line values (lines starting with space). Returns nil if property not found." (when (string-match (format "^%s[^:\n]*:\\(.*\\)$" (regexp-quote property)) event) - (let ((value (match-string 1 event)) - (start (match-end 0))) - ;; Handle continuation lines (RFC 5545 ยง3.1: folded lines start with space or tab) - (while (and (< start (length event)) - (string-match "\n[ \t]\\([^\n]*\\)" event start) - (= (match-beginning 0) start)) - (setq value (concat value (match-string 1 event))) - (setq start (match-end 0))) - value))) + (car (calendar-sync--unfold-continuation + event (match-string 1 event) (match-end 0))))) (defun calendar-sync--get-property-line (event property) "Extract full PROPERTY line from EVENT string, including parameters. @@ -641,14 +645,10 @@ Returns nil if EVENT or PROPERTY is nil, or no matches found." (pattern (format "^%s[^\n]*" (regexp-quote property))) (pos 0)) (while (string-match pattern event pos) - (let ((line (match-string 0 event)) - (end (match-end 0))) - ;; Handle continuation lines (start with space or tab after newline) - (while (and (< end (length event)) - (string-match "\n[ \t]\\([^\n]*\\)" event end) - (= (match-beginning 0) end)) - (setq line (concat line (match-string 1 event))) - (setq end (match-end 0))) + (let* ((result (calendar-sync--unfold-continuation + event (match-string 0 event) (match-end 0))) + (line (car result)) + (end (cdr result))) (push line lines) (setq pos (if (< end (length event)) (1+ end) end)))) (nreverse lines)))) |
