Fix bugs in search rule matching

This commit is contained in:
Justin Aquadro 2014-02-19 20:29:22 -05:00
parent d4ad1bd99a
commit c5debf12d4

View file

@ -169,26 +169,30 @@ namespace NBTExplorer.Model.Search
{ {
TagDataNode childNode = GetChild(container, Name); TagDataNode childNode = GetChild(container, Name);
T data = LookupTag<T>(container, Name); T data = LookupTag<T>(container, Name);
if (data == null)
return false;
if (data != null) { switch (Operator) {
switch (Operator) { case NumericOperator.Equals:
case NumericOperator.Equals: if (data.ToTagLong() != Value)
if (data.ToTagLong() != Value) return false;
return false; break;
break; case NumericOperator.NotEquals:
case NumericOperator.NotEquals: if (data.ToTagLong() == Value)
if (data.ToTagLong() == Value) return false;
return false; break;
break; case NumericOperator.GreaterThan:
case NumericOperator.GreaterThan: if (data.ToTagLong() <= Value)
if (data.ToTagLong() <= Value) return false;
return false; break;
break; case NumericOperator.LessThan:
case NumericOperator.LessThan: if (data.ToTagLong() >= Value)
if (data.ToTagLong() >= Value) return false;
return false; break;
break; case NumericOperator.Any:
} break;
default:
return false;
} }
if (!matchedNodes.Contains(childNode)) if (!matchedNodes.Contains(childNode))
@ -226,26 +230,30 @@ namespace NBTExplorer.Model.Search
{ {
TagDataNode childNode = GetChild(container, Name); TagDataNode childNode = GetChild(container, Name);
T data = LookupTag<T>(container, Name); T data = LookupTag<T>(container, Name);
if (data == null)
return false;
if (data != null) { switch (Operator) {
switch (Operator) { case NumericOperator.Equals:
case NumericOperator.Equals: if (data.ToTagDouble() != Value)
if (data.ToTagDouble() != Value) return false;
return false; break;
break; case NumericOperator.NotEquals:
case NumericOperator.NotEquals: if (data.ToTagDouble() == Value)
if (data.ToTagDouble() == Value) return false;
return false; break;
break; case NumericOperator.GreaterThan:
case NumericOperator.GreaterThan: if (data.ToTagDouble() <= Value)
if (data.ToTagDouble() <= Value) return false;
return false; break;
break; case NumericOperator.LessThan:
case NumericOperator.LessThan: if (data.ToTagDouble() >= Value)
if (data.ToTagDouble() >= Value) return false;
return false; break;
break; case NumericOperator.Any:
} break;
default:
return false;
} }
if (!matchedNodes.Contains(childNode)) if (!matchedNodes.Contains(childNode))
@ -276,34 +284,38 @@ namespace NBTExplorer.Model.Search
{ {
TagDataNode childNode = GetChild(container, Name); TagDataNode childNode = GetChild(container, Name);
TagNodeString data = LookupTag<TagNodeString>(container, Name); TagNodeString data = LookupTag<TagNodeString>(container, Name);
if (data == null)
return false;
if (data != null) { switch (Operator) {
switch (Operator) { case StringOperator.Equals:
case StringOperator.Equals: if (data.ToTagString().Data != Value)
if (data.ToTagString().Data != Value) return false;
return false; break;
break; case StringOperator.NotEquals:
case StringOperator.NotEquals: if (data.ToTagString().Data == Value)
if (data.ToTagString().Data == Value) return false;
return false; break;
break; case StringOperator.Contains:
case StringOperator.Contains: if (!data.ToTagString().Data.Contains(Value))
if (!data.ToTagString().Data.Contains(Value)) return false;
return false; break;
break; case StringOperator.NotContains:
case StringOperator.NotContains: if (data.ToTagString().Data.Contains(Value))
if (data.ToTagString().Data.Contains(Value)) return false;
return false; break;
break; case StringOperator.StartsWith:
case StringOperator.StartsWith: if (!data.ToTagString().Data.StartsWith(Value))
if (!data.ToTagString().Data.StartsWith(Value)) return false;
return false; break;
break; case StringOperator.EndsWith:
case StringOperator.EndsWith: if (!data.ToTagString().Data.EndsWith(Value))
if (!data.ToTagString().Data.EndsWith(Value)) return false;
return false; break;
break; case StringOperator.Any:
} break;
default:
return false;
} }
if (!matchedNodes.Contains(childNode)) if (!matchedNodes.Contains(childNode))