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) ?
Amiga CompareStr()
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Amiga CompareStr()
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
CompareStr("á","a",False) /* 1 */
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()
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:
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"}
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"}
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Amiga CompareStr()
No, they don't use different methods of collation so looks there is something wrong...
Yeah, there's definitely something wrong here. I'll investigate
- airsoftsoftwair
- Posts: 5443
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Amiga CompareStr()
Well, actually, this isn't a bug in Hollywood but a case of RTFM
The documentation of Sort() says:
Then both problems will be gone.
The documentation of Sort() says:
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: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.
Code: Select all
Sort(a, Function(a, b) Return(CompareStr(a,b) = -1) EndFunction)