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
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

  • SRP_Sort_Array uses standard C++ sorting rules while OI does ordinal sorting. That puts me between a rock and a hard place. I'd argue that standard sorting is what most people desire since it is how most other languages and systems sort. If I go with ordinal sorting, I would be more compatible with OI, but then we'd be counter to most everything else out there.

    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.
  • Interesting! I got the impression that you were moving toward OI ANSI ordinal sorting as SortRows is the only SRP function that still uses standard C++ sorting now. In v1.6, all SRP sorting was standard C++. I hadn't noticed the difference between that an OI until now ;).

    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.
  • Okay. I was way off here.

    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.
  • Ah ha! So the CaseSensitive parameter is that parameter the changes the sorting sequence. That makes sense now that I look at those sequences harder ;)

    Cheers, M@
Sign In or Register to comment.