Bug 797989 - Sorting columns by alphabet with non-ASCII characters

use gnc:string-locale for string sorting
This commit is contained in:
Christopher Lam 2020-10-27 21:51:00 +08:00
parent 8628ffa957
commit 7e6cb470f1
11 changed files with 44 additions and 41 deletions

View File

@ -65,7 +65,7 @@
(gnc-main-window-open-report
(gnc:make-report report-guid) window))))))
(sort (filter (compose gnc:report-template-in-menu? cdr) *template-items*)
(lambda (a b) (string>? (car a) (car b))))))
(lambda (a b) (gnc:string-locale>? (car a) (car b))))))
(define (gnc:report-menu-setup)
(define asset-liability-menu

View File

@ -412,8 +412,8 @@
(set! retval
(sort retval
(lambda (a b)
(string<? (qif-map-entry:qif-name a)
(qif-map-entry:qif-name b)))))
(gnc:string-locale<? (qif-map-entry:qif-name a)
(qif-map-entry:qif-name b)))))
retval))
@ -532,8 +532,8 @@
;; sort by qif account name
(set! retval (sort retval
(lambda (a b)
(string<? (qif-map-entry:qif-name a)
(qif-map-entry:qif-name b)))))
(gnc:string-locale<? (qif-map-entry:qif-name a)
(qif-map-entry:qif-name b)))))
retval))
;; this one's like the other display builders, it just looks at the
@ -624,8 +624,8 @@
;; sort by qif memo/payee name
(set! retval (sort retval
(lambda (a b)
(string<? (qif-map-entry:qif-name a)
(qif-map-entry:qif-name b)))))
(gnc:string-locale<? (qif-map-entry:qif-name a)
(qif-map-entry:qif-name b)))))
retval))
@ -826,7 +826,7 @@
#f acct-hash)
(if (not (null? names))
(sort names string<?)
(sort names gnc:string-locale<?)
#f)))
;; this is used within the dialog to get a list of all the new
@ -867,7 +867,7 @@
(loop (car tree-left) (cdr tree-left))
(set! newtree (cons (cvt-to-tree path new?)
newtree))))))
(sort newtree (lambda (a b) (string<? (car a) (car b))))))))
(sort newtree (lambda (a b) (gnc:string-locale<? (car a) (car b))))))))
(let ((accts '())

View File

@ -528,14 +528,14 @@
;; some useful predicates to export
(define (gnc:account-code-less-p a b)
(string<? (xaccAccountGetCode a)
(xaccAccountGetCode b)))
(gnc:string-locale<? (xaccAccountGetCode a)
(xaccAccountGetCode b)))
(define (gnc:account-name-less-p a b)
(string<? (xaccAccountGetName a)
(xaccAccountGetName b)))
(gnc:string-locale<? (xaccAccountGetName a)
(xaccAccountGetName b)))
(define (gnc:account-path-less-p a b)
(string<? (gnc-account-get-full-name a)
(gnc-account-get-full-name b)))
(gnc:string-locale<? (gnc-account-get-full-name a)
(gnc-account-get-full-name b)))
(define (gnc:html-acct-table-add-accounts! acct-table accounts)

View File

@ -201,14 +201,14 @@
(define (gnc:get-html-style-sheets)
(sort (map cdr (hash-map->list cons *gnc:_style-sheets_*))
(lambda (a b)
(string<? (gnc:html-style-sheet-name a)
(gnc:html-style-sheet-name b)))))
(gnc:string-locale<? (gnc:html-style-sheet-name a)
(gnc:html-style-sheet-name b)))))
(define (gnc:get-html-templates)
(sort (map cdr (hash-map->list cons *gnc:_style-sheet-templates_*))
(lambda (a b)
(string<? (gnc:html-style-sheet-template-name a)
(gnc:html-style-sheet-template-name b)))))
(gnc:string-locale<? (gnc:html-style-sheet-template-name a)
(gnc:html-style-sheet-template-name b)))))
(define (gnc:html-style-sheet-find tname)
(hash-ref *gnc:_style-sheets_* tname))

View File

@ -777,7 +777,8 @@ not found.")))
(lambda (k v p) (if (gnc:report-template-in-menu? v) (cons v p) p))
'() *gnc:_report-templates_*)
(lambda (a b)
(string<? (gnc:report-template-name a) (gnc:report-template-name b))))))
(gnc:string-locale<? (gnc:report-template-name a)
(gnc:report-template-name b))))))
(define-public (gnc:cmdline-report-show report port)
(let ((templates (reportname->templates report)))

View File

@ -138,8 +138,8 @@
(sort-and-delete-duplicates
(map xaccAccountGetCommodity accounts)
(lambda (a b)
(string<? (gnc-commodity-get-unique-name a)
(gnc-commodity-get-unique-name b)))
(gnc:string-locale<? (gnc-commodity-get-unique-name a)
(gnc-commodity-get-unique-name b)))
gnc-commodity-equiv)))

View File

@ -209,12 +209,12 @@ balance at a given time"))
(cond
((eq? sort-method 'acct-code)
(lambda (a b)
(string<? (xaccAccountGetCode (cadr a))
(xaccAccountGetCode (cadr b)))))
(gnc:string-locale<? (xaccAccountGetCode (cadr a))
(xaccAccountGetCode (cadr b)))))
((eq? sort-method 'alphabetical)
(lambda (a b)
(string<? (display-name-accounts show-fullname? (cadr a))
(display-name-accounts show-fullname? (cadr b)))))
(gnc:string-locale<? (display-name-accounts show-fullname? (cadr a))
(display-name-accounts show-fullname? (cadr b)))))
(else
(lambda (a b) (> (car a) (car b))))))
@ -223,12 +223,12 @@ balance at a given time"))
(cond
((eq? sort-method 'acct-code)
(lambda (a b)
(string<? (gnc-commodity-get-mnemonic (cadr a))
(gnc-commodity-get-mnemonic (cadr b)))))
(gnc:string-locale<? (gnc-commodity-get-mnemonic (cadr a))
(gnc-commodity-get-mnemonic (cadr b)))))
((eq? sort-method 'alphabetical)
(lambda (a b)
(string<? (display-name-security show-fullname? (cadr a))
(display-name-security show-fullname? (cadr b)))))
(gnc:string-locale<? (display-name-security show-fullname? (cadr a))
(display-name-security show-fullname? (cadr b)))))
(else
(lambda (a b) (> (car a) (car b))))))

View File

@ -479,14 +479,14 @@ developing over time"))
((alphabetical)
(lambda (a b)
(if show-fullname?
(string<? (gnc-account-get-full-name (car a))
(gnc-account-get-full-name (car b)))
(string<? (xaccAccountGetName (car a))
(xaccAccountGetName (car b))))))
(gnc:string-locale<? (gnc-account-get-full-name (car a))
(gnc-account-get-full-name (car b)))
(gnc:string-locale<? (xaccAccountGetName (car a))
(xaccAccountGetName (car b))))))
((acct-code)
(lambda (a b)
(string<? (xaccAccountGetCode (car a))
(xaccAccountGetCode (car b)))))
(gnc:string-locale<? (xaccAccountGetCode (car a))
(xaccAccountGetCode (car b)))))
((amount)
(lambda (a b)
(> (gnc:gnc-monetary-amount (apply gnc:monetary+ (cadr a)))

View File

@ -406,7 +406,9 @@
;; Stable-sort the sortingtable according to column, then
;; stable-sort according to currency. This results in group-by
;; currency then sort by columns.
(let* ((str-op (if (eq? sort-order 'descend) string>? string<?))
(let* ((str-op (if (eq? sort-order 'descend)
gnc:string-locale>?
gnc:string-locale<?))
(op (if (eq? sort-order 'descend) > <)))
(define (<? key)
(case key
@ -421,7 +423,7 @@
(else (str-op (vector-ref a 0) (vector-ref b 0))))))
;; currency sorting always alphabetical a-z
((currency)
(lambda (a b) (string<?
(lambda (a b) (gnc:string-locale<?
(gnc-commodity-get-mnemonic (vector-ref a 1))
(gnc-commodity-get-mnemonic (vector-ref b 1)))))
((markup)

View File

@ -218,7 +218,7 @@ exist but have no suitable transactions."))
(match-let* (((own1 aging1 aging-total1) a)
((own2 aging2 aging-total2) b)
(increasing? (eq? sort-order 'increasing))
(op-str (if increasing? string<? string>?))
(op-str (if increasing? gnc:string-locale<? gnc:string-locale>?))
(op-num (if increasing? < >)))
(case sort-by
((name) (op-str (gncOwnerGetName own1) (gncOwnerGetName own2)))

View File

@ -2089,7 +2089,7 @@ warning will be removed in GnuCash 5.0"))
(value-of-X (comparator-function split-X))
(value-of-Y (comparator-function split-Y))
(op (if (string? value-of-X)
(if ascend? string<? string>?)
(if ascend? gnc:string-locale<? gnc:string-locale>?)
(if ascend? < >))))
(and value-of-X (op value-of-X value-of-Y))))
@ -2245,7 +2245,7 @@ warning will be removed in GnuCash 5.0"))
(when subtotal-table?
(let* ((generic<?
(lambda (a b)
(cond ((string? (car a)) (string<? (car a) (car b)))
(cond ((string? (car a)) (gnc:string-locale<? (car a) (car b)))
((number? (car a)) (< (car a) (car b)))
(else (gnc:error "unknown sortvalue")))))
(list-of-rows