diff Modules/Utils.lua @ 8:0271e781b154

Working on converting the database to store items as links instead of names.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 23 Jun 2010 23:47:48 -0700
parents bbba2fae0f69
children 374dd1a90d02
line wrap: on
line diff
--- a/Modules/Utils.lua	Tue Jun 08 11:19:16 2010 -0700
+++ b/Modules/Utils.lua	Wed Jun 23 23:47:48 2010 -0700
@@ -14,7 +14,7 @@
 	return prefix .. Altoholic:GetMoneyString(abs(money), WHITE, false)
 end
 
-                   -- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called
+-- This is only here to make sure this doesn't blow up if ReplaceItemCache is never called
 local item_db = {}
 
 function addon:ReplaceItemCache(new_cache)
@@ -71,6 +71,17 @@
    return n
 end
 
+function addon:GetSafeLink(link)
+	if link ~= string.match(link, '.-:[-0-9]+[:0-9]*') then
+		link = link and string.match(link, "|H(.-):([-0-9]+):([0-9]+)|h")
+	end
+	return link and string.gsub(link, ":0:0:0:0:0:0", "")
+end
+
+function addon:GetIDFromLink(link)
+	local _, _, _, _, Id = string.find(link, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
+	return tonumber(Id)
+end
 
 function addon:GetDebug(info)
 	return true