// protected methods protected internal virtual string GetComponents (Uri uri, UriComponents components, UriFormat format) { if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped)) throw new ArgumentOutOfRangeException ("format"); return GetComponentsHelper (uri, components, format); }
public void ConstructorsShouldSetExpectedProperties( UriComponents components, UriFormat format, bool ignoreCase ) { // arrange var target = new UriComparer( components, format, ignoreCase ); // act // assert Assert.Equal( components, target.UriComponents ); Assert.Equal( format, target.UriFormat ); Assert.Equal( ignoreCase, target.IgnoreCase ); }
// protected methods protected internal virtual string GetComponents (Uri uri, UriComponents components, UriFormat format) { if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped)) throw new ArgumentOutOfRangeException ("format"); if ((components & UriComponents.SerializationInfoString) != 0) { if (components != UriComponents.SerializationInfoString) throw new ArgumentOutOfRangeException ("components", "UriComponents.SerializationInfoString must not be combined with other UriComponents."); if (!uri.IsAbsoluteUri) return UriHelper.FormatRelative (uri.OriginalString, "", format); components |= UriComponents.AbsoluteUri; } return GetComponentsHelper (uri, components, format); }
} // 0x00000001809D4120-0x00000001809D45E0 internal string GetParts(UriComponents uriParts, UriFormat formatAs) => default; // 0x00000001809D3B80-0x00000001809D3D30
private unsafe Check CheckCanonical(char *str, ref ushort idx, ushort end, char delim) => default; // 0x00000001809CECF0-0x00000001809CF0A0 private char[] GetCanonicalPath(char[] dest, ref int pos, UriFormat formatAs) => default; // 0x00000001809D2E20-0x00000001809D3620
// // UriParser helpers methods // internal string GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat) { if (uriComponents == UriComponents.Scheme) return m_Syntax.SchemeName; // A serialzation info is "almost" the same as AbsoluteUri except for IPv6 + ScopeID hostname case if ((uriComponents & UriComponents.SerializationInfoString) != 0) uriComponents |= UriComponents.AbsoluteUri; //This will get all the offsets, HostString will be created below if needed EnsureParseRemaining(); if ((uriComponents & UriComponents.NormalizedHost) != 0) { // Down the path we rely on Host to be ON for NormalizedHost uriComponents |= UriComponents.Host; } //Check to see if we need the host/authotity string if ((uriComponents & UriComponents.Host) != 0) EnsureHostString(true); //This, single Port request is always processed here if (uriComponents == UriComponents.Port || uriComponents == UriComponents.StrongPort) { if (((m_Flags & Flags.NotDefaultPort) != 0) || (uriComponents == UriComponents.StrongPort && m_Syntax.DefaultPort != UriParser.NoDefaultPort)) { // recreate string from the port value return m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture); } return string.Empty; } if ((uriComponents & UriComponents.StrongPort) != 0) { // Down the path we rely on Port to be ON for StrongPort uriComponents |= UriComponents.Port; } //This request sometime is faster to process here if (uriComponents == UriComponents.Host && (uriFormat == UriFormat.UriEscaped || (( m_Flags & (Flags.HostNotCanonical | Flags.E_HostNotCanonical)) == 0))) { EnsureHostString(false); return m_Info.Host; } switch (uriFormat) { case UriFormat.UriEscaped: return GetEscapedParts(uriComponents); case V1ToStringUnescape: case UriFormat.SafeUnescaped: case UriFormat.Unescaped: return GetUnescapedParts(uriComponents, uriFormat); default: throw new ArgumentOutOfRangeException("uriFormat"); } }
public string GetComponents (UriComponents components, UriFormat format) { return Parser.GetComponents (this, components, format); }
internal string GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat) { if (uriComponents == UriComponents.Scheme) { return this.m_Syntax.SchemeName; } if ((uriComponents & UriComponents.SerializationInfoString) != 0) { uriComponents |= UriComponents.AbsoluteUri; } this.EnsureParseRemaining(); if ((uriComponents & UriComponents.Host) != 0) { this.EnsureHostString(true); } if ((uriComponents == UriComponents.Port) || (uriComponents == UriComponents.StrongPort)) { if (((this.m_Flags & (Flags.HostNotParsed | Flags.NotDefaultPort)) == Flags.HostNotParsed) && ((uriComponents != UriComponents.StrongPort) || (this.m_Syntax.DefaultPort == -1))) { return string.Empty; } return this.m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture); } if ((uriComponents & UriComponents.StrongPort) != 0) { uriComponents |= UriComponents.Port; } if ((uriComponents == UriComponents.Host) && ((uriFormat == UriFormat.UriEscaped) || ((this.m_Flags & (Flags.E_HostNotCanonical | Flags.HostNotCanonical)) == Flags.HostNotParsed))) { this.EnsureHostString(false); return this.m_Info.Host; } switch (uriFormat) { case UriFormat.UriEscaped: return this.GetEscapedParts(uriComponents); case UriFormat.Unescaped: case UriFormat.SafeUnescaped: case ((UriFormat) 0x7fff): return this.GetUnescapedParts(uriComponents, uriFormat); } throw new ArgumentOutOfRangeException("uriFormat"); }
private string ReCreateParts(UriComponents parts, ushort nonCanonical, UriFormat formatAs) { ushort num3; this.EnsureHostString(false); string input = ((parts & UriComponents.Host) == 0) ? string.Empty : this.m_Info.Host; int destinationIndex = (this.m_Info.Offset.End - this.m_Info.Offset.User) * ((formatAs == UriFormat.UriEscaped) ? 12 : 1); char[] destination = new char[(((input.Length + destinationIndex) + this.m_Syntax.SchemeName.Length) + 3) + 1]; destinationIndex = 0; if ((parts & UriComponents.Scheme) != 0) { this.m_Syntax.SchemeName.CopyTo(0, destination, destinationIndex, this.m_Syntax.SchemeName.Length); destinationIndex += this.m_Syntax.SchemeName.Length; if (parts != UriComponents.Scheme) { destination[destinationIndex++] = ':'; if (this.InFact(Flags.AuthorityFound)) { destination[destinationIndex++] = '/'; destination[destinationIndex++] = '/'; } } } if (((parts & UriComponents.UserInfo) != 0) && this.InFact(Flags.HasUserInfo)) { if ((nonCanonical & 2) == 0) { UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, false, false); } else { switch (formatAs) { case UriFormat.UriEscaped: if (!this.NotAny(Flags.HostNotParsed | Flags.UserEscaped)) { this.InFact(Flags.E_UserNotCanonical); this.m_String.CopyTo(this.m_Info.Offset.User, destination, destinationIndex, this.m_Info.Offset.Host - this.m_Info.Offset.User); destinationIndex += this.m_Info.Offset.Host - this.m_Info.Offset.User; break; } destination = EscapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, true, '?', '#', '%'); break; case UriFormat.Unescaped: destination = UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.UnescapeAll | UnescapeMode.Unescape, this.m_Syntax, false, false); break; case UriFormat.SafeUnescaped: destination = UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host - 1, destination, ref destinationIndex, '@', '/', '\\', this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, this.m_Syntax, false, false); destination[destinationIndex++] = '@'; break; default: destination = UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, false, false); break; } } if (parts == UriComponents.UserInfo) { destinationIndex--; } } if (((parts & UriComponents.Host) != 0) && (input.Length != 0)) { UnescapeMode copyOnly; if (((formatAs != UriFormat.UriEscaped) && (this.HostType == Flags.BasicHostType)) && ((nonCanonical & 4) != 0)) { copyOnly = (formatAs == UriFormat.Unescaped) ? (UnescapeMode.UnescapeAll | UnescapeMode.Unescape) : (this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape); } else { copyOnly = UnescapeMode.CopyOnly; } destination = UnescapeString(input, 0, input.Length, destination, ref destinationIndex, '/', '?', '#', copyOnly, this.m_Syntax, false, false); if ((((parts & UriComponents.SerializationInfoString) != 0) && (this.HostType == (Flags.HostNotParsed | Flags.IPv6HostType))) && (this.m_Info.ScopeId != null)) { this.m_Info.ScopeId.CopyTo(0, destination, destinationIndex - 1, this.m_Info.ScopeId.Length); destinationIndex += this.m_Info.ScopeId.Length; destination[destinationIndex - 1] = ']'; } } if ((parts & UriComponents.Port) != 0) { if ((nonCanonical & 8) == 0) { if (this.InFact(Flags.HostNotParsed | Flags.NotDefaultPort)) { ushort path = this.m_Info.Offset.Path; while (this.m_String[path = (ushort) (path - 1)] != ':') { } this.m_String.CopyTo(path, destination, destinationIndex, this.m_Info.Offset.Path - path); destinationIndex += this.m_Info.Offset.Path - path; } else if (((parts & UriComponents.StrongPort) != 0) && (this.m_Syntax.DefaultPort != -1)) { destination[destinationIndex++] = ':'; input = this.m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture); input.CopyTo(0, destination, destinationIndex, input.Length); destinationIndex += input.Length; } } else if (this.InFact(Flags.HostNotParsed | Flags.NotDefaultPort) || (((parts & UriComponents.StrongPort) != 0) && (this.m_Syntax.DefaultPort != -1))) { destination[destinationIndex++] = ':'; input = this.m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture); input.CopyTo(0, destination, destinationIndex, input.Length); destinationIndex += input.Length; } } if ((parts & UriComponents.Path) != 0) { destination = this.GetCanonicalPath(destination, ref destinationIndex, formatAs); if (parts == UriComponents.Path) { if ((this.InFact(Flags.AuthorityFound) && (destinationIndex != 0)) && (destination[0] == '/')) { num3 = 1; destinationIndex--; } else { num3 = 0; } if (destinationIndex != 0) { return new string(destination, num3, destinationIndex); } return string.Empty; } } if (((parts & UriComponents.Query) != 0) && (this.m_Info.Offset.Query < this.m_Info.Offset.Fragment)) { num3 = (ushort) (this.m_Info.Offset.Query + 1); if (parts != UriComponents.Query) { destination[destinationIndex++] = '?'; } if ((nonCanonical & 0x20) == 0) { UnescapeString(this.m_String, num3, this.m_Info.Offset.Fragment, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, true, false); } else { switch (formatAs) { case UriFormat.UriEscaped: if (!this.NotAny(Flags.HostNotParsed | Flags.UserEscaped)) { UnescapeString(this.m_String, num3, this.m_Info.Offset.Fragment, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, true, false); break; } destination = EscapeString(this.m_String, num3, this.m_Info.Offset.Fragment, destination, ref destinationIndex, true, '#', 0xffff, '%'); break; case UriFormat.Unescaped: destination = UnescapeString(this.m_String, num3, this.m_Info.Offset.Fragment, destination, ref destinationIndex, '#', 0xffff, 0xffff, UnescapeMode.UnescapeAll | UnescapeMode.Unescape, this.m_Syntax, true, false); break; case ((UriFormat) 0x7fff): destination = UnescapeString(this.m_String, num3, this.m_Info.Offset.Fragment, destination, ref destinationIndex, '#', 0xffff, 0xffff, (this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape) | UnescapeMode.V1ToStringFlag, this.m_Syntax, true, false); break; default: destination = UnescapeString(this.m_String, num3, this.m_Info.Offset.Fragment, destination, ref destinationIndex, '#', 0xffff, 0xffff, this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, this.m_Syntax, true, false); break; } } } if (((parts & UriComponents.Fragment) != 0) && (this.m_Info.Offset.Fragment < this.m_Info.Offset.End)) { num3 = (ushort) (this.m_Info.Offset.Fragment + 1); if (parts != UriComponents.Fragment) { destination[destinationIndex++] = '#'; } if ((nonCanonical & 0x40) == 0) { UnescapeString(this.m_String, num3, this.m_Info.Offset.End, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, false, false); } else { switch (formatAs) { case UriFormat.UriEscaped: if (!this.NotAny(Flags.HostNotParsed | Flags.UserEscaped)) { UnescapeString(this.m_String, num3, this.m_Info.Offset.End, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, false, false); break; } destination = EscapeString(this.m_String, num3, this.m_Info.Offset.End, destination, ref destinationIndex, true, '#', 0xffff, '%'); break; case UriFormat.Unescaped: destination = UnescapeString(this.m_String, num3, this.m_Info.Offset.End, destination, ref destinationIndex, '#', 0xffff, 0xffff, UnescapeMode.UnescapeAll | UnescapeMode.Unescape, this.m_Syntax, false, false); break; case ((UriFormat) 0x7fff): destination = UnescapeString(this.m_String, num3, this.m_Info.Offset.End, destination, ref destinationIndex, '#', 0xffff, 0xffff, (this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape) | UnescapeMode.V1ToStringFlag, this.m_Syntax, false, false); break; default: destination = UnescapeString(this.m_String, num3, this.m_Info.Offset.End, destination, ref destinationIndex, '#', 0xffff, 0xffff, this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, this.m_Syntax, false, false); break; } } } return new string(destination, 0, destinationIndex); }
private static string FormatChar(char c, char surrogate, string cStr, UriSchemes scheme, UriKind uriKind, UriComponents component, UriFormat uriFormat, FormatFlags formatFlags) { var isEscaped = cStr.Length != 1; var userEscaped = (formatFlags & FormatFlags.UserEscaped) != 0; if (!isEscaped && !userEscaped && NeedToEscape(c, scheme, component, uriKind, uriFormat, formatFlags)) { return(HexEscapeMultiByte(c)); } if (isEscaped && ( #if NET_4_0 (userEscaped && c < 0xFF) || #endif !NeedToUnescape(c, scheme, component, uriKind, uriFormat, formatFlags))) { if (IriParsing && (c == '<' || c == '>' || c == '^' || c == '{' || c == '|' || c == '}' || c > 0x7F) && (formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0) { return(cStr.ToUpperInvariant()); //Upper case escape } return(cStr); //Keep original case } if ((formatFlags & FormatFlags.NoSlashReplace) == 0 && c == '\\' && component == UriComponents.Path) { if (!IriParsing && uriFormat != UriFormat.UriEscaped && SchemeContains(scheme, UriSchemes.Http | UriSchemes.Https)) { return("/"); } if (SchemeContains(scheme, UriSchemes.Http | UriSchemes.Https | UriSchemes.Ftp | UriSchemes.CustomWithHost)) { return((isEscaped && uriFormat != UriFormat.UriEscaped) ? "\\" : "/"); } if (SchemeContains(scheme, UriSchemes.NetPipe | UriSchemes.NetTcp | UriSchemes.File)) { return("/"); } if (SchemeContains(scheme, UriSchemes.Custom) && (formatFlags & FormatFlags.HasWindowsPath) == 0) { return("/"); } } var ret = c.ToString(CultureInfo.InvariantCulture); if (surrogate != char.MinValue) { ret += surrogate.ToString(CultureInfo.InvariantCulture); } return(ret); }
private static string CombineUri(Uri basePart, string relativePart, UriFormat uriFormat) { string parts; int length; char[] chArray; char ch = relativePart[0]; if ((basePart.IsDosPath && ((ch == '/') || (ch == '\\'))) && ((relativePart.Length == 1) || ((relativePart[1] != '/') && (relativePart[1] != '\\')))) { int index = basePart.OriginalString.IndexOf(':'); if (!basePart.IsImplicitFile) { index = basePart.OriginalString.IndexOf(':', index + 1); } return (basePart.OriginalString.Substring(0, index + 1) + relativePart); } if (!StaticIsFile(basePart.Syntax) || ((ch != '\\') && (ch != '/'))) { bool flag = basePart.Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes); parts = null; if ((ch == '/') || ((ch == '\\') && flag)) { if ((relativePart.Length >= 2) && (relativePart[1] == '/')) { return (basePart.Scheme + ':' + relativePart); } if (basePart.HostType == (Flags.HostNotParsed | Flags.IPv6HostType)) { parts = string.Concat(new object[] { basePart.GetParts(UriComponents.UserInfo | UriComponents.Scheme, uriFormat), '[', basePart.DnsSafeHost, ']', basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Port, uriFormat) }); } else { parts = basePart.GetParts(UriComponents.SchemeAndServer | UriComponents.UserInfo, uriFormat); } if (flag && (ch == '\\')) { relativePart = '/' + relativePart.Substring(1); } return (parts + relativePart); } parts = basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Path, basePart.IsImplicitFile ? UriFormat.Unescaped : uriFormat); length = parts.Length; chArray = new char[length + relativePart.Length]; if (length > 0) { parts.CopyTo(0, chArray, 0, length); while (length > 0) { if (chArray[--length] == '/') { length++; break; } } } } else { if ((relativePart.Length >= 2) && ((relativePart[1] == '\\') || (relativePart[1] == '/'))) { if (!basePart.IsImplicitFile) { return ("file:" + relativePart); } return relativePart; } if (!basePart.IsUnc) { return ("file://" + relativePart); } string str = basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Path, UriFormat.Unescaped); for (int i = 1; i < str.Length; i++) { if (str[i] == '/') { str = str.Substring(0, i); break; } } if (basePart.IsImplicitFile) { return (@"\\" + basePart.GetParts(UriComponents.Host, UriFormat.Unescaped) + str + relativePart); } return ("file://" + basePart.GetParts(UriComponents.Host, uriFormat) + str + relativePart); } relativePart.CopyTo(0, chArray, length, relativePart.Length); ch = basePart.Syntax.InFact(UriSyntaxFlags.MayHaveQuery) ? '?' : ((char) 0xffff); char ch2 = (!basePart.IsImplicitFile && basePart.Syntax.InFact(UriSyntaxFlags.MayHaveFragment)) ? '#' : ((char) 0xffff); string str3 = string.Empty; if ((ch == 0xffff) && (ch2 == 0xffff)) { length += relativePart.Length; } else { int startIndex = 0; while (startIndex < relativePart.Length) { if ((chArray[length + startIndex] == ch) || (chArray[length + startIndex] == ch2)) { break; } startIndex++; } if (startIndex == 0) { str3 = relativePart; } else if (startIndex < relativePart.Length) { str3 = relativePart.Substring(startIndex); } length += startIndex; } if (basePart.HostType == (Flags.HostNotParsed | Flags.IPv6HostType)) { if (basePart.IsImplicitFile) { parts = @"\\[" + basePart.DnsSafeHost + ']'; } else { parts = string.Concat(new object[] { basePart.GetParts(UriComponents.UserInfo | UriComponents.Scheme, uriFormat), '[', basePart.DnsSafeHost, ']', basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Port, uriFormat) }); } } else if (basePart.IsImplicitFile) { if (basePart.IsDosPath) { return (new string(Compress(chArray, 3, ref length, basePart.Syntax), 1, length - 1) + str3); } parts = @"\\" + basePart.GetParts(UriComponents.Host, UriFormat.Unescaped); } else { parts = basePart.GetParts(UriComponents.SchemeAndServer | UriComponents.UserInfo, uriFormat); } chArray = Compress(chArray, basePart.SecuredPathIndex, ref length, basePart.Syntax); return (parts + new string(chArray, 0, length) + str3); }
internal static string FormatRelative(string str, string schemeName, UriFormat uriFormat) { return(Format(str, schemeName, UriKind.Relative, UriComponents.Path, uriFormat, FormatFlags.None)); }
private static string Format(string str, string schemeName, UriKind uriKind, UriComponents component, UriFormat uriFormat, FormatFlags formatFlags) { if (string.IsNullOrEmpty(str)) { return(""); } if (UriHelper.HasCharactersToNormalize(str)) { formatFlags |= UriHelper.FormatFlags.HasComponentCharactersToNormalize | FormatFlags.HasUriCharactersToNormalize; } if (component == UriComponents.Fragment && UriHelper.HasPercentage(str)) { formatFlags |= UriHelper.FormatFlags.HasFragmentPercentage; } if (component == UriComponents.Host && str.Length > 1 && str [0] == '[' && str [str.Length - 1] == ']') { formatFlags |= UriHelper.FormatFlags.IPv6Host; } if (component == UriComponents.Path && str.Length >= 2 && str [1] != ':' && ('a' <= str [0] && str [0] <= 'z') || ('A' <= str [0] && str [0] <= 'Z')) { formatFlags |= UriHelper.FormatFlags.HasWindowsPath; } UriSchemes scheme = GetScheme(schemeName); if (scheme == UriSchemes.Custom && (formatFlags & FormatFlags.HasHost) != 0) { scheme = UriSchemes.CustomWithHost; } var reduceAfter = UriSchemes.Http | UriSchemes.Https | UriSchemes.File | UriSchemes.NetPipe | UriSchemes.NetTcp; if (IriParsing) { reduceAfter |= UriSchemes.Ftp; } else if (component == UriComponents.Path && (formatFlags & FormatFlags.NoSlashReplace) == 0) { if (scheme == UriSchemes.Ftp) { str = Reduce(str.Replace('\\', '/'), !IriParsing); } if (scheme == UriSchemes.CustomWithHost) { str = Reduce(str.Replace('\\', '/'), false); } } str = FormatString(str, scheme, uriKind, component, uriFormat, formatFlags); if (component == UriComponents.Path && (formatFlags & FormatFlags.NoReduce) == 0) { if (SchemeContains(scheme, reduceAfter)) { str = Reduce(str, !IriParsing); } if (IriParsing && scheme == UriSchemes.CustomWithHost) { str = Reduce(str, false); } } return(str); }
internal static string FormatAbsolute(string str, string schemeName, UriComponents component, UriFormat uriFormat, FormatFlags formatFlags = FormatFlags.None) { return(Format(str, schemeName, UriKind.Absolute, component, uriFormat, formatFlags)); }
public async Task GetWxWebAuthenticationCode(string accessToken, string redirectUrl) { var t = await HttpClient.GetStringAsync(UriFormat.GetWxWebAuthenticationCodeUri(_provider.Instance.WeChat.AppID, redirectUrl)); }
internal static int CalculateCaseInsensitiveHashCode(string text) => default; // 0x00000001809CD420-0x00000001809CD4E0 private static string CombineUri(Uri basePart, string relativePart, UriFormat uriFormat) => default; // 0x00000001809CFDC0-0x00000001809D0930
private static string FormatString (string str, UriSchemes scheme, UriKind uriKind, UriComponents component, UriFormat uriFormat, FormatFlags formatFlags) { var s = new StringBuilder (); int len = str.Length; for (int i = 0; i < len; i++) { char c = str [i]; if (c == '%') { int iStart = i; char surrogate; bool invalidUnescape; char x = Uri.HexUnescapeMultiByte (str, ref i, out surrogate, out invalidUnescape); if (invalidUnescape ) { s.Append (c); i = iStart; continue; } string cStr = str.Substring (iStart, i-iStart); s.Append (FormatChar (x, surrogate, cStr, scheme, uriKind, component, uriFormat, formatFlags)); i--; } else s.Append (FormatChar (c, char.MinValue, "" + c, scheme, uriKind, component, uriFormat, formatFlags)); } return s.ToString (); }
private static bool NeedToUnescape(char c, UriSchemes scheme, UriComponents component, UriKind uriKind, UriFormat uriFormat, FormatFlags formatFlags) { if ((formatFlags & FormatFlags.IPv6Host) != 0) { return(false); } if (uriFormat == UriFormat.Unescaped) { return(true); } UriSchemes sDecoders = UriSchemes.NetPipe | UriSchemes.NetTcp; if (!IriParsing) { sDecoders |= UriSchemes.Http | UriSchemes.Https; } if (c == '/' || c == '\\') { if (!IriParsing && uriKind == UriKind.Absolute && uriFormat != UriFormat.UriEscaped && uriFormat != UriFormat.SafeUnescaped) { return(true); } if (SchemeContains(scheme, UriSchemes.File)) { return(component != UriComponents.Fragment && (component != UriComponents.Query || !IriParsing)); } return(component != UriComponents.Query && component != UriComponents.Fragment && SchemeContains(scheme, sDecoders)); } if (c == '?') { //Avoid creating new query if (SupportsQuery(scheme) && component == UriComponents.Path) { return(false); } if (!IriParsing && uriFormat == ToStringUnescape) { if (SupportsQuery(scheme)) { return(component == UriComponents.Query || component == UriComponents.Fragment); } return(component == UriComponents.Fragment); } return(false); } if (c == '#') { return(false); } if (uriFormat == ToStringUnescape && !IriParsing) { if (uriKind == UriKind.Relative) { return(false); } switch (c) { case '$': case '&': case '+': case ',': case ';': case '=': case '@': return(true); } if (c < 0x20 || c == 0x7f) { return(true); } } if (uriFormat == UriFormat.SafeUnescaped || uriFormat == ToStringUnescape) { switch (c) { case '-': case '.': case '_': case '~': return(true); case ' ': case '!': case '"': case '\'': case '(': case ')': case '*': case '<': case '>': case '^': case '`': case '{': case '}': case '|': return(uriKind != UriKind.Relative || (IriParsing && (formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0)); case ':': case '[': case ']': return(uriKind != UriKind.Relative); } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { return(true); } if (c > 0x7f) { return(true); } return(false); } if (uriFormat == UriFormat.UriEscaped) { if (!IriParsing) { if (c == '.') { if (SchemeContains(scheme, UriSchemes.File)) { return(component != UriComponents.Fragment); } return(component != UriComponents.Query && component != UriComponents.Fragment && SchemeContains(scheme, sDecoders)); } return(false); } switch (c) { case '-': case '.': case '_': case '~': return(true); } if ((formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0) { switch (c) { case '!': case '\'': case '(': case ')': case '*': case ':': case '[': case ']': return(true); } } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { return(true); } return(false); } return(false); }
private static bool NeedToUnescape (char c, UriSchemes scheme, UriComponents component, UriKind uriKind, UriFormat uriFormat, FormatFlags formatFlags) { if ((formatFlags & FormatFlags.IPv6Host) != 0) return false; if (uriFormat == UriFormat.Unescaped) return true; UriSchemes sDecoders = UriSchemes.NetPipe | UriSchemes.NetTcp; if (!IriParsing) sDecoders |= UriSchemes.Http | UriSchemes.Https; if (c == '/' || c == '\\') { if (!IriParsing && uriKind == UriKind.Absolute && uriFormat != UriFormat.UriEscaped && uriFormat != UriFormat.SafeUnescaped) return true; if (SchemeContains (scheme, UriSchemes.File)) { return component != UriComponents.Fragment && (component != UriComponents.Query || !IriParsing); } return component != UriComponents.Query && component != UriComponents.Fragment && SchemeContains (scheme, sDecoders); } if (c == '?') { //Avoid creating new query if (SupportsQuery (scheme) && component == UriComponents.Path) return false; if (!IriParsing && uriFormat == ToStringUnescape) { if (SupportsQuery (scheme)) return component == UriComponents.Query || component == UriComponents.Fragment; return component == UriComponents.Fragment; } return false; } if (c == '#') return false; if (uriFormat == ToStringUnescape && !IriParsing) { if (uriKind == UriKind.Relative) return false; switch (c) { case '$': case '&': case '+': case ',': case ';': case '=': case '@': return true; } if (c < 0x20 || c == 0x7f) return true; } if (uriFormat == UriFormat.SafeUnescaped || uriFormat == ToStringUnescape) { switch (c) { case '-': case '.': case '_': case '~': return true; case ' ': case '!': case '"': case '\'': case '(': case ')': case '*': case '<': case '>': case '^': case '`': case '{': case '}': case '|': return uriKind != UriKind.Relative || (IriParsing && (formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0); case ':': case '[': case ']': return uriKind != UriKind.Relative; } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) return true; if (c > 0x7f) return true; return false; } if (uriFormat == UriFormat.UriEscaped) { if (!IriParsing) { if (c == '.') { if (SchemeContains (scheme, UriSchemes.File)) return component != UriComponents.Fragment; return component != UriComponents.Query && component != UriComponents.Fragment && SchemeContains (scheme, sDecoders); } return false; } switch (c) { case '-': case '.': case '_': case '~': return true; } if ((formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0) { switch (c) { case '!': case '\'': case '(': case ')': case '*': case ':': case '[': case ']': return true; } } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) return true; return false; } return false; }
private static bool NeedToEscape(char c, UriSchemes scheme, UriComponents component, UriKind uriKind, UriFormat uriFormat, FormatFlags formatFlags) { if ((formatFlags & FormatFlags.IPv6Host) != 0) { return(false); } if (c == '?') { if (uriFormat == UriFormat.Unescaped) { return(false); } if (!SupportsQuery(scheme)) { return(component != UriComponents.Fragment); } return(false); } if (c == '#') { //Avoid removing fragment if (component == UriComponents.Path || component == UriComponents.Query) { return(false); } if (component == UriComponents.Fragment && (uriFormat == ToStringUnescape || uriFormat == UriFormat.SafeUnescaped) && (formatFlags & FormatFlags.HasFragmentPercentage) != 0) { return(true); } #if NET_4_5 return(false); #else return(uriFormat == UriFormat.UriEscaped || (uriFormat != UriFormat.Unescaped && (formatFlags & FormatFlags.HasComponentCharactersToNormalize) != 0)); #endif } if (uriFormat == UriFormat.SafeUnescaped || uriFormat == ToStringUnescape) { if (c == '%') { return(uriKind != UriKind.Relative); } } if (uriFormat == UriFormat.SafeUnescaped) { if (c < 0x20 || c == 0x7F) { return(true); } } if (uriFormat == UriFormat.UriEscaped) { if (c < 0x20 || c >= 0x7F) { return(component != UriComponents.Host); } switch (c) { case ' ': case '"': case '%': case '<': case '>': case '^': case '`': case '{': case '}': case '|': return(true); case '[': case ']': return(!IriParsing); case '\\': return(component != UriComponents.Path || SchemeContains(scheme, UriSchemes.Gopher | UriSchemes.Ldap | UriSchemes.Mailto | UriSchemes.Nntp | UriSchemes.Telnet | UriSchemes.News | UriSchemes.Custom)); } } return(false); }
private unsafe char[] GetCanonicalPath(char[] dest, ref int pos, UriFormat formatAs) { char[] chArray2; if (this.InFact(Flags.FirstSlashAbsent)) { dest[pos++] = '/'; } if (this.m_Info.Offset.Path == this.m_Info.Offset.Query) { return dest; } int destinationIndex = pos; int securedPathIndex = this.SecuredPathIndex; if (formatAs != UriFormat.UriEscaped) { goto Label_0272; } if (!this.InFact(Flags.HostNotParsed | Flags.ShouldBeCompressed)) { goto Label_013F; } this.m_String.CopyTo(this.m_Info.Offset.Path, dest, destinationIndex, this.m_Info.Offset.Query - this.m_Info.Offset.Path); destinationIndex += this.m_Info.Offset.Query - this.m_Info.Offset.Path; if ((!this.m_Syntax.InFact(UriSyntaxFlags.UnEscapeDotsAndSlashes) || !this.InFact(Flags.HostNotParsed | Flags.PathNotCanonical)) || this.IsImplicitFile) { goto Label_0352; } if (((chArray2 = dest) == null) || (chArray2.Length == 0)) { chRef = null; } else { chRef = chArray2; } UnescapeOnly(chRef, pos, ref destinationIndex, '.', '/', this.m_Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes) ? '\\' : ((char) 0xffff)); fixed (char* chRef = null) { char[] chArray3; goto Label_0352; Label_013F: if (this.InFact(Flags.E_PathNotCanonical) && this.NotAny(Flags.HostNotParsed | Flags.UserEscaped)) { string input = this.m_String; if ((securedPathIndex != 0) && (input[(securedPathIndex + this.m_Info.Offset.Path) - 1] == '|')) { input = input.Remove((securedPathIndex + this.m_Info.Offset.Path) - 1, 1).Insert((securedPathIndex + this.m_Info.Offset.Path) - 1, ":"); } dest = EscapeString(input, this.m_Info.Offset.Path, this.m_Info.Offset.Query, dest, ref destinationIndex, true, '?', '#', this.IsImplicitFile ? ((char) 0xffff) : '%'); } else { this.m_String.CopyTo(this.m_Info.Offset.Path, dest, destinationIndex, this.m_Info.Offset.Query - this.m_Info.Offset.Path); destinationIndex += this.m_Info.Offset.Query - this.m_Info.Offset.Path; } goto Label_0352; Label_0272: this.m_String.CopyTo(this.m_Info.Offset.Path, dest, destinationIndex, this.m_Info.Offset.Query - this.m_Info.Offset.Path); destinationIndex += this.m_Info.Offset.Query - this.m_Info.Offset.Path; if ((!this.InFact(Flags.HostNotParsed | Flags.ShouldBeCompressed) || !this.m_Syntax.InFact(UriSyntaxFlags.UnEscapeDotsAndSlashes)) || (!this.InFact(Flags.HostNotParsed | Flags.PathNotCanonical) || this.IsImplicitFile)) { goto Label_0352; } if (((chArray3 = dest) == null) || (chArray3.Length == 0)) { chRef2 = null; } else { chRef2 = chArray3; } UnescapeOnly(chRef2, pos, ref destinationIndex, '.', '/', this.m_Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes) ? '\\' : ((char) 0xffff)); fixed (char* chRef2 = null) { UnescapeMode mode; char[] chArray; Label_0352: if ((securedPathIndex != 0) && (dest[(securedPathIndex + pos) - 1] == '|')) { dest[(securedPathIndex + pos) - 1] = ':'; } if (this.InFact(Flags.HostNotParsed | Flags.ShouldBeCompressed)) { dest = Compress(dest, (ushort) (pos + securedPathIndex), ref destinationIndex, this.m_Syntax); if (dest[pos] == '\\') { dest[pos] = '/'; } if (((formatAs == UriFormat.UriEscaped) && this.NotAny(Flags.HostNotParsed | Flags.UserEscaped)) && this.InFact(Flags.E_PathNotCanonical)) { string str2 = new string(dest, pos, destinationIndex - pos); dest = EscapeString(str2, 0, destinationIndex - pos, dest, ref pos, true, '?', '#', this.IsImplicitFile ? ((char) 0xffff) : '%'); destinationIndex = pos; } } else if (this.m_Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes) && this.InFact(Flags.BackslashInPath)) { for (int i = pos; i < destinationIndex; i++) { if (dest[i] == '\\') { dest[i] = '/'; } } } if ((formatAs == UriFormat.UriEscaped) || !this.InFact(Flags.HostNotParsed | Flags.PathNotCanonical)) { goto Label_052A; } if (!this.InFact(Flags.HostNotParsed | Flags.PathNotCanonical)) { goto Label_04CB; } UriFormat format = formatAs; if (format != UriFormat.Unescaped) { if (format != ((UriFormat) 0x7fff)) { goto Label_04A6; } mode = (this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape) | UnescapeMode.V1ToStringFlag; if (this.IsImplicitFile) { mode &= ~UnescapeMode.Unescape; } } else { mode = this.IsImplicitFile ? UnescapeMode.CopyOnly : (UnescapeMode.UnescapeAll | UnescapeMode.Unescape); } goto Label_04CE; Label_04A6: mode = this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape; if (this.IsImplicitFile) { mode &= ~UnescapeMode.Unescape; } goto Label_04CE; Label_04CB: mode = UnescapeMode.CopyOnly; Label_04CE: chArray = new char[dest.Length]; Buffer.BlockCopy(dest, 0, chArray, 0, destinationIndex << 1); fixed (char* chRef3 = chArray) { dest = UnescapeString(chRef3, pos, destinationIndex, dest, ref pos, '?', '#', 0xffff, mode, this.m_Syntax, false, false); } return dest; Label_052A: pos = destinationIndex; return dest; } } }
public static string GetContextTypeByFormat(UriFormat a) { return(null); }
private string GetRelativeSerializationString(UriFormat format) { if (format == UriFormat.UriEscaped) { if (this.m_String.Length == 0) { return string.Empty; } int destPos = 0; char[] chArray = EscapeString(this.m_String, 0, this.m_String.Length, null, ref destPos, true, 0xffff, 0xffff, '%'); if (chArray == null) { return this.m_String; } return new string(chArray, 0, destPos); } if (format == UriFormat.Unescaped) { return UnescapeDataString(this.m_String); } if (format != UriFormat.SafeUnescaped) { throw new ArgumentOutOfRangeException("format"); } if (this.m_String.Length == 0) { return string.Empty; } char[] dest = new char[this.m_String.Length]; int length = 0; return new string(UnescapeString(this.m_String, 0, this.m_String.Length, dest, ref length, 0xffff, 0xffff, 0xffff, UnescapeMode.EscapeUnescape, null, false, true), 0, length); }
public UrnWriter(string nid, string nss, string rqf, UriFormat format = UriFormat.UriEscaped) : base(nid, nss, rqf, format) { }
public string GetComponents (UriComponents components, UriFormat format) { if ((components & UriComponents.SerializationInfoString) == 0) EnsureAbsoluteUri (); return Parser.GetComponents (this, components, format); }
public UrnWriter(string urn, UriFormat format = UriFormat.UriEscaped) : base(urn, format) { }
// // // This is for languages that do not support == != operators overloading // // Note that Uri.Equals will get an optimized path but is limited to true/fasle result only // public static int Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType) { if ((object) uri1 == null) { if (uri2 == null) return 0; // Equal return -1; // null < non-null } if ((object) uri2 == null) return 1; // non-null > null // a relative uri is always less than an absolute one if (!uri1.IsAbsoluteUri || !uri2.IsAbsoluteUri) return uri1.IsAbsoluteUri? 1: uri2.IsAbsoluteUri? -1: string.Compare(uri1.OriginalString, uri2.OriginalString, comparisonType); return string.Compare( uri1.GetParts(partsToCompare, compareFormat), uri2.GetParts(partsToCompare, compareFormat), comparisonType ); }
private string GetEscapedParts(UriComponents uriParts) => default; // 0x00000001809D3D30-0x00000001809D3E50 private string GetUnescapedParts(UriComponents uriParts, UriFormat formatAs) => default; // 0x00000001809D5240-0x00000001809D5340
internal string GetComponentsHelper(Uri uri, UriComponents components, UriFormat format) { UriElements elements = UriParseComponents.ParseComponents(uri.OriginalString.Trim(), UriKind.Absolute); string scheme = scheme_name; int dp = default_port; if ((scheme == null) || (scheme == "*")) { scheme = elements.scheme; dp = Uri.GetDefaultPort(scheme); } else if (String.Compare(scheme.ToLower(), elements.scheme.ToLower()) != 0) { throw new SystemException("URI Parser: scheme mismatch: " + scheme + " vs. " + elements.scheme); } var formatFlags = UriHelper.FormatFlags.None; if (UriHelper.HasCharactersToNormalize(uri.OriginalString)) formatFlags |= UriHelper.FormatFlags.HasUriCharactersToNormalize; if (uri.UserEscaped) formatFlags |= UriHelper.FormatFlags.UserEscaped; if (!StringUtilities.IsNullOrEmpty(elements.host)) formatFlags |= UriHelper.FormatFlags.HasHost; // it's easier to answer some case directly (as the output isn't identical // when mixed with others components, e.g. leading slash, # ...) switch (components) { case UriComponents.Scheme: return scheme; case UriComponents.UserInfo: return elements.user ?? ""; case UriComponents.Host: return elements.host; case UriComponents.Port: { int p = elements.port; if (p >= 0 && p != dp) return p.ToString(); return String.Empty; } case UriComponents.Path: var path = elements.path; if (scheme != Uri.UriSchemeMailto && scheme != Uri.UriSchemeNews) path = IgnoreFirstCharIf(elements.path, '/'); return UriHelper.FormatAbsolute(path, scheme, UriComponents.Path, format, formatFlags); case UriComponents.Query: return UriHelper.FormatAbsolute(elements.query, scheme, UriComponents.Query, format, formatFlags); case UriComponents.Fragment: return UriHelper.FormatAbsolute(elements.fragment, scheme, UriComponents.Fragment, format, formatFlags); case UriComponents.StrongPort: { return elements.port >= 0 ? elements.port.ToString() : dp.ToString(); } case UriComponents.SerializationInfoString: components = UriComponents.AbsoluteUri; break; } // now we deal with multiple flags... StringBuilder sb = new StringBuilder(); if ((components & UriComponents.Scheme) != 0) { sb.Append(scheme); sb.Append(elements.delimiter); } if ((components & UriComponents.UserInfo) != 0) { string userinfo = elements.user; if (userinfo != null) { sb.Append(elements.user); sb.Append('@'); } } if ((components & UriComponents.Host) != 0) sb.Append(elements.host); // for StrongPort always show port - even if -1 // otherwise only display if ut's not the default port if ((components & UriComponents.StrongPort) != 0) { sb.Append(":"); if (elements.port >= 0) { sb.Append(elements.port); } else { sb.Append(dp); } } if ((components & UriComponents.Port) != 0) { int p = elements.port; if (p >= 0 && p != dp) { sb.Append(":"); sb.Append(elements.port); } } if ((components & UriComponents.Path) != 0) { string path = elements.path; if ((components & UriComponents.PathAndQuery) != 0 && (path.Length == 0 || !path.StartsWith("/")) && elements.delimiter == Uri.SchemeDelimiter) sb.Append("/"); sb.Append(UriHelper.FormatAbsolute(path, scheme, UriComponents.Path, format, formatFlags)); } if ((components & UriComponents.Query) != 0) { string query = elements.query; if (query != null) { sb.Append("?"); sb.Append(UriHelper.FormatAbsolute(query, scheme, UriComponents.Query, format, formatFlags)); } } if ((components & UriComponents.Fragment) != 0) { string f = elements.fragment; if (f != null) { sb.Append("#"); sb.Append(UriHelper.FormatAbsolute(f, scheme, UriComponents.Fragment, format, formatFlags)); } } return sb.ToString(); }
internal static string FormatRelative (string str, string schemeName, UriFormat uriFormat) { return Format (str, schemeName, UriKind.Relative, UriComponents.Path, uriFormat, FormatFlags.None); }
// protected methods protected internal virtual string GetComponents(Uri uri, UriComponents components, UriFormat format) { if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped)) { throw new ArgumentOutOfRangeException("format"); } Match m = uri_regex.Match(uri.OriginalString.Trim()); string scheme = scheme_name; int dp = default_port; if ((scheme == null) || (scheme == "*")) { scheme = m.Groups [2].Value; dp = Uri.GetDefaultPort(scheme); } else if (String.Compare(scheme, m.Groups [2].Value, true) != 0) { throw new SystemException("URI Parser: scheme mismatch: " + scheme + " vs. " + m.Groups [2].Value); } // it's easier to answer some case directly (as the output isn't identical // when mixed with others components, e.g. leading slash, # ...) switch (components) { case UriComponents.Scheme: return(scheme); case UriComponents.UserInfo: return(ParseAuthority(m.Groups [4]).Groups [2].Value); case UriComponents.Host: return(ParseAuthority(m.Groups [4]).Groups [3].Value); case UriComponents.Port: { string p = ParseAuthority(m.Groups [4]).Groups [5].Value; if (p != null && p != String.Empty && p != dp.ToString()) { return(p); } return(String.Empty); } case UriComponents.Path: return(Format(IgnoreFirstCharIf(m.Groups [5].Value, '/'), format)); case UriComponents.Query: return(Format(m.Groups [7].Value, format)); case UriComponents.Fragment: return(Format(m.Groups [9].Value, format)); case UriComponents.StrongPort: { Group g = ParseAuthority(m.Groups [4]).Groups [5]; return(g.Success ? g.Value : dp.ToString()); } case UriComponents.SerializationInfoString: components = UriComponents.AbsoluteUri; break; } Match am = ParseAuthority(m.Groups [4]); // now we deal with multiple flags... StringBuilder sb = new StringBuilder(); if ((components & UriComponents.Scheme) != 0) { sb.Append(scheme); sb.Append(Uri.GetSchemeDelimiter(scheme)); } if ((components & UriComponents.UserInfo) != 0) { sb.Append(am.Groups [1].Value); } if ((components & UriComponents.Host) != 0) { sb.Append(am.Groups [3].Value); } // for StrongPort always show port - even if -1 // otherwise only display if ut's not the default port if ((components & UriComponents.StrongPort) != 0) { Group g = am.Groups [4]; sb.Append(g.Success ? g.Value : ":" + dp); } if ((components & UriComponents.Port) != 0) { string p = am.Groups [5].Value; if (p != null && p != String.Empty && p != dp.ToString()) { sb.Append(am.Groups [4].Value); } } if ((components & UriComponents.Path) != 0) { if ((components & UriComponents.PathAndQuery) != 0 && (m.Groups [5].Value == null || !m.Groups [5].Value.StartsWith("/"))) { sb.Append("/"); } sb.Append(m.Groups [5]); } if ((components & UriComponents.Query) != 0) { sb.Append(m.Groups [6]); } if ((components & UriComponents.Fragment) != 0) { sb.Append(m.Groups [8]); } return(Format(sb.ToString(), format)); }
private string GetUnescapedParts(UriComponents uriParts, UriFormat formatAs) => default; // 0x00000001809D5240-0x00000001809D5340 private string ReCreateParts(UriComponents parts, ushort nonCanonical, UriFormat formatAs) => default; // 0x00000001809D8EE0-0x00000001809DA5A0
internal static string FormatAbsolute (string str, string schemeName, UriComponents component, UriFormat uriFormat, FormatFlags formatFlags = FormatFlags.None) { return Format (str, schemeName, UriKind.Absolute, component, uriFormat, formatFlags); }
protected override string GetComponents(Uri uri, UriComponents uriComponents, UriFormat format) { Uri newUri = uri; Match match = PathStyleRegEx.Match(uri.OriginalString); if (match.Success && (uriComponents == UriComponents.Path) || (uriComponents == (UriComponents.Path | UriComponents.KeepDelimiter))) { return(GetBucketName(uri) + "/" + GetKey(uri)); } if (match.Success && (uriComponents == UriComponents.AbsoluteUri)) { return(uri.OriginalString); } if (match.Success && (uriComponents == (UriComponents.SchemeAndServer | UriComponents.UserInfo) || uriComponents == UriComponents.SchemeAndServer)) { return("s3://"); } if (match.Success && (uriComponents == UriComponents.Host)) { return(""); } return(""); }
private static string Format (string str, string schemeName, UriKind uriKind, UriComponents component, UriFormat uriFormat, FormatFlags formatFlags) { if (string.IsNullOrEmpty (str)) return ""; if (UriHelper.HasCharactersToNormalize (str)) formatFlags |= UriHelper.FormatFlags.HasComponentCharactersToNormalize | FormatFlags.HasUriCharactersToNormalize; if (component == UriComponents.Fragment && UriHelper.HasPercentage (str)) formatFlags |= UriHelper.FormatFlags.HasFragmentPercentage; if (component == UriComponents.Host && str.Length > 1 && str [0] == '[' && str [str.Length - 1] == ']') formatFlags |= UriHelper.FormatFlags.IPv6Host; if (component == UriComponents.Path && str.Length >= 2 && str [1] != ':' && ('a' <= str [0] && str [0] <= 'z') || ('A' <= str [0] && str [0] <= 'Z')) formatFlags |= UriHelper.FormatFlags.HasWindowsPath; UriSchemes scheme = GetScheme (schemeName); if (scheme == UriSchemes.Custom && (formatFlags & FormatFlags.HasHost) != 0) scheme = UriSchemes.CustomWithHost; var reduceAfter = UriSchemes.Http | UriSchemes.Https | UriSchemes.File | UriSchemes.NetPipe | UriSchemes.NetTcp; if (IriParsing) { reduceAfter |= UriSchemes.Ftp; } else if (component == UriComponents.Path && (formatFlags & FormatFlags.NoSlashReplace) == 0) { if (scheme == UriSchemes.Ftp) str = Reduce (str.Replace ('\\', '/'), !IriParsing); if (scheme == UriSchemes.CustomWithHost) str = Reduce (str.Replace ('\\', '/'), false); } str = FormatString (str, scheme, uriKind, component, uriFormat, formatFlags); if (component == UriComponents.Path && (formatFlags & FormatFlags.NoReduce) == 0) { if (SchemeContains (scheme, reduceAfter)) str = Reduce (str, !IriParsing); if (IriParsing && scheme == UriSchemes.CustomWithHost) str = Reduce (str, false); } return str; }
protected override string GetComponents(Uri uri, UriComponents components, UriFormat format) { string s = uri.OriginalString; builder.Remove(0, builder.Length); if ((components & UriComponents.Scheme) == UriComponents.Scheme) { int start = 0; int end = s.IndexOf(':'); builder.Append(s, start, end - start); } if ((components & UriComponents.Host) == UriComponents.Host) { // Skip past pack:// int start = 7; int end = s.IndexOf('/', start); if (end == -1) { end = s.Length; } if (builder.Length > 0) { builder.Append("://"); } builder.Append(s, start, end - start); } // Port is always -1, so i think i can ignore both Port and StrongPort // Normally they'd get parsed here if ((components & UriComponents.Path) == UriComponents.Path) { // Skip past pack:// int start = s.IndexOf('/', 7); int end = s.IndexOf('?'); if (end == -1) { end = s.IndexOf('#'); } if (end == -1) { end = s.Length; } if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter && builder.Length == 0) { start++; } if (start > 0) { builder.Append(s, start, end - start); } } if ((components & UriComponents.Query) == UriComponents.Query) { int index = s.IndexOf('?'); if (index != -1) { if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter && builder.Length == 0) { index++; } int fragIndex = s.IndexOf('#'); int end = fragIndex == -1 ? s.Length : fragIndex; builder.Append(s, index, end - index); } } if ((components & UriComponents.Fragment) == UriComponents.Fragment) { int index = s.IndexOf('#'); if (index != -1) { if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter && builder.Length == 0) { index++; } builder.Append(s, index, s.Length - index); } } return(builder.ToString()); }
private static string FormatChar (char c, char surrogate, string cStr, UriSchemes scheme, UriKind uriKind, UriComponents component, UriFormat uriFormat, FormatFlags formatFlags) { var isEscaped = cStr.Length != 1; var userEscaped = (formatFlags & FormatFlags.UserEscaped) != 0; if (!isEscaped && !userEscaped && NeedToEscape (c, scheme, component, uriKind, uriFormat, formatFlags)) return HexEscapeMultiByte (c); if (isEscaped && ( (userEscaped && c < 0xFF) || !NeedToUnescape (c, scheme, component, uriKind, uriFormat, formatFlags))) { if (IriParsing && (c == '<' || c == '>' || c == '^' || c == '{' || c == '|' || c == '}' || c > 0x7F) && (formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0) return cStr.ToUpperInvariant (); //Upper case escape return cStr; //Keep original case } if ((formatFlags & FormatFlags.NoSlashReplace) == 0 && c == '\\' && component == UriComponents.Path) { if (!IriParsing && uriFormat != UriFormat.UriEscaped && SchemeContains (scheme, UriSchemes.Http | UriSchemes.Https)) return "/"; if (SchemeContains (scheme, UriSchemes.Http | UriSchemes.Https | UriSchemes.Ftp | UriSchemes.CustomWithHost)) return (isEscaped && uriFormat != UriFormat.UriEscaped) ? "\\" : "/"; if (SchemeContains (scheme, UriSchemes.NetPipe | UriSchemes.NetTcp | UriSchemes.File)) return "/"; if (SchemeContains (scheme, UriSchemes.Custom) && (formatFlags & FormatFlags.HasWindowsPath) == 0) return "/"; } var ret = c.ToString (CultureInfo.InvariantCulture); if (surrogate != char.MinValue) ret += surrogate.ToString (CultureInfo.InvariantCulture); return ret; }
// protected methods protected internal virtual string GetComponents(Uri uri, UriComponents components, UriFormat format) { if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped)) { throw new ArgumentOutOfRangeException("format"); } return(GetComponentsHelper(uri, components, format)); }
private static bool NeedToEscape (char c, UriSchemes scheme, UriComponents component, UriKind uriKind, UriFormat uriFormat, FormatFlags formatFlags) { if ((formatFlags & FormatFlags.IPv6Host) != 0) return false; if (c == '?') { if (uriFormat == UriFormat.Unescaped) return false; if (!SupportsQuery (scheme)) return component != UriComponents.Fragment; return false; } if (c == '#') { //Avoid removing fragment if (component == UriComponents.Path || component == UriComponents.Query) return false; if (component == UriComponents.Fragment && (uriFormat == ToStringUnescape || uriFormat == UriFormat.SafeUnescaped) && (formatFlags & FormatFlags.HasFragmentPercentage) != 0) return true; return false; } if (uriFormat == UriFormat.SafeUnescaped || uriFormat == ToStringUnescape) { if (c == '%') return uriKind != UriKind.Relative; } if (uriFormat == UriFormat.SafeUnescaped) { if (c < 0x20 || c == 0x7F) return true; } if (uriFormat == UriFormat.UriEscaped) { if (c < 0x20 || c >= 0x7F) return component != UriComponents.Host; switch (c) { case ' ': case '"': case '%': case '<': case '>': case '^': case '`': case '{': case '}': case '|': return true; case '[': case ']': return !IriParsing; case '\\': return component != UriComponents.Path || SchemeContains (scheme, UriSchemes.Gopher | UriSchemes.Ldap | UriSchemes.Mailto | UriSchemes.Nntp | UriSchemes.Telnet | UriSchemes.News | UriSchemes.Custom); } } return false; }
internal string GetComponentsHelper(Uri uri, UriComponents components, UriFormat format) { UriElements elements = UriParseComponents.ParseComponents(uri.OriginalString.Trim(), UriKind.Absolute); string scheme = scheme_name; int dp = default_port; if ((scheme == null) || (scheme == "*")) { scheme = elements.scheme; dp = Uri.GetDefaultPort(scheme); } else if (String.Compare(scheme, elements.scheme, true) != 0) { throw new SystemException("URI Parser: scheme mismatch: " + scheme + " vs. " + elements.scheme); } var formatFlags = UriHelper.FormatFlags.None; if (UriHelper.HasCharactersToNormalize(uri.OriginalString)) { formatFlags |= UriHelper.FormatFlags.HasUriCharactersToNormalize; } if (uri.UserEscaped) { formatFlags |= UriHelper.FormatFlags.UserEscaped; } if (!string.IsNullOrEmpty(elements.host)) { formatFlags |= UriHelper.FormatFlags.HasHost; } // it's easier to answer some case directly (as the output isn't identical // when mixed with others components, e.g. leading slash, # ...) switch (components) { case UriComponents.Scheme: return(scheme); case UriComponents.UserInfo: return(elements.user ?? ""); case UriComponents.Host: return(elements.host); case UriComponents.Port: { int p = elements.port; if (p >= 0 && p != dp) { return(p.ToString(CultureInfo.InvariantCulture)); } return(String.Empty); } case UriComponents.Path: var path = elements.path; if (scheme != Uri.UriSchemeMailto && scheme != Uri.UriSchemeNews) { path = IgnoreFirstCharIf(elements.path, '/'); } return(UriHelper.FormatAbsolute(path, scheme, UriComponents.Path, format, formatFlags)); case UriComponents.Query: return(UriHelper.FormatAbsolute(elements.query, scheme, UriComponents.Query, format, formatFlags)); case UriComponents.Fragment: return(UriHelper.FormatAbsolute(elements.fragment, scheme, UriComponents.Fragment, format, formatFlags)); case UriComponents.StrongPort: { return(elements.port >= 0 ? elements.port.ToString(CultureInfo.InvariantCulture) : dp.ToString(CultureInfo.InvariantCulture)); } case UriComponents.SerializationInfoString: components = UriComponents.AbsoluteUri; break; } // now we deal with multiple flags... StringBuilder sb = new StringBuilder(); if ((components & UriComponents.Scheme) != 0) { sb.Append(scheme); sb.Append(elements.delimiter); } if ((components & UriComponents.UserInfo) != 0) { string userinfo = elements.user; if (userinfo != null) { sb.Append(elements.user); sb.Append('@'); } } if ((components & UriComponents.Host) != 0) { sb.Append(elements.host); } // for StrongPort always show port - even if -1 // otherwise only display if ut's not the default port if ((components & UriComponents.StrongPort) != 0) { sb.Append(":"); if (elements.port >= 0) { sb.Append(elements.port); } else { sb.Append(dp); } } if ((components & UriComponents.Port) != 0) { int p = elements.port; if (p >= 0 && p != dp) { sb.Append(":"); sb.Append(elements.port); } } if ((components & UriComponents.Path) != 0) { string path = elements.path; if ((components & UriComponents.PathAndQuery) != 0 && (path.Length == 0 || !path.StartsWith("/", StringComparison.Ordinal)) && elements.delimiter == Uri.SchemeDelimiter) { sb.Append("/"); } sb.Append(UriHelper.FormatAbsolute(path, scheme, UriComponents.Path, format, formatFlags)); } if ((components & UriComponents.Query) != 0) { string query = elements.query; if (query != null) { sb.Append("?"); sb.Append(UriHelper.FormatAbsolute(query, scheme, UriComponents.Query, format, formatFlags)); } } if ((components & UriComponents.Fragment) != 0) { string f = elements.fragment; if (f != null) { sb.Append("#"); sb.Append(UriHelper.FormatAbsolute(f, scheme, UriComponents.Fragment, format, formatFlags)); } } return(sb.ToString()); }
public static int Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType) { if (uri1 == null) { if (uri2 == null) { return 0; } return -1; } if (uri2 == null) { return 1; } if (uri1.IsAbsoluteUri && uri2.IsAbsoluteUri) { return string.Compare(uri1.GetParts(partsToCompare, compareFormat), uri2.GetParts(partsToCompare, compareFormat), comparisonType); } if (uri1.IsAbsoluteUri) { return 1; } if (!uri2.IsAbsoluteUri) { return string.Compare(uri1.OriginalString, uri2.OriginalString, comparisonType); } return -1; }
public static string GetHostAndPort(this Uri uri, UriFormat format) { uri.EnsureNotNull(nameof(uri)).EnsureAbsolute(); // return(uri.GetComponents(components: UriComponents.HostAndPort, format: format)); }
public string GetComponents(UriComponents components, UriFormat format) { if (((components & UriComponents.SerializationInfoString) != 0) && (components != UriComponents.SerializationInfoString)) { throw new ArgumentOutOfRangeException("UriComponents.SerializationInfoString"); } if ((format & ~UriFormat.SafeUnescaped) != ((UriFormat) 0)) { throw new ArgumentOutOfRangeException("format"); } if (this.IsNotAbsoluteUri) { if (components != UriComponents.SerializationInfoString) { throw new InvalidOperationException(System.SR.GetString("net_uri_NotAbsolute")); } return this.GetRelativeSerializationString(format); } if (this.Syntax.IsSimple) { return this.GetComponentsHelper(components, format); } return this.Syntax.InternalGetComponents(this, components, format); }
public string _GetComponents(Uri uri, UriComponents components, UriFormat format) { return(base.GetComponents(uri, components, format)); }
internal string GetParts(UriComponents uriParts, UriFormat formatAs) { return this.GetComponents(uriParts, formatAs); }
public string GetComponents(UriComponents components, UriFormat format) { throw new NotImplementedException(); }
private string GetUnescapedParts(UriComponents uriParts, UriFormat formatAs) { ushort nonCanonical = (ushort) (((ushort) this.m_Flags) & 0x7f); if ((uriParts & UriComponents.Path) != 0) { if ((this.m_Flags & (Flags.BackslashInPath | Flags.FirstSlashAbsent | Flags.ShouldBeCompressed)) != Flags.HostNotParsed) { nonCanonical = (ushort) (nonCanonical | 0x10); } else if (this.IsDosPath && (this.m_String[(this.m_Info.Offset.Path + this.SecuredPathIndex) - 1] == '|')) { nonCanonical = (ushort) (nonCanonical | 0x10); } } if ((((ushort) uriParts) & nonCanonical) == 0) { string uriPartsFromUserString = this.GetUriPartsFromUserString(uriParts); if (uriPartsFromUserString != null) { return uriPartsFromUserString; } } return this.ReCreateParts(uriParts, nonCanonical, formatAs); }
public static int Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType) { throw new NotImplementedException(); }
// // This method is invoked to allow a custom parser to override the // internal parser when serving application with Uri component strings. // The output format depends on the "format" parameter // // Parameters: // uriComponents - Which components are to be retrieved. // uriFormat - The requested output format. // // This method returns: // The final result. The base implementation could be invoked to get a suggested value // protected virtual string GetComponents(Uri uri, UriComponents components, UriFormat format) { if (((components & UriComponents.SerializationInfoString) != 0) && components != UriComponents.SerializationInfoString) throw new ArgumentOutOfRangeException(nameof(components), components, SR.net_uri_NotJustSerialization); if ((format & ~UriFormat.SafeUnescaped) != 0) throw new ArgumentOutOfRangeException(nameof(format)); if (uri.UserDrivenParsing) throw new InvalidOperationException(SR.Format(SR.net_uri_UserDrivenParsing, this.GetType().ToString())); if (!uri.IsAbsoluteUri) throw new InvalidOperationException(SR.net_uri_NotAbsolute); return uri.GetComponentsHelper(components, format); }
// // UriParser helpers methods // internal string GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat) { if (uriComponents == UriComponents.Scheme) { return(m_Syntax.SchemeName); } // A serialzation info is "almost" the same as AbsoluteUri except for IPv6 + ScopeID hostname case if ((uriComponents & UriComponents.SerializationInfoString) != 0) { uriComponents |= UriComponents.AbsoluteUri; } //This will get all the offsets, HostString will be created below if needed EnsureParseRemaining(); if ((uriComponents & UriComponents.NormalizedHost) != 0) { // Down the path we rely on Host to be ON for NormalizedHost uriComponents |= UriComponents.Host; } //Check to see if we need the host/authotity string if ((uriComponents & UriComponents.Host) != 0) { EnsureHostString(true); } //This, single Port request is always processed here if (uriComponents == UriComponents.Port || uriComponents == UriComponents.StrongPort) { if (((m_Flags & Flags.NotDefaultPort) != 0) || (uriComponents == UriComponents.StrongPort && m_Syntax.DefaultPort != UriParser.NoDefaultPort)) { // recreate string from the port value return(m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture)); } return(string.Empty); } if ((uriComponents & UriComponents.StrongPort) != 0) { // Down the path we rely on Port to be ON for StrongPort uriComponents |= UriComponents.Port; } //This request sometime is faster to process here if (uriComponents == UriComponents.Host && (uriFormat == UriFormat.UriEscaped || ((m_Flags & (Flags.HostNotCanonical | Flags.E_HostNotCanonical)) == 0))) { EnsureHostString(false); return(m_Info.Host); } switch (uriFormat) { case UriFormat.UriEscaped: return(GetEscapedParts(uriComponents)); case V1ToStringUnescape: case UriFormat.SafeUnescaped: case UriFormat.Unescaped: return(GetUnescapedParts(uriComponents, uriFormat)); default: throw new ArgumentOutOfRangeException("uriFormat"); } }
private unsafe string GetRelativeSerializationString(UriFormat format) { if (format == UriFormat.UriEscaped) { if (m_String.Length == 0) return string.Empty; int position = 0; char[] dest = UriHelper.EscapeString(m_String, 0, m_String.Length, null, ref position, true, c_DummyChar, c_DummyChar, '%'); if ((object)dest == null) return m_String; return new string(dest, 0, position); } else if (format == UriFormat.Unescaped) return UnescapeDataString(m_String); else if (format == UriFormat.SafeUnescaped) { if (m_String.Length == 0) return string.Empty; char[] dest = new char[m_String.Length]; int position = 0; dest = UriHelper.UnescapeString(m_String, 0, m_String.Length, dest, ref position, c_DummyChar, c_DummyChar, c_DummyChar, UnescapeMode.EscapeUnescape, null, false); return new string(dest, 0, position); } else throw new ArgumentOutOfRangeException("format"); }
// internal string InternalGetComponents(Uri thisUri, UriComponents uriComponents, UriFormat uriFormat) { return(GetComponents(thisUri, uriComponents, uriFormat)); }
// // public string GetComponents(UriComponents components, UriFormat format) { if (((components & UriComponents.SerializationInfoString) != 0) && components != UriComponents.SerializationInfoString) throw new ArgumentOutOfRangeException("components", components, SR.GetString(SR.net_uri_NotJustSerialization)); if ((format & ~UriFormat.SafeUnescaped) != 0) throw new ArgumentOutOfRangeException("format"); if (IsNotAbsoluteUri) { if (components == UriComponents.SerializationInfoString) return GetRelativeSerializationString(format); else throw new InvalidOperationException(SR.GetString(SR.net_uri_NotAbsolute)); } if (Syntax.IsSimple) return GetComponentsHelper(components, format); return Syntax.InternalGetComponents(this, components, format); }
public void Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType, int expected) { Assert.Equal(expected, Math.Sign(Uri.Compare(uri1, uri2, partsToCompare, compareFormat, comparisonType))); }
protected override string GetComponents (Uri uri, UriComponents components, UriFormat format) { return base.GetComponents (uri, components, format); }
public void GetComponents(Uri uri, UriComponents components, UriFormat format, string expected) { Assert.Equal(expected, uri.GetComponents(components, format)); }
public static int Compare (Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType) { if ((comparisonType < StringComparison.CurrentCulture) || (comparisonType > StringComparison.OrdinalIgnoreCase)) { string msg = Locale.GetText ("Invalid StringComparison value '{0}'", comparisonType); throw new ArgumentException ("comparisonType", msg); } if ((uri1 == null) && (uri2 == null)) return 0; string s1 = uri1.GetComponents (partsToCompare, compareFormat); string s2 = uri2.GetComponents (partsToCompare, compareFormat); return String.Compare (s1, s2, comparisonType); }
// protected methods protected internal virtual string GetComponents(Uri uri, UriComponents components, UriFormat format) { if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped)) { throw new ArgumentOutOfRangeException("format"); } UriElements elements = UriParseComponents.ParseComponents(uri.OriginalString.Trim()); string scheme = scheme_name; int dp = default_port; if ((scheme == null) || (scheme == "*")) { scheme = elements.scheme; #if SSHARP dp = KnownProtocols.GetProtocolDefaultPort(scheme); #else dp = Uri.GetDefaultPort(scheme); #endif } else if (String.Compare(scheme, elements.scheme, true) != 0) { throw new SystemException("URI Parser: scheme mismatch: " + scheme + " vs. " + elements.scheme); } // it's easier to answer some case directly (as the output isn't identical // when mixed with others components, e.g. leading slash, # ...) switch (components) { case UriComponents.Scheme: return(scheme); case UriComponents.UserInfo: return(elements.user); case UriComponents.Host: return(elements.host); case UriComponents.Port: { string p = elements.port; if (p != null && p.Length != 0 && p != dp.ToString()) { return(p); } return(String.Empty); } case UriComponents.Path: return(Format(IgnoreFirstCharIf(elements.path, '/'), format)); case UriComponents.Query: return(Format(elements.query, format)); case UriComponents.Fragment: return(Format(elements.fragment, format)); case UriComponents.StrongPort: { return(elements.port.Length != 0 ? elements.port : dp.ToString()); } case UriComponents.SerializationInfoString: components = UriComponents.AbsoluteUri; break; } // now we deal with multiple flags... StringBuilder sb = new StringBuilder(); if ((components & UriComponents.Scheme) != 0) { sb.Append(scheme); #if SSHARP sb.Append(scheme == "mailto" || scheme == "news" ? ":" : Uri.SchemeDelimiter); #else sb.Append(Uri.GetSchemeDelimiter(scheme)); #endif } if ((components & UriComponents.UserInfo) != 0) { string userinfo = elements.user; if (!String.IsNullOrEmpty(userinfo)) { sb.Append(elements.user); sb.Append('@'); } } if ((components & UriComponents.Host) != 0) { sb.Append(elements.host); } // for StrongPort always show port - even if -1 // otherwise only display if ut's not the default port if ((components & UriComponents.StrongPort) != 0) { sb.Append(":"); if (elements.port.Length != 0) { sb.Append(elements.port); } else { sb.Append(dp); } } if ((components & UriComponents.Port) != 0) { string p = elements.port; if (p != null && p.Length != 0 && p != dp.ToString()) { sb.Append(":"); sb.Append(elements.port); } } if ((components & UriComponents.Path) != 0) { if ((components & UriComponents.PathAndQuery) != 0 && (elements.path.Length == 0 || !elements.path.StartsWith("/"))) { sb.Append("/"); } sb.Append(elements.path); } if ((components & UriComponents.Query) != 0) { string query = elements.query; if (!String.IsNullOrEmpty(query)) { sb.Append("?"); sb.Append(elements.query); } } string result = Format(sb.ToString(), format); if ((components & UriComponents.Fragment) != 0) { string f = elements.fragment; if (!String.IsNullOrEmpty(f)) { result += "#" + Format(f, format); } } return(result); }
protected override string GetComponents (Uri uri, UriComponents components, UriFormat format) { throw new UriFormatException (); // return components.ToString (); }
protected override string GetComponents(Uri uri, UriComponents components, UriFormat format) { throw new UriFormatException(); // return components.ToString (); }