Function: xsdre-range-list-to-char-alternative

xsdre-range-list-to-char-alternative is a byte-compiled function defined in xsd-regexp.el.gz.

Signature

(xsdre-range-list-to-char-alternative RANGE-LIST)

Documentation

Return a char alternative for a range-list.

RANGE-LIST must contain more than integer. The char alternative is a string containing an Emacs regexp consisting of a single char alternative delimited with [].

Source Code

;; Defined in /usr/src/emacs/lisp/nxml/xsd-regexp.el.gz
(defun xsdre-range-list-to-char-alternative (range-list)
  "Return a char alternative for a range-list.
RANGE-LIST must contain more than integer.
The char alternative is a string containing an Emacs regexp
consisting of a single char alternative delimited with []."
  (let (range caret close-bracket hyphen chars first last)
    (while range-list
      (setq range (car range-list))
      (setq first (xsdre-range-first range))
      (setq last (xsdre-range-last range))
      (while (and (cond ((eq first ?^)
			 (setq caret t)
			 (setq first (1+ first)))
			((eq first ?-)
			 (setq hyphen t)
			 (setq first (1+ first)))
			((eq last ?-)
			 (setq hyphen t)
			 (setq last (1- last)))
			((eq first ?\])
			 (setq close-bracket t)
			 (setq first (1+ first)))
			((eq last ?\])
			 (setq close-bracket t)
			 (setq last (1- last))))
		  (<= first last)))
      (when (<= first last)
	(setq chars
	      (cons first chars))
	(when (< first last)
	  (setq chars
		(if (and (eq last (1+ first))
			 (not (eq last ?-)))
		    (cons last chars)
		  (cons last (cons ?- chars))))))
      (setq range-list (cdr range-list)))
    (when caret
      (setq chars (cons ?^ chars)))
    (when hyphen
      (setq chars (cons ?- chars)))
    (setq chars (cons ?\] chars))
    (setq chars (nreverse chars))
    (when close-bracket
      (setq chars (cons ?\] chars)))
    (when (equal chars '(?^ ?- ?\]))
      (setq chars '(?- ?^ ?\])))
    (setq chars (cons ?\[ chars))
    (apply 'string chars)))