Ejemplo n.º 1
0
 public virtual void Exit()
 {
     onRouteExit?.Invoke();
     match = default;
     match.matchProgress = -1;
     SetEnabled(false);
 }
Ejemplo n.º 2
0
 public virtual bool TryMatch(RouteMatch match, out RouteMatch result)
 {
     if (path == null)
     {
         result = default;
         result.matchProgress = -1;
         return(false);
     }
     result = RouteMatch.Match(path, match);
     return(result.IsMatch);
 }
Ejemplo n.º 3
0
        public override bool TryMatch(RouteMatch match, out RouteMatch result)
        {
            if (guardFn == null || !guardFn())
            {
                result = default(RouteMatch);
                result.matchProgress = -1;
                return(false);
            }

            return(base.TryMatch(match, out result));
        }
Ejemplo n.º 4
0
 protected void HandleParentRouteEnter()
 {
     if (string.IsNullOrEmpty(path))
     {
         Enter(parentRoute.CurrentMatch);
     }
     else
     {
         match = RouteMatch.Match(FullPath, 0, new RouteMatch(parentRoute.CurrentMatch.url));
         if (match.IsMatch)
         {
             Enter(match);
         }
     }
 }
Ejemplo n.º 5
0
 public override void Enter(RouteMatch route)
 {
     base.Enter(route);
     RouteElement[] routes = m_ChildRoutes.Array;
     for (int i = 0; i < m_ChildRoutes.Count; i++)
     {
         RouteMatch childMatch;
         if (routes[i].TryMatch(route, out childMatch))
         {
             activeChild = routes[i];
             routes[i].Enter(childMatch);
             break;
         }
     }
 }
Ejemplo n.º 6
0
        protected void HandleParentRouteUpdate()
        {
            bool wasMatched = IsRouteMatched;

            match = RouteMatch.Match(FullPath, 0, new RouteMatch(parentRoute.CurrentMatch.url));

            if (!wasMatched && match.IsMatch)
            {
                Enter(match);
            }
            else if (wasMatched && !match.IsMatch)
            {
                Exit();
            }
            else if (wasMatched && match.IsMatch)
            {
                RouteMatch route = string.IsNullOrEmpty(path) ? parentRoute.CurrentMatch : CurrentMatch;
                Update(route); // todo -- not sure about this
                RouteElement[] routes = m_ChildRoutes.Array;
                for (int i = 0; i < m_ChildRoutes.Count; i++)
                {
                    RouteMatch childMatch;
                    if (routes[i].TryMatch(route, out childMatch))
                    {
                        if (activeChild == routes[i])
                        {
                            activeChild.Update(childMatch);
                            return;
                        }

                        activeChild?.Exit();
                        activeChild = routes[i];
                        activeChild.Enter(childMatch);
                        onRouteChanged?.Invoke();
                        return;
                    }
                }

                if (activeChild != null)
                {
                    activeChild.Exit();
                    activeChild = null;
                }

                onRouteChanged?.Invoke();
            }
        }
Ejemplo n.º 7
0
        public static RouteMatch Match(string path, int ptr, RouteMatch toMatch)
        {
            RouteMatch clone = toMatch;

            if (path == null)
            {
                clone.matchProgress = -1;
                return(clone);
            }

            while (clone.IsMatch && ptr < path.Length)
            {
                clone = MatchSegment(ref ptr, path, clone);
            }

            return(clone);
        }
Ejemplo n.º 8
0
        public static RouteMatch MatchSegment(ref int ptr, string path, RouteMatch toMatch)
        {
            int matchPtr = toMatch.matchProgress;

            while (ptr < path.Length)
            {
                char current = path[ptr];

                if (matchPtr >= toMatch.url.Length)
                {
                    toMatch.matchProgress = -1;
                    return(toMatch);
                }

                char matchCurrent = toMatch.url[matchPtr];

                if (current == matchCurrent)
                {
                    ptr++;
                    matchPtr++;
                    continue;
                }

                if (current == ':')
                {
                    ptr++;
                    if (ptr == path.Length)
                    {
                        throw new ParseException();
                    }

                    string name  = ReadRouteSectionContents(ref ptr, path);
                    string value = ReadRouteSectionContents(ref matchPtr, toMatch.url);
                    toMatch.SetParameter(name, value);
                    continue;
                }

                toMatch.matchProgress = -1;
                return(toMatch);
            }

            toMatch.matchProgress = matchPtr;

            return(toMatch);
        }
Ejemplo n.º 9
0
 public static RouteMatch Match(string path, RouteMatch toMatch)
 {
     return(Match(path, 0, toMatch));
 }
Ejemplo n.º 10
0
 public override bool TryMatch(RouteMatch match, out RouteMatch result)
 {
     result = RouteMatch.Match(FullPath, 0, match);
     return(result.IsMatch);
 }
Ejemplo n.º 11
0
 public void Update(RouteMatch match)
 {
     this.match = match;
     onRouteUpdate?.Invoke();
 }
Ejemplo n.º 12
0
 public virtual void Enter(RouteMatch match)
 {
     this.match = match;
     onRouteEnter?.Invoke();
     SetEnabled(true);
 }