From c8c94e960206f705610b92b6957a2209208c69c5 Mon Sep 17 00:00:00 2001 From: Craig Earls Date: Tue, 26 Mar 2013 13:55:31 -0400 Subject: Handle quoted commodities in ledger-split-commodity-string --- lisp/ldg-commodities.el | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'lisp') diff --git a/lisp/ldg-commodities.el b/lisp/ldg-commodities.el index 3485d93f..831d770b 100644 --- a/lisp/ldg-commodities.el +++ b/lisp/ldg-commodities.el @@ -41,21 +41,32 @@ Returns a list with (value commodity)." (with-temp-buffer (insert str) (goto-char (point-min)) - (cond ((re-search-forward number-regex nil t) - ;; found a number in the current locale, return it in - ;; the car. Anything left over is annotation, - ;; the first thing should be the commodity, separated - ;; by whitespace, return it in the cdr. I can't think of any - ;; counterexamples - (list - (string-to-number - (ledger-commodity-string-number-decimalize - (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)) - (nth 0 (split-string (buffer-substring-no-properties (point-min) (point-max)))))) - ((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))))) + (cond + ((re-search-forward "\"\\(.*\\)\"" nil t) + (let ((com (delete-and-extract-region + (match-beginning 1) + (match-end 1)))) + (if (re-search-forward number-regex nil t) + (list + (string-to-number + (ledger-commodity-string-number-decimalize + (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)) + com)))) + ((re-search-forward number-regex nil t) + ;; found a number in the current locale, return it in + ;; the car. Anything left over is annotation, + ;; the first thing should be the commodity, separated + ;; by whitespace, return it in the cdr. I can't think of any + ;; counterexamples + (list + (string-to-number + (ledger-commodity-string-number-decimalize + (delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user)) + (nth 0 (split-string (buffer-substring-no-properties (point-min) (point-max)))))) + ((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))))) ;; nothing found, return 0 (list 0 ledger-reconcile-default-commodity))) -- cgit v1.2.3