commodities cleanup

This commit is contained in:
Craig Earls 2013-04-15 08:14:54 -07:00
parent 981dba0df3
commit 19be97c246

View file

@ -92,11 +92,9 @@ Returns a list with (value commodity)."
(defun ledger-strip (str char) (defun ledger-strip (str char)
(let (new-str) (let (new-str)
(concat (dolist (ch (append str nil) new-str)
(dolist (ch (append str nil))
(unless (= ch char) (unless (= ch char)
(setq new-str (append new-str (list ch))))) (setq new-str (append new-str (list ch))))))))
(concat new-str)))
(defun ledger-string-to-number (str &optional decimal-comma) (defun ledger-string-to-number (str &optional decimal-comma)
"improve builtin string-to-number by handling internationalization, and return nil of number can't be parsed" "improve builtin string-to-number by handling internationalization, and return nil of number can't be parsed"
@ -104,7 +102,7 @@ Returns a list with (value commodity)."
(assoc "decimal-comma" ledger-environment-alist)) (assoc "decimal-comma" ledger-environment-alist))
(ledger-strip str ?.) (ledger-strip str ?.)
(ledger-strip str ?,)))) (ledger-strip str ?,))))
(while (string-match "," nstr) (while (string-match "," nstr) ;if there is a comma now, it is a thousands separator
(setq nstr (replace-match "." nil nil nstr))) (setq nstr (replace-match "." nil nil nstr)))
(string-to-number nstr))) (string-to-number nstr)))
@ -116,30 +114,6 @@ Returns a list with (value commodity)."
(setq str (replace-match "," nil nil str))) (setq str (replace-match "," nil nil str)))
str))) str)))
;; (defun ledger-commodity-string-number-decimalize (number-string direction)
;; "Take NUMBER-STRING and ensure proper decimalization for use by string-to-number and number-to-string.
;; DIRECTION can be :to-user or :from-user. All math calculations
;; are done with decimal-period, some users may prefer decimal-comma
;; which must be translated both directions."
;; (let ((val number-string))
;; (if (assoc "decimal-comma" ledger-environment-alist)
;; (cond ((eq direction :from-user)
;; ;; change string to decimal-period
;; (while (string-match "," val)
;; (setq val (replace-match "." nil nil val)))) ;; switch to period separator
;; ((eq direction :to-user)
;; ;; change to decimal-comma
;; (while (string-match "\\." val)
;; (setq val (replace-match "," nil nil val)))) ;; gets rid of periods
;; (t
;; (error "ledger-commodity-string-number-decimalize: direction not properly specified %S" direction)))
;; (while (string-match "," val)
;; (setq val (replace-match "" nil nil val))))
;; val))
(defun ledger-commodity-to-string (c1) (defun ledger-commodity-to-string (c1)
"Return string representing C1. "Return string representing C1.
Single character commodities are placed ahead of the value, Single character commodities are placed ahead of the value,