summaryrefslogtreecommitdiff
path: root/lisp/ldg-commodities.el
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2013-03-09 12:27:08 -0500
committerCraig Earls <enderw88@gmail.com>2013-03-09 12:27:08 -0500
commitca99c0de03432393aa6576244005c9ad8806fa29 (patch)
treebf0dd4586adb4b7df1adad8a5eff5d2bca36f4e3 /lisp/ldg-commodities.el
parent4c608cccd0c6f06f403882dcca36cb62a40178a2 (diff)
parentbfe360d4c992caf2e7da09ab058599c0404f1348 (diff)
downloadfork-ledger-ca99c0de03432393aa6576244005c9ad8806fa29.tar.gz
fork-ledger-ca99c0de03432393aa6576244005c9ad8806fa29.tar.bz2
fork-ledger-ca99c0de03432393aa6576244005c9ad8806fa29.zip
Merge branch 'next' into ledger-mode-automatic-transactions
Diffstat (limited to 'lisp/ldg-commodities.el')
-rw-r--r--lisp/ldg-commodities.el46
1 files changed, 24 insertions, 22 deletions
diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el
index a3cc8951..9291136f 100644
--- a/lisp/ldg-commodities.el
+++ b/lisp/ldg-commodities.el
@@ -33,28 +33,30 @@
(defun ledger-split-commodity-string (str)
"Split a commoditized amount into two parts"
- (let (val
- comm)
- (with-temp-buffer
- (insert str)
- (goto-char (point-min))
- (cond ((re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t)
- ;; found a decimal number
- (setq val
- (string-to-number
- (ledger-commodity-string-number-decimalize
- (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)))
- (goto-char (point-min))
- (re-search-forward "[^[:space:]]" nil t)
- (setq comm
- (delete-and-extract-region (match-beginning 0) (match-end 0)))
- (list val comm))
- ((re-search-forward "0" nil t)
- ;; couldn't find a decimal number, look for a single 0,
- ;; indicating account with zero balance
- (list 0 ledger-reconcile-default-commodity))
- (t
- (error "split-commodity-string: cannot parse commodity string: %S" str))))))
+ (if (> (length str) 0)
+ (let (val
+ comm)
+ (with-temp-buffer
+ (insert str)
+ (goto-char (point-min))
+ (cond ((re-search-forward "-?[1-9][0-9]*[.,][0-9]*" nil t)
+ ;; found a decimal number
+ (setq val
+ (string-to-number
+ (ledger-commodity-string-number-decimalize
+ (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)))
+ (goto-char (point-min))
+ (re-search-forward "[^[:space:]]" nil t)
+ (setq comm
+ (delete-and-extract-region (match-beginning 0) (match-end 0)))
+ (list val comm))
+ ((re-search-forward "0" nil t)
+ ;; couldn't find a decimal number, look for a single 0,
+ ;; indicating account with zero balance
+ (list 0 ledger-reconcile-default-commodity))
+ (t
+ (error "split-commodity-string: cannot parse commodity string: %S" str)))))
+ (list 0 ledger-reconcile-default-commodity)))
(defun ledger-string-balance-to-commoditized-amount (str)