Page 1 of 1

UTF8 characters with HaveItem

Posted: Thu Nov 02, 2023 8:55 am
by jPV
HaveItem() doesn't find string indices that contain non-english or some special characters if the script is run in the default UTF-8 mode. If you save the file as ASCII and add "@OPTIONS {Encoding = #ENCODING_ISO8859_1}" in the beginning, then it works just fine with the same characters.

I think that if a character is a two-byte UTF-8 character then it doesn't work, but if it's ASCII character then it works even if it'd be a special character like "@" which is represented with a single byte even in UTF-8.

Is this something fixable?

Code: Select all

t = {}

t["ä"] = "test-ä"
DebugPrint(t["ä"])           ; Works
DebugPrint(RawGet(t, "ä"))   ; Works
DebugPrint(HaveItem(t, "ä")) ; Doesn't work

t["®"] = "test-®"
DebugPrint(t["®"])           ; Works
DebugPrint(RawGet(t, "®"))   ; Works
DebugPrint(HaveItem(t, "®")) ; Doesn't work

t["@"] = "test-@"
DebugPrint(t["@"])           ; Works
DebugPrint(RawGet(t, "@"))   ; Works
DebugPrint(HaveItem(t, "@")) ; Works

Re: UTF8 characters with HaveItem

Posted: Fri Nov 03, 2023 11:10 pm
by airsoftsoftwair
jPV wrote: Thu Nov 02, 2023 8:55 am Is this something fixable?
Sure. Thanks for the MCVE. Will be fixed.

Re: UTF8 characters with HaveItem

Posted: Sat Jul 20, 2024 4:15 pm
by airsoftsoftwair

Code: Select all

- Fix: HaveItem() didn't work correctly with non-ASCII characters when using UTF-8 as the script encoding