internal void Remove(XUri uri) { Remove(uri.GetSegments(UriPathFormat.Normalized), 0); }
internal List <DreamFeature> Find(XUri uri) { return(Find(uri.GetSegments(UriPathFormat.Normalized), 0)); }
//--- Class Methods --- private static void ParseFeatureSignature(XUri baseUri, string signature, out string[] pathSegments, out KeyValuePair <int, string>[] paramNames, out int optional) { List <string> segments = new List <string>(baseUri.GetSegments(UriPathFormat.Normalized)); List <KeyValuePair <int, string> > names = new List <KeyValuePair <int, string> >(); optional = 0; // normalize and remove any leading and trailing '/' signature = signature.ToLowerInvariant().Trim(); if ((signature.Length > 0) && (signature[0] == '/')) { signature = signature.Substring(1); } if ((signature.Length > 0) && (signature[signature.Length - 1] == '/')) { signature = signature.Substring(0, signature.Length - 1); } if (signature.Length > 0) { string[] parts = signature.Split('/'); // loop over all parts for (int i = 0; i < parts.Length; ++i) { // check if part is empty (this only happens for "//") if (parts[i].Length == 0) { // we found two slashes in a row; the next token MUST be the final token if ((i != (parts.Length - 2)) || (parts[i + 1] != "*")) { throw new ArgumentException("invalid feature signature", signature); } optional = int.MaxValue; break; } else { string part = parts[i].Trim(); if ((part.Length >= 2) && (part[0] == '{') && (part[part.Length - 1] == '}')) { // we have a path variable (e.g. /{foo}/) if (optional != 0) { throw new ArgumentException("invalid feature signature", signature); } segments.Add(SysUtil.NameTable.Add("*")); names.Add(new KeyValuePair <int, string>(baseUri.Segments.Length + i, SysUtil.NameTable.Add(part.Substring(1, part.Length - 2)))); } else if (part == "*") { // we have a path wildcard (e.g. /*/) if (optional != 0) { throw new ArgumentException("invalid feature signature", signature); } segments.Add(SysUtil.NameTable.Add(part)); names.Add(new KeyValuePair <int, string>(baseUri.Segments.Length + i, SysUtil.NameTable.Add(i.ToString()))); } else if (part == "?") { // we have an optional path (e.g. /?/) ++optional; segments.Add(SysUtil.NameTable.Add(part)); } else { // we have a path constant (e.g. /foo/) if (optional != 0) { throw new ArgumentException("invalid feature signature", signature); } segments.Add(SysUtil.NameTable.Add(part)); } } } } pathSegments = segments.ToArray(); paramNames = names.ToArray(); }