Quantcast
Weird issues with string.match and encoding (I think) - WoWInterface
Thread Tools Display Modes
09-27-22, 03:43 PM   #1
casualfetzer
A Defias Bandit
Join Date: Sep 2022
Posts: 3
Weird issues with string.match and encoding (I think)

Hey,

I'm trying to do some string pattern matching to pull out an m+ key level from the description from a Group Finder posting. However the matching seems to get some fairly odd results

Here is a snippet of the code from within a hook function registered to the LFGListSearchEntry_Update event

Code:
function DWMShook_LFGListSearchEntry_Update(entry, ...)

    local name = entry.Name:GetText() or "";

    local key_level = strmatch(name, "(%d+)")
    --Show the matched string and the original string it was matched from
    print(format("%s - key_level, %s - name", key_level, name))

    --Check strmatch functionality on string literal (i.e. not string from
    --Blizzard API
    print(strmatch("+21", "(%d+)"))

end
And this outputs
Code:
445 - key_level, +15 - name
21
I've read somehwere that all strings returned from Blizz APIs are encoded as UTF-8 and I guess this might be causing an issue due to the variable width of the character codes in UTF-8. Anyone come across this kind of issue before is there something super obvious I am missing. Feels like I'm missing something or that I'm doing something dumb (or both)

Cheers,
Fetzer
  Reply With Quote
09-27-22, 06:29 PM   #2
casualfetzer
A Defias Bandit
Join Date: Sep 2022
Posts: 3
On further investigation i think it might be more to do with the data I'm trying to match being held on the C side of the API's and there must be some weird interaction with how that data is accessed behind the scenes that means it doesn't play nice with the string functions.

Does anyone know of any way to deep copy that data out into a new variable, sorry I'm very new to lua (like a week new)
  Reply With Quote
09-27-22, 08:22 PM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 645
The title and description of finder groups are protected using UI escape sequences similar to colors (|c|r), links (|H|h|h), textures (|T|t), and so on. Custom code cannot read it and there's no API available to translate it.

https://wowpedia.fandom.com/wiki/UI_...tected_strings

What your code is really seeing in your example is the string |Kr445|k and when it's printed or otherwise displayed by your code the UI formats it into the title you see which is +15. The number 445 is the 445th group your client has loaded to show you since the last time the client started; the number will continue to increase persistent across logouts and reloads until you exit the game. If you saved any chat messages mentioning the group name, such as a chat history addon, those group names will load as "Unknown" when you start the game since there is no longer a group with that ID in the C memory.

Last edited by Kanegasi : 09-27-22 at 08:27 PM.
  Reply With Quote
09-28-22, 01:34 AM   #4
casualfetzer
A Defias Bandit
Join Date: Sep 2022
Posts: 3
Brilliant thanks for the explanation, while I can't achieve what i wanted to I can now at least be happy that I'm not going mad

So in effect any of those protected strings can only be read by blizzard code which is why they render properly in the UI (including console print) but cannot be read or manipulated in any way by addon code

Cheers,
Fetzer
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Weird issues with string.match and encoding (I think)

Thread Tools
Display Modes

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