Function: icalendar-make-value-node-of

icalendar-make-value-node-of is a byte-compiled function defined in icalendar-ast.el.gz.

Signature

(icalendar-make-value-node-of TYPE VALUE)

Documentation

Make an iCalendar syntax node of type TYPE containing VALUE as its value.

TYPE should be a symbol for an iCalendar value type, and VALUE should be a value of that type. If TYPE is the symbol 'plain-text, VALUE should be a string, and in that case VALUE is returned as-is.

TYPE may also be a list of type symbols; in that case, the first type in the list which VALUE satisfies is used as the returned node's type. If the list is nil, VALUE will be checked against all types in icalendar-value-types.

If VALUE is nil, and icalendar-boolean is not (in) TYPE, nil is returned. Otherwise, a 'wrong-type-argument error is signaled if VALUE does not satisfy (any type in) TYPE.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/icalendar-ast.el.gz
;; A more flexible constructor for value nodes which can choose the
;; correct type from a list.  This helps keep templates succinct and easy
;; to use in `icalendar-make-node-from-templates', and related macros
;; below.
(defun ical:make-value-node-of (type value)
  "Make an iCalendar syntax node of type TYPE containing VALUE as its value.

TYPE should be a symbol for an iCalendar value type, and VALUE should be
a value of that type.  If TYPE is the symbol \\='plain-text, VALUE should
be a string, and in that case VALUE is returned as-is.

TYPE may also be a list of type symbols; in that case, the first type in
the list which VALUE satisfies is used as the returned node's type.  If
the list is nil, VALUE will be checked against all types in
`icalendar-value-types'.

If VALUE is nil, and `icalendar-boolean' is not (in) TYPE, nil is
returned.  Otherwise, a \\='wrong-type-argument error is signaled if
VALUE does not satisfy (any type in) TYPE."
  (require 'icalendar-parser) ; for `icalendar-list-of-p'
  (cond
   ((and (null value)
         (not (if (listp type) (memq 'ical:boolean type)
                (eq 'ical:boolean type))))
    ;; Instead of signaling an error, we just return nil in this case.
    ;; This allows the `ical:make-*' macros higher up the stack to
    ;; filter out templates that evaluate to nil at run time:
    nil)
   ((eq type 'plain-text)
    (unless (stringp value)
      (signal 'wrong-type-argument (list 'stringp value)))
    value)
   ((symbolp type)
    (unless (ical:value-type-symbol-p type)
      (signal 'wrong-type-argument (list 'icalendar-value-type-symbol-p type)))
    (if (ical:expects-list-of-values-p type)
        (unless (ical:list-of-p value type)
          (signal 'wrong-type-argument (list `(list-of ,type) value)))
      (unless (cl-typep value type)
        (signal 'wrong-type-argument (list type value)))
      (ical:make-ast-node type (list :value value))))
   ((listp type)
    ;; N.B. nil is allowed; in that case, `ical:type-of' will check all
    ;; types in `ical:value-types':
    (let ((the-type (ical:type-of value type)))
      (if the-type
          (ical:make-ast-node the-type (list :value value))
        (signal 'wrong-type-argument
                (list (if (length> type 1) (cons 'or type) (car type))
                      value)))))
   (t (signal 'wrong-type-argument (list '(or symbolp listp) type)))))