Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
SRP_Array( 'SortSimpleList') and SRP_Sort_Array(), vs SRP_Array( 'SortRows') - v2.1.4
I've found a difference in the sorting sequence between these functions in v2.1.4.
For example, both these statements
both SortSimpleList and SRP_Sort_Array() return "OBJECT,OB_STATUS"
These functions, and OI's V119() and Locate By, use the ANSI sequence for ordering characters
However - SortRows
returns the reverse order, "OB_STATUS,OBJECT"
It appears that 'SortRows' is using a different sequence for ordering these characters:
(The same is true for all older SRP Sort functions, as at v1.6. Perhaps this changed in v2.0.3?)
Notably, the underscore '_' precedes any alphabetic characters in this sequence.
The 'gotcha' is that if you are using OI's Locate By statement to insert into a pre-sorted list, that list should be sorted using the ANSI sequence for that to work consistently.
Cheers, M@
For example, both these statements
SRP_Array( 'SortSimpleList', 'OB_STATUS,OBJECT', 'AscendingText', ',')
SRP_Sort_Array( 'OB_STATUS,OBJECT', 'AL1', 1, ',')
both SortSimpleList and SRP_Sort_Array() return "OBJECT,OB_STATUS"
These functions, and OI's V119() and Locate By, use the ANSI sequence for ordering characters
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz
However - SortRows
SRP_Array( 'SortRows', 'OB_STATUS,OBJECT', 'AL1', 'LIST', ',')
returns the reverse order, "OB_STATUS,OBJECT"
It appears that 'SortRows' is using a different sequence for ordering these characters:
[\]^_`AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz
(The same is true for all older SRP Sort functions, as at v1.6. Perhaps this changed in v2.0.3?)
Notably, the underscore '_' precedes any alphabetic characters in this sequence.
The 'gotcha' is that if you are using OI's Locate By statement to insert into a pre-sorted list, that list should be sorted using the ANSI sequence for that to work consistently.
Cheers, M@
Comments
That being said, I do realize the documentation does not make this clear, mostly because I didn't realize V119 sorted this way. I'll update the documentation to be clearer on this point.
I guess you'll want to make the sorting sequencing consistent across SRP functions, one way or the other. Perhaps even add another parameter to the functions to indicate the sequencing scheme? Maybe you would only need OI sequencing if you were going to maintain the same array with Locate By statements.
I guess the C++ sort does in fact use ASCII order, so I'm gonna eat a slice of humble pie for a second here...
...now that I've had my fill, here's the reason SortRows is behaving differently from SortSimpleList. SortRows is not defaulting the CaseSensitive parameter to 1, but to "". As a result, SortRows is sorting case-insensitively by default whereas the other SRP sort functions are doing a case sensitive sort.
I've fixed SortRows for future releases. In the meantime, if you force the CaseSensitive parameter to 1, you'll get the expected sorting results.
Cheers, M@