Function: icalendar-parse-property-value

icalendar-parse-property-value is a byte-compiled function defined in icalendar-parser.el.gz.

Signature

(icalendar-parse-property-value TYPE LIMIT &optional PARAMS)

Documentation

Parse a value for the property type TYPE from point up to LIMIT.

This function expects point to be at the start of the value expression, after "PROPERTY-NAME[PARAM...]:". Returns a syntax node of type TYPE containing the parsed value and the list of PARAMS.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar-parser.el.gz
(defun ical:parse-property-value (type limit &optional params)
  "Parse a value for the property type TYPE from point up to LIMIT.
This function expects point to be at the start of the value
expression, after \"PROPERTY-NAME[PARAM...]:\".  Returns a syntax
node of type TYPE containing the parsed value and the list of
PARAMS."
  (let ((start (point))
        (full-value-regex (rx-to-string (get type 'ical:full-value-rx))))

    ;; By far the most common invalid data seem to be text values that
    ;; contain unescaped characters (e.g. commas in addresses in
    ;; LOCATION).  These are harmless as long as the property accepts
    ;; any text value, accepts no other types of values, and does not
    ;; expect a list of values.  So we treat this as a special case and
    ;; loosen the regexp to accept any non-control character until eol:
    (when (and (eq 'ical:text (get type 'ical:default-type))
               (equal (rx-to-string 'ical:text t)
                      (rx-to-string (get type 'ical:value-rx) t))
               (null (get type 'ical:other-types))
               (not (ical:expects-list-of-values-p type))
               (not ical:parse-strictly))
        (setq full-value-regex
              (rx (group-n 2 (zero-or-more (not (any control))))
                  line-end)))

    (unless (re-search-forward full-value-regex limit t)
      (ical:signal-parse-error
       (format "Unable to parse `%s' property value between %d and %d"
               type start limit)
       :restart-at (1+ limit)))

    (when (match-string 3)
      (ical:signal-parse-error
       (format "Invalid value for `%s' property: %s" type (match-string 3))
       :restart-at (1+ limit)))

    (let* ((value-begin (match-beginning 2))
           (value-end (match-end 2))
           (end value-end)
           (node (ical:read-property-value type (match-string 2) params)))
      (ical:ast-node-meta-set node :buffer (current-buffer))
      ;; 'begin must be set by parse-property
      (ical:ast-node-meta-set node :value-begin value-begin)
      (ical:ast-node-meta-set node :value-end value-end)
      (ical:ast-node-meta-set node :end end)

      node)))