Function: icalendar-unfold-undecoded-region
icalendar-unfold-undecoded-region is a byte-compiled function defined
in icalendar-parser.el.gz.
Signature
(icalendar-unfold-undecoded-region START END &optional BUFFER)
Documentation
Unfold an undecoded region in BUFFER between START and END.
If omitted, BUFFER defaults to the current buffer.
"Unfolding" means removing the whitespace characters inserted to
continue lines longer than 75 octets (see icalendar-fold-region
for the folding operation). RFC5545 specifies these whitespace
characters to be a CR-LF sequence followed by a single space or
tab character. Unfolding can only be done reliably before a
region is decoded, since decoding potentially replaces CR-LF line
endings.
When icalendar-parse-strictly is non-nil, this function searches
strictly for CR-LF sequences and will fail if they have already been
replaced, so it should only be called with a region that has not yet
been decoded. Otherwise, it also searches for folds containing
Unix-style LF line endings, since these are common in real data.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/icalendar-parser.el.gz
(defun ical:unfold-undecoded-region (start end &optional buffer)
"Unfold an undecoded region in BUFFER between START and END.
If omitted, BUFFER defaults to the current buffer.
\"Unfolding\" means removing the whitespace characters inserted to
continue lines longer than 75 octets (see `icalendar-fold-region'
for the folding operation). RFC5545 specifies these whitespace
characters to be a CR-LF sequence followed by a single space or
tab character. Unfolding can only be done reliably before a
region is decoded, since decoding potentially replaces CR-LF line
endings.
When `icalendar-parse-strictly' is non-nil, this function searches
strictly for CR-LF sequences and will fail if they have already been
replaced, so it should only be called with a region that has not yet
been decoded. Otherwise, it also searches for folds containing
Unix-style LF line endings, since these are common in real data."
(with-current-buffer (or buffer (current-buffer))
(let ((modp (buffer-modified-p)))
(with-restriction start end
(run-hooks 'ical:pre-unfolding-hook)
(goto-char (point-min))
;; Testing reveals that a *significant* amount of real-world data
;; does not use CR-LF line endings, even if it is otherwise
;; OK. So unless we're explicitly parsing strictly, we allow the
;; CR to be missing, as we do in `icalendar-unfold-region':
(let ((fold (if ical:parse-strictly (rx (seq "\r\n" (or " " "\t")))
(rx (seq (zero-or-one "\r") "\n" (or " " "\t"))))))
(while (re-search-forward fold nil t)
(replace-match "" nil nil)))
;; merely unfolding should not mark the buffer as modified;
;; this prevents querying the user before killing it:
(set-buffer-modified-p modp)))))