Esempio n. 1
0
        private void GetSegments(string route)
        {
            var rx = new Regex(@"^(?<isToken>{)?(?(isToken)(?<isGreedy>\*?))(?<name>[a-zA-Z0-9-_]+)(?(isToken)})$", RegexOptions.Compiled | RegexOptions.Singleline);
            foreach (string segment in route.Split('/'))
            {
                // segment must not be empty
                if (string.IsNullOrEmpty(segment))
                {
                    throw new ArgumentException("Route URL is invalid. Sequence \"//\" is not allowed.", "url");
                }

                if (rx.IsMatch(segment))
                {
                    var m = rx.Match(segment);
                    var s = new RouteSegment
                    {
                        IsToken = m.Groups["isToken"].Value.Length.Equals(1),
                        IsGreedy = m.Groups["isGreedy"].Value.Length.Equals(1),
                        Name = m.Groups["name"].Value
                    };
                    _segments.AddLast(s);
                    _hasGreedy |= s.IsGreedy;

                    continue;
                }
                throw new ArgumentException("Route URL is invalid.", "url");
            }
        }