Thread Tools Display Modes
08/21/15, 09:34 AM   #1
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
[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
 
08/21/15, 01:03 PM   #2
CrazyDutchGuy
 
CrazyDutchGuy's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 89
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 ...

Last edited by CrazyDutchGuy : 08/21/15 at 01:09 PM.
 
08/22/15, 06:57 AM   #3
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by CrazyDutchGuy View Post
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
 

ESOUI » Developer Discussions » Wish List » [outdated] strcmp, or a proper operator < on strings


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off