LibItemSearch

This commit is contained in:
Bunny67
2018-01-12 01:22:57 +03:00
parent 5dd6eccd72
commit 2d223bef31
7 changed files with 48 additions and 37 deletions
@@ -23,6 +23,7 @@ if not Lib then
return
end
local lower = string.lower
--[[ Parsing ]]--
@@ -36,7 +37,7 @@ function Lib:Matches(object, search, filters)
end
function Lib:MatchAll(search)
for phrase in self:Clean(search):gmatch('[^&]+') do
for phrase in gmatch(self:Clean(search), '[^&]+') do
if not self:MatchAny(phrase) then
return
end
@@ -46,7 +47,7 @@ function Lib:MatchAll(search)
end
function Lib:MatchAny(search)
for phrase in search:gmatch('[^|]+') do
for phrase in gmatch(search, '[^|]+') do
if self:Match(phrase) then
return true
end
@@ -54,13 +55,13 @@ function Lib:MatchAny(search)
end
function Lib:Match(search)
local tag, rest = search:match('^%s*(%S+):(.*)$')
local tag, rest = match(search, '^%s*(%S+):(.*)$')
if tag then
tag = '^' .. tag
search = rest
end
local words = search:gmatch('%S+')
local words = gmatch(search, '%S+')
local failed
for word in words do
@@ -72,7 +73,7 @@ function Lib:Match(search)
end
else
local negate, rest = word:match('^([!~]=*)(.*)$')
local negate, rest = match(word, '^([!~]=*)(.*)$')
if negate or word == self.NOT_MATCH then
word = rest and rest ~= '' and rest or words() or ''
negate = -1
@@ -80,7 +81,7 @@ function Lib:Match(search)
negate = 1
end
local operator, rest = word:match('^(=*[<>]=*)(.*)$')
local operator, rest = match(word, '^(=*[<>]=*)(.*)$')
if operator then
word = rest ~= '' and rest or words()
end
@@ -106,7 +107,7 @@ function Lib:Filter(tag, operator, search)
if tag then
for _, filter in pairs(self.filters) do
for _, value in pairs(filter.tags or {}) do
if value:find(tag) then
if find(value, tag) then
return self:UseFilter(filter, operator, search)
end
end
@@ -123,7 +124,7 @@ end
function Lib:UseFilter(filter, operator, search)
local data = {filter:canSearch(operator, search, self.object)}
if data[1] then
return filter:match(self.object, operator, unpack(data))
return match(filter, self.object, operator, unpack(data))
end
end
@@ -131,20 +132,20 @@ end
--[[ Utilities ]]--
function Lib:Find(search, ...)
for i = 1, select('#', ...) do
local text = select(i, ...)
if text and self:Clean(text):find(search) then
for i = 1, getn(arg) do
local text = arg[i]
if text and find(self:Clean(text), search) then
return true
end
end
end
function Lib:Clean(string)
string = string:lower()
string = string:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', function(c) return '%'..c end)
string = lower(string)
string = gsub(string, '[%(%)%.%%%+%-%*%?%[%]%^%$]', function(c) return '%'..c end)
for accent, char in pairs(self.ACCENTS) do
string = string:gsub(accent, char)
string = gsub(string, accent, char)
end
return string
@@ -152,16 +153,16 @@ end
function Lib:Compare(op, a, b)
if op then
if op:find('<') then
if op:find('=') then
if find(op, '<') then
if find(op, '=') then
return a <= b
end
return a < b
end
if op:find('>')then
if op:find('=') then
if find(op, '>')then
if find(op, '=') then
return a >= b
end
@@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="CustomSearch-1.0.lua"/>
</Ui>
@@ -12,6 +12,8 @@ else
return;
end
local strmatch, lower = string.match, string.lower
--[[ User API ]]--
function Lib:Matches(link, search)
@@ -19,17 +21,17 @@ function Lib:Matches(link, search)
end
function Lib:Tooltip(link, search)
return link and self.Filters.tip:match(link, nil, search);
return link and strmatch(self.Filters.tip, link, nil, search);
end
function Lib:TooltipPhrase(link, search)
return link and self.Filters.tipPhrases:match(link, nil, search);
return link and strmatch(self.Filters.tipPhrases, link, nil, search);
end
function Lib:InSet(link, search)
if(IsEquippableItem(link)) then
local id = tonumber(link:match("item:(%-?%d+)"));
return self:BelongsToSet(id, (search or ""):lower());
local id = tonumber(strmatch(link, "item:(%-?%d+)"));
return self:BelongsToSet(id, lower(search or ""));
end
end
@@ -43,7 +45,7 @@ Lib.Filters.name = {
end,
match = function(self, item, _, search)
local name = item:match("%[(.-)%]");
local name = strmatch(item, "%[(.-)%]");
return Search:Find(search, name);
end
};
@@ -94,8 +96,8 @@ Lib.Filters.requiredlevel = {
--[[ Quality ]]--
local qualities = {};
for i = 0, #ITEM_QUALITY_COLORS do
qualities[i] = _G["ITEM_QUALITY" .. i .. "_DESC"]:lower();
for i = 0, getn(ITEM_QUALITY_COLORS) do
qualities[i] = lower(_G["ITEM_QUALITY" .. i .. "_DESC"]);
end
Lib.Filters.quality = {
@@ -103,7 +105,7 @@ Lib.Filters.quality = {
canSearch = function(self, _, search)
for i, name in pairs(qualities) do
if(name:find(search)) then
if(find(namesearch)) then
return i;
end
end
@@ -146,7 +148,7 @@ Lib.Filters.tip = {
end,
match = function(self, link, _, search)
if(link:find("item:")) then
if(find(link, "item:")) then
scanner:SetOwner(UIParent, "ANCHOR_NONE");
scanner:SetHyperlink(link)
@@ -166,7 +168,7 @@ local escapes = {
local function CleanString(str)
for k, v in pairs(escapes) do
str = str:gsub(k, v);
str = string.gsub(str, k, v);
end
return str;
end
@@ -177,7 +179,7 @@ Lib.Filters.tipPhrases = {
end,
match = function(self, link, _, search)
local id = link:match("item:(%d+)");
local id = strmatch(link, "item:(%d+)");
if(not id) then
return;
end
@@ -207,13 +209,12 @@ Lib.Filters.tipPhrases = {
cache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end}),
keywords = {
[ITEM_SOULBOUND:lower()] = ITEM_BIND_ON_PICKUP,
[lower(ITEM_SOULBOUND)] = ITEM_BIND_ON_PICKUP,
["bound"] = ITEM_BIND_ON_PICKUP,
["bop"] = ITEM_BIND_ON_PICKUP,
["boe"] = ITEM_BIND_ON_EQUIP,
["bou"] = ITEM_BIND_ON_USE,
["boa"] = ITEM_BIND_TO_ACCOUNT,
[QUESTS_LABEL:lower()] = ITEM_BIND_QUEST
};
};
@@ -225,7 +226,7 @@ if IsAddOnLoaded("ItemRack") then
function Lib:BelongsToSet(id, search)
for name, set in pairs(ItemRackUser.Sets) do
if name:sub(1,1) ~= "" and Search:Find(search, name) then
if string.sub(name,1,1) ~= "" and Search:Find(search, name) then
for _, item in pairs(set.equip) do
if sameID(id, item) then
return true
@@ -1,6 +1,6 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="CustomSearch-1.0\CustomSearch-1.0.lua"/>
<Script file="Unfit-1.0\Unfit-1.0.lua"/>
<Include file="CustomSearch-1.0\CustomSearch-1.0.xml"/>
<Include file="Unfit-1.0\Unfit-1.0.xml"/>
<Script file="LibItemSearch-1.2.lua"/>
</Ui>
@@ -97,9 +97,9 @@ end
--[[ API ]]--
function Lib:IsItemUnusable(...)
if ... then
local subclass, _, slot = select(7, GetItemInfo(...))
function Lib:IsItemUnusable(arg1)
if arg1 then
local subclass, _, slot = select(7, GetItemInfo(arg1))
return Lib:IsClassUnusable(subclass, slot)
end
end
@@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file="Unfit-1.0.lua"/>
</Ui>
@@ -21,4 +21,5 @@
<Include file="LibBase64-1.0\LibBase64-1.0.xml"/>
<Include file="LibAnim\LibAnim.xml"/>
<Include file="LibUIDropDownMenu\LibUIDropDownMenu.xml"/>
<Include file="LibItemSearch-1.2\LibItemSearch-1.2.xml"/>
</Ui>