Page 1 of 1
Amiga CompareStr()
Posted: Wed May 29, 2019 11:44 pm
by lazi
This is ok:
CompareStr("Amiga","pc",False) /* -1 */
These two are wrong:
CompareStr("álma","alma",False) /* 0 */
CompareStr("á","a",False) /* 1 */
Should it work on Amiga (codesets.library) ?
Re: Amiga CompareStr()
Posted: Thu May 30, 2019 7:13 pm
by airsoftsoftwair
Actually, this isn't wrong:
"á" is greater than "a" so this is right, but the other one is definitely wrong. It's fixed now. Unfortunately, codesets.library doesn't offer any collation capabilities so Hollywood uses a custom algorithm on Amiga/Linux/Android.
Code: Select all
- Fix [Amiga/Linux/Android]: Unicode sorting in CompareStr() and Sort() didn't work correctly for words
which only differ in their diacritics
Re: Amiga CompareStr()
Posted: Sun Sep 29, 2019 9:06 pm
by lazi
I wonder that why Sort and CompareStr uses different method of collation?
The 7.0 history said about this: - New:
Sort() supports full Unicode collation now.
Edit:
Is it resolved by the fix you mentioned? Just realized that fix is not public yet.
Here are a simple test:
Code: Select all
SetFont(#SANS,20)
a={"abcd","ábcd","adcb"}
Sort(a)
for i,v in ipairs(a)
nprint(i,v)
next
NPrint("")
Sort(a,CompareStr)
for i,v in ipairs(a)
nprint(i,v)
next
WaitLeftMouse
The Sort(a) result, which is faulty:
ábcd
abcd
adcb
The Sort(a,CompareStr) result is correct:
abcd
adcb
ábcd
Other question is why drops me an "Invalid orderfunction for sorting" error when a fourth string is added to the array?
a={"abcd","ábcd","adcb","abce"}
Re: Amiga CompareStr()
Posted: Tue Oct 01, 2019 12:18 am
by airsoftsoftwair
lazi wrote: ↑Sun Sep 29, 2019 9:06 pm
I wonder that why Sort and CompareStr uses different method of collation?
No, they don't use different methods of collation so looks there is something wrong...
lazi wrote: ↑Sun Sep 29, 2019 9:06 pm
Other question is why drops me an "Invalid orderfunction for sorting" error when a fourth string is added to the array?
a={"abcd","ábcd","adcb","abce"}
Yeah, there's definitely something wrong here. I'll investigate
Re: Amiga CompareStr()
Posted: Fri Dec 13, 2019 6:03 pm
by airsoftsoftwair
Well, actually, this isn't a bug in Hollywood but a case of RTFM
The documentation of
Sort() says:
Starting with Hollywood 4.5, you can customize the sorting operation by using a custom sort callback. This function has to accept two parameters and it has to return if the first parameter should be inserted before the second one or not. This gives you great flexibility in setting up custom sort operations because you can compare arbitrary values and you can also customize the sorting order.
So your callback function is expected to return either TRUE or FALSE, but not [-1,0,1] as done by
CompareStr(). So the code needs to be fixed like this:
Code: Select all
Sort(a, Function(a, b) Return(CompareStr(a,b) = -1) EndFunction)
Then both problems will be gone.