[GNC] Transaction ordering on num field
John Ralls
jralls at ceridwen.us
Tue Jun 8 13:37:04 EDT 2021
Really the effective num field because of the split-action option, but anyway...
The submitter of PR#963 complained that sorting on the num field doesn't work right if the value is bigger than an int can hold; that's 9 digits. His knowledge of C wasn't quite up to the task of fixing it, but I've fixed his implementation and have it ready to push for GnuCash 4.6.
So far so good, but it changes the order of transactions when the num field isn't all numeric and I want to know if the change will cause trouble for anyone.
The current behavior is that a string beginning with a letter will have a sort value of 0 and one starting with a number will have a value equal to the numbers up to the first non-number character, so for example 12ab34 will have a sort value of 12, up to ±(10^10 - 1). "abc" and "def" will sort equally so the compare would fall through to the next criterion; "abc" would sort between "-12ab34" and "12ab34".
The new way is that if both strings are all numbers and there are fewer than 19 characters in each then the sort values will be their numeric values and the comparison will be numeric, so e.g. 2 sorts before 10. If those conditions aren't true then the two values will be string-compared, meaning a lexical sort: A very large number beginning with 2 will sort before a shorter number beginning with 3; "abc" will sort before "def" but after both "123" and "-123" because 1 and - sort before a. That's for an English locale; in order to accommodate UTF-8 strings the collation of the current locale.
Will that break anyone's carefully-crafted transaction ordering?
Regards,
John Ralls
More information about the gnucash-user
mailing list