WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Weird issues with string.match and encoding (I think) (https://www.wowinterface.com/forums/showthread.php?t=59238)

casualfetzer 09-27-22 03:43 PM

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

casualfetzer 09-27-22 06:29 PM

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)

Kanegasi 09-27-22 08:22 PM

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.

casualfetzer 09-28-22 01:34 AM

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


All times are GMT -6. The time now is 02:29 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI