Quantcast

Added preprocessing to eliminate color codes from text

Kevin Lyles [09-12-09 - 17:15]
Added preprocessing to eliminate color codes from text

Still double parsing
Filename
Regexps.lua
WeightsWatcher.lua
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