private UriString UpdatePath(UriString uri) { var expandedPath = Environment.ExpandEnvironmentVariables(uri.Path.Decoded.ToString()); var normalizedPath = UriStringHelper.Normalize(expandedPath); uri = uri.With(x => x.Path, new UriStringComponent(normalizedPath)); if (!uri.Scheme && Path.IsPathRooted(uri.Path.Decoded.ToString())) { uri = uri.With(x => x.Scheme, "file"); } return(uri); }
public UriString([NotNull] string uri) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } uri = UriStringHelper.Normalize(uri); var uriMatch = Regex.Match ( uri, UriPattern, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture ); if (!uriMatch.Success) { throw new ArgumentException(paramName: nameof(uri), message: $"'{uri}' is not a valid Uri."); } Scheme = uriMatch.Groups["scheme"].Value; Authority = uriMatch.Groups["authority"].Value; Path = new UriStringComponent(UriStringHelper.Encode(uriMatch.Groups["path"].Value.Trim('/'))); Query = uriMatch.Groups["query"].Success ? Regex .Matches ( uriMatch.Groups["query"].Value, @"(?:^|&)(?<key>[a-z0-9]+)(?:=(?<value>[a-z0-9]+))?", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture ) .Cast <Match>() .ToImmutableDictionary ( m => (SoftString)m.Groups["key"].Value, m => (SoftString)m.Groups["value"].Value ) : ImmutableDictionary <SoftString, SoftString> .Empty; Fragment = uriMatch.Groups["fragment"].Value; }
public UriString(string scheme, string path) : this($"{scheme}:{UriStringHelper.Normalize(path)}") { }