-JsonPath++

This commit is contained in:
James Newton-King
2013-11-30 13:13:02 +13:00
parent 847e3e5ac2
commit cd0bc9591d
2 changed files with 0 additions and 54 deletions
@@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Newtonsoft.Json.Linq.JsonPath
{
internal class AndFilter : PathFilter
{
public List<PathFilter> Filters { get; set; }
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
{
foreach (PathFilter f in Filters)
{
current = f.ExecuteFilter(current, errorWhenNoMatch).ToList();
}
return current;
}
}
}
@@ -1,31 +0,0 @@
using System.Collections.Generic;
using System.Linq;
namespace Newtonsoft.Json.Linq.JsonPath
{
internal class OrFilter : PathFilter
{
public List<PathFilter> Filters { get; set; }
public override IEnumerable<JToken> ExecuteFilter(IEnumerable<JToken> current, bool errorWhenNoMatch)
{
List<JToken> cachedCurrent = current.ToList();
List<JToken> remaining = cachedCurrent.ToList();
List<JToken> matches = new List<JToken>();
int previousResultCount = 0;
foreach (PathFilter f in Filters)
{
matches.AddRange(f.ExecuteFilter(remaining, errorWhenNoMatch));
for (int i = previousResultCount; i < matches.Count; i++)
{
remaining.Remove(matches[i]);
}
previousResultCount = matches.Count;
}
return cachedCurrent.Where(matches.Contains);
}
}
}