Handle quoted commodities in ledger-split-commodity-string
This commit is contained in:
parent
f1882d0a56
commit
c8c94e9602
1 changed files with 26 additions and 15 deletions
|
|
@ -41,21 +41,32 @@ Returns a list with (value commodity)."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert str)
|
(insert str)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(cond ((re-search-forward number-regex nil t)
|
(cond
|
||||||
;; found a number in the current locale, return it in
|
((re-search-forward "\"\\(.*\\)\"" nil t)
|
||||||
;; the car. Anything left over is annotation,
|
(let ((com (delete-and-extract-region
|
||||||
;; the first thing should be the commodity, separated
|
(match-beginning 1)
|
||||||
;; by whitespace, return it in the cdr. I can't think of any
|
(match-end 1))))
|
||||||
;; counterexamples
|
(if (re-search-forward number-regex nil t)
|
||||||
(list
|
(list
|
||||||
(string-to-number
|
(string-to-number
|
||||||
(ledger-commodity-string-number-decimalize
|
(ledger-commodity-string-number-decimalize
|
||||||
(delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))
|
(delete-and-extract-region (match-beginning 0) (match-end 0)) :from-user))
|
||||||
(nth 0 (split-string (buffer-substring-no-properties (point-min) (point-max))))))
|
com))))
|
||||||
((re-search-forward "0" nil t)
|
((re-search-forward number-regex nil t)
|
||||||
;; couldn't find a decimal number, look for a single 0,
|
;; found a number in the current locale, return it in
|
||||||
;; indicating account with zero balance
|
;; the car. Anything left over is annotation,
|
||||||
(list 0 ledger-reconcile-default-commodity)))))
|
;; 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
|
;; nothing found, return 0
|
||||||
(list 0 ledger-reconcile-default-commodity)))
|
(list 0 ledger-reconcile-default-commodity)))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue