Function: shr--parse-srcset

shr--parse-srcset is a byte-compiled function defined in shr.el.gz.

Signature

(shr--parse-srcset SRCSET &optional WIDTH)

Source Code

;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
(defun shr--parse-srcset (srcset &optional width)
  (setq srcset (string-trim srcset)
        width (or width 100))
  (when (> (length srcset) 0)
    ;; srcset consists of a series of URL/size specifications separated
    ;; by the " ," string.
    (sort (mapcar
           (lambda (elem)
             (let ((spec (split-string elem "[\t\n\r ]+")))
               (cond
                ((= (length spec) 1)
                 ;; Make sure it's well formed.
                 (list (car spec) 0))
                ((string-match "\\([0-9]+\\)x\\'" (cadr spec))
                 ;; If we have an "x" form, then use the width
                 ;; spec to compute the real width.
                 (list (car spec)
                       (* width (string-to-number
                                 (match-string 1 (cadr spec))))))
                (t
                 (list (car spec)
                       (string-to-number (cadr spec)))))))
           (with-temp-buffer
             (insert srcset)
             (goto-char (point-min))
             (let ((bits nil))
               (while (re-search-forward "[^\t\n\r ]+[\t\n\r ]+[^\t\n\r ,]+"
                                         nil t)
                 (push (match-string 0) bits)
                 (if (looking-at "[\t\n\r ]*,[\t\n\r ]*")
                     (goto-char (match-end 0))
                   (goto-char (point-max))))
               bits)))
          (lambda (e1 e2)
            (> (cadr e1) (cadr e2))))))