/// <summary> /// Match the given URI to a dictionary of variable values. Keys in the returned map are variable names, /// values are variable values, as occurred in the given URI /// </summary> /// <example> /// <code> /// UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}"); /// Console.Out.WriteLine(template.Match("http://example.com/hotels/1/bookings/42")); /// </code> /// will print: <blockquote>{hotel=1, booking=42}</blockquote> /// </example> /// <param name="uri">The URI to match to.</param> /// <returns>A dictionary of variable values.</returns> public IDictionary <string, string> Match(string uri) { ArgumentUtils.AssertNotNull(uri, "uri"); IDictionary <string, string> result = new Dictionary <string, string>(); Match match = this.matchRegex.Match(uri); for (int i = 1; i < match.Groups.Count; i++) { result.Add(this.matchRegex.GroupNameFromNumber(i), match.Groups[i].Value); } return(result); }
public Parser(string uriTemplate) { ArgumentUtils.AssertNotNull(uriTemplate, "uriTemplate"); int index = 0; this.patternBuilder.Append("^"); foreach (Match match in VARIABLENAMES_REGEX.Matches(uriTemplate)) { string variableName = match.Groups[1].Value; if (!variableNames.Contains(variableName)) { variableNames.Add(variableName); } this.patternBuilder.Append(Escape(uriTemplate, index, match.Index - index)); this.patternBuilder.Append(String.Format(VARIABLEVALUE_PATTERN, variableName)); index = match.Index + match.Length; } this.patternBuilder.Append(Escape(uriTemplate, index, uriTemplate.Length - index)); this.patternBuilder.Append("$"); }
public void ArgumentNotNull() { ArgumentUtils.AssertNotNull(null, "foo"); }