ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Wish List (https://www.esoui.com/forums/forumdisplay.php?f=177)
-   -   [outdated] strcmp, or a proper operator < on strings (https://www.esoui.com/forums/showthread.php?t=5038)

merlight 08/21/15 09:34 AM

[outdated] strcmp, or a proper operator < on strings
 
Operator < on strings in ESO-Lua ignores everything except letters and digits. It's useless for sorting strings containing spaces and/or punctuation, as it doesn't define a total order.

Examples:
Lua Code:
  1. "a" < "A" == true
  2. "b" < "A" == false
  3. "A" < "a" == false
  4. "B" < "c" == true
  5. -- interesting, the order is: "a", "A", "b", "B", "c", ...
  6. -- that's nice, actually
  7.  
  8. "aa" < "A" == false
  9. "aa" < "Aa" == true
  10. -- more surprises, the order is: "a", "aa", "aA", "Aa", "AA", ...
  11. -- but still fine
  12.  
  13. "a head" < "ahead" == false
  14. "ahead" < "a head" == false
  15. -- they're not equal, yet neither is less than the other
  16. -- this is bad, table.sort will not give consistent order
  17.  
  18. "#" < "~" == false
  19. "~" < "#" == false
  20. -- it doesn't compare the characters at all

CrazyDutchGuy 08/21/15 01:03 PM

I assume the sorting is based on type, then the order with base 36 as next
0123456789abcdefghijklmnopqrstuvwxyz, if they are equal then sorting is based on case ?

comparing other values would likely produce a nil value as it can't convert it to a number for comaprison, which leads to a nil, which leads to type inequality, which leads to false, if it all makes sense somehow
"a head" < "ahead" == false --> nil < 17607829
"ahead" < "a head" == false --> 17607829 < nil

Anyways, it looks weird :P
aa == 370 -> (36^1)*10 + (36^0)*10
aaa == 13330 -> (36^2)*10 + aa
and so on ...

merlight 08/22/15 06:57 AM

Quote:

Originally Posted by CrazyDutchGuy (Post 22874)
I assume the sorting is based on type, then the order with base 36 as next
0123456789abcdefghijklmnopqrstuvwxyz, if they are equal then sorting is based on case ?

comparing other values would likely produce a nil value as it can't convert it to a number for comaprison, which leads to a nil, which leads to type inequality, which leads to false, if it all makes sense somehow

The default operator < in Lua requires that both operands are of the same type:
http://www.lua.org/source/5.1/lvm.c.html#luaV_lessthan

Strings are compared using strcoll:
http://www.lua.org/source/5.1/lvm.c.html#l_strcmp

What we have in ESO is some custom-made string comparison. Perhaps it supports multi-byte UTF-8 characters, I haven't checked that. It doesn't support ASCII punctuation, that's broken enough in my eyes ;)


All times are GMT -6. The time now is 02:43 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI