WeakAuras

WeakAuras

206M Downloads

Can not get chinese charactors by new function of WeakAuras.GetMHTenchInfo()

roundzero opened this issue ยท 4 comments

commented

Description

After typing /dump WeakAuras.GetMHTenchInfo() , it returns unknown about enchanted name.
This issue caused by the factor which one chinese charactor occupies two bytes.

WeakAuras Version

3.6.1-2-gef69528

World of Warcraft Flavor

The Burning Crusade

Tested with only WeakAuras

  • Yes
  • No

Lua Error

No response

Reproduction Steps

  1. /dump WeakAuras.GetMHTenchInfo()
  2. no enchanted name returns
    WowClassic_o5nfrzh7vE
    WowClassic_96Zcq7RA7S

Last Good Version

No response

Screenshots

WowClassic_o5nfrzh7vE
WowClassic_96Zcq7RA7S

Export String

No response

commented

i try fix this original code by Aura Frames1
Libs\LibAura-1.0\WeaponEnchantments.lua#L58-L85

local patterns = {}
local gsubPatterns = "([^|]+)[|][4]([^:]+):([^;]+);(.*)"
local function SetupWeaponEnchantPatterns()
    local temp = {
        ITEM_ENCHANT_TIME_LEFT_HOURS, ITEM_ENCHANT_TIME_LEFT_MIN,
        ITEM_ENCHANT_TIME_LEFT_SEC
    }
    for i, v in pairs(temp) do
        local raw_i = (i * 2)
        patterns[raw_i - 1], patterns[raw_i] =
            v:gsub(gsubPatterns, "%1%2%4")
        if patterns[raw_i] ~= 0 then
            patterns[raw_i] = v:gsub(gsubPatterns, "%1%3%4")
        else
            patterns[raw_i] = nil
        end
    end
    for i = 1, (#temp) * 2 do
        local temp
        if patterns[i] then
            patterns[i] = patterns[i]:gsub("%((.+)%)", "%%(%1%%)"):gsub(
                              "%%s", "(.+)"):gsub("%%d", "%%d+")
        end
    end
end
SetupWeaponEnchantPatterns()

local function GetWeaponEnchantText(text)
    local _, enchantText
    for i, v in pairs(patterns) do
        _, _, enchantText = text:find(v)
        if enchantText then return enchantText end
    end
end
commented

i try fix this original code by Aura Frames1
Libs\LibAura-1.0\WeaponEnchantments.lua#L58-L85

local patterns = {}
local gsubPatterns = "([^|]+)[|][4]([^:]+):([^;]+);(.*)"
local function SetupWeaponEnchantPatterns()
    local temp = {
        ITEM_ENCHANT_TIME_LEFT_HOURS, ITEM_ENCHANT_TIME_LEFT_MIN,
        ITEM_ENCHANT_TIME_LEFT_SEC
    }
    for i, v in pairs(temp) do
        local raw_i = (i * 2)
        patterns[raw_i - 1], patterns[raw_i] =
            v:gsub(gsubPatterns, "%1%2%4")
        if patterns[raw_i] ~= 0 then
            patterns[raw_i] = v:gsub(gsubPatterns, "%1%3%4")
        else
            patterns[raw_i] = nil
        end
    end
    for i = 1, (#temp) * 2 do
        local temp
        if patterns[i] then
            patterns[i] = patterns[i]:gsub("%((.+)%)", "%%(%1%%)"):gsub(
                              "%%s", "(.+)"):gsub("%%d", "%%d+")
        end
    end
end
SetupWeaponEnchantPatterns()

local function GetWeaponEnchantText(text)
    local _, enchantText
    for i, v in pairs(patterns) do
        _, _, enchantText = text:find(v)
        if enchantText then return enchantText end
    end
end

It works.

commented

@q513902026 that addon is under a ARR license. Please do not suggest stealing code from a addon.

commented

i mean.just example