private static string NormalizeHostname(string h) { if (string.IsNullOrWhiteSpace(h)) { return(null); } h = h.Trim().ToLower(); if (!h.StartsWith("http") || !h.Contains("://")) { return(h); } var m = HostPattern.Match(h); return(m.Success ? m.Groups[2].Value : h); }
private void ExtractSegments() { // TODO : validation of segments (for example the match-all segment should be the last of a section) SchemeSegment = SchemePattern; hostSegments = HostPattern == "" ? new string[0] : HostPattern.Split(HostSeparator).ToArray(); pathSegments = PathPattern == "" ? new string[0] : PathPattern.Split(PathDelimiter).ToArray(); QuerySegments = QueryPattern == "" ? Enumerable.Empty <KeyValuePair <string, string> >() : QueryPattern.Split(QuerySeparator) .Select(x => new Tuple <string, int>(x, x.IndexOf('='))) .Where(t => t.Item2 > 0) .Select(t => { string varName = t.Item1.Substring(0, t.Item2); string varValue = t.Item1.Substring(t.Item2 + 1); return(new KeyValuePair <string, string>(varName, varValue)); }) .ToList(); }