Warcraft III resources & community, 2003–2006 · archived

HighlightHotkey

not rated
Submitted by PepparText Parsing0 downloads
Highlights the first occurence of a given hotkey inside whichString (case insensitive) with color string color. If hotkey isn't found inside the string then the hotkey is appended and colored inside parenthesis at the end of the string.

If color is null then the default yellow color is applied ("ffffcc00")

HilightHotkey("Armageddon", 'a', "ffaabbcc") = "|cffaabbccA|rrmageddon"
HilightHotkey("Death Coil", 'u', "ff666666") = "Death Coil (|cff666666U|r)"
HilightHotkey("JASS", 's', null) = "JA|cffffcc00S|rS"

Requires: AsciiIntegerToChar

Source

function HighlightHotkey takes string whichString, integer hotkey, string color returns string
    local string s = StringCase(whichString, true)
    local string c
    local string hkey = StringCase(AsciiIntegerToChar(hotkey), true)
    local integer i = 0
    if whichString == null or hkey == null or hkey == "" then
        return whichString
    elseif color == null then
        set color = "ffffcc00"
    endif
    loop
        set c = SubString(s, i, i + 1)
        exitwhen c == ""
        if c == hkey then
            return SubString(whichString, 0, i) + "|c" + color + SubString(whichString, i, i + 1) + "|r" + SubString(whichString, i + 1, 0x10000)
        endif
        set i = i + 1
    endloop
    return whichString + " (|c" + color + hkey + "|r)"
endfunction

Comments

0

No comments.