Function: dired-x--string-to-number

dired-x--string-to-number is a byte-compiled function defined in dired-x.el.gz.

Signature

(dired-x--string-to-number STR)

Documentation

Like string-to-number but recognize a trailing unit prefix.

For example, 2K is expanded to 2048.0. The caller should make sure that a trailing letter in STR is one of BKkMGTPEZY.

Source Code

;; Defined in /usr/src/emacs/lisp/dired-x.el.gz
;; Needed if ls -lh is supported and also for GNU ls -ls.
(defun dired-x--string-to-number (str)
  "Like `string-to-number' but recognize a trailing unit prefix.
For example, 2K is expanded to 2048.0.  The caller should make
sure that a trailing letter in STR is one of BKkMGTPEZY."
  (let* ((val (string-to-number str))
         (u (unless (zerop val)
              (aref str (1- (length str))))))
    (when (and u (> u ?9))
      (when (= u ?k)
        (setq u ?K))
      (let ((units '(?B ?K ?M ?G ?T ?P ?E ?Z ?Y)))
        (while (and units (/= (pop units) u))
          (setq val (* 1024.0 val)))))
    val))