From 0bbd6b6a4e5bd1c77ef72246af0bb46d89105802 Mon Sep 17 00:00:00 2001 From: Kevin Lyles Date: Sat, 12 Sep 2009 12:15:27 -0500 Subject: [PATCH] Added preprocessing to eliminate color codes from text Still double parsing --- Regexps.lua | 5 +++++ WeightsWatcher.lua | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Regexps.lua b/Regexps.lua index 290a4f3..e5aa0ab 100644 --- a/Regexps.lua +++ b/Regexps.lua @@ -1,3 +1,8 @@ +Preprocess = { + {"(.*)|r$", "%1"}, + {"^|c[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9](.*)", "%1"}, +} + ProcessedLines = { "%+(%d+) (%a[%a ]+)" } diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua index 5207bb1..c6124c3 100644 --- a/WeightsWatcher.lua +++ b/WeightsWatcher.lua @@ -82,7 +82,8 @@ function DisplayItemInfo(tooltip, ttname) start = 2 end for i = start, tooltip:NumLines() do - text = getglobal(ttname .. "TextLeft" .. i):GetText() + text = WeightsWatcher:preprocess(getglobal(ttname .. "TextLeft" .. i):GetText()) + for _, regex in pairs(ProcessedLines) do start, _, value, name = string.find(text, regex) if start then @@ -93,3 +94,16 @@ function DisplayItemInfo(tooltip, ttname) tooltip:Show() end end + +function WeightsWatcher:preprocess(text) + local pattern, replacement + + for _, regex in pairs(Preprocess) do + pattern, replacement = unpack(regex) + if string.find(text, pattern) then + text = gsub(text, pattern, replacement) + end + end + + return text +end -- 1.7.9.5