﻿// Decompiled with JetBrains decompiler
// Type: Mono.Xml.XPath.LocationPathPattern
// Assembly: System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
// MVID: B96316B8-9B8D-4ED8-8305-8C4F91B6775A
// Assembly location: C:\Users\CGA Computer\Desktop\LEGO Universe Stuff\LOCO Server\Unity Web Player Extractor\Saved Files\LOCO Server.unity3d_unpacked\System.Xml.dll

using Mono.Xml.Xsl;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace Mono.Xml.XPath
{
  internal class LocationPathPattern : Pattern
  {
    private LocationPathPattern patternPrevious;
    private bool isAncestor;
    private NodeTest nodeTest;
    private ExprFilter filter;

    public override double DefaultPriority
    {
      get
      {
        if (this.patternPrevious != null || this.filter != null)
          return 0.5;
        NodeNameTest nodeNameTest = this.nodeTest as NodeNameTest;
        if (nodeNameTest == null)
          return -0.5;
        return nodeNameTest.Name.Name == "*" || nodeNameTest.Name.Name.Length == 0 ? -0.25 : 0.0;
      }
    }

    public override XPathNodeType EvaluatedNodeType
    {
      get
      {
        return this.nodeTest.EvaluatedNodeType;
      }
    }

    public LocationPathPattern LastPathPattern
    {
      get
      {
        LocationPathPattern locationPathPattern = this;
        while (locationPathPattern.patternPrevious != null)
          locationPathPattern = locationPathPattern.patternPrevious;
        return locationPathPattern;
      }
    }

    public LocationPathPattern(NodeTest nodeTest)
    {
      this.nodeTest = nodeTest;
    }

    public LocationPathPattern(ExprFilter filter)
    {
      this.filter = filter;
      while (!(filter.expr is NodeTest))
        filter = (ExprFilter) filter.expr;
      this.nodeTest = (NodeTest) filter.expr;
    }

    internal void SetPreviousPattern(Pattern prev, bool isAncestor)
    {
      LocationPathPattern lastPathPattern = this.LastPathPattern;
      lastPathPattern.patternPrevious = (LocationPathPattern) prev;
      lastPathPattern.isAncestor = isAncestor;
    }

    public override bool Matches(XPathNavigator node, XsltContext ctx)
    {
      if (!this.nodeTest.Match((IXmlNamespaceResolver) ctx, node) || this.nodeTest is NodeTypeTest && ((NodeTypeTest) this.nodeTest).type == XPathNodeType.All && (node.NodeType == XPathNodeType.Root || node.NodeType == XPathNodeType.Attribute))
        return false;
      if (this.filter == null && this.patternPrevious == null)
        return true;
      if (this.patternPrevious != null)
      {
        XPathNavigator navCache = ((XsltCompiledContext) ctx).GetNavCache((Pattern) this, node);
        if (!this.isAncestor)
        {
          navCache.MoveToParent();
          if (!this.patternPrevious.Matches(navCache, ctx))
            return false;
        }
        else
        {
          while (navCache.MoveToParent())
          {
            if (this.patternPrevious.Matches(navCache, ctx))
              goto label_11;
          }
          return false;
        }
      }
label_11:
      if (this.filter == null)
        return true;
      if (!this.filter.IsPositional && !(this.filter.expr is ExprFilter))
        return this.filter.pred.EvaluateBoolean((BaseIterator) new NullIterator(node, (IXmlNamespaceResolver) ctx));
      XPathNavigator navCache1 = ((XsltCompiledContext) ctx).GetNavCache((Pattern) this, node);
      navCache1.MoveToParent();
      BaseIterator baseIterator = this.filter.EvaluateNodeSet((BaseIterator) new NullIterator(navCache1, (IXmlNamespaceResolver) ctx));
      while (baseIterator.MoveNext())
      {
        if (node.IsSamePosition(baseIterator.Current))
          return true;
      }
      return false;
    }

    public override string ToString()
    {
      string str = string.Empty;
      if (this.patternPrevious != null)
        str = this.patternPrevious.ToString() + (!this.isAncestor ? "/" : "//");
      return this.filter == null ? str + this.nodeTest.ToString() : str + this.filter.ToString();
    }
  }
}
