Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ReCreateParts()

string System.Uri.ReCreateParts ( UriComponents parts,
ushort nonCanonical,
UriFormat formatAs )
inlineprivate

Definition at line 1887 of file Uri.cs.

1888 {
1890 string @string = _string;
1892 if (@string.Length <= 512)
1893 {
1896 }
1897 else
1898 {
1899 valueStringBuilder = new System.Text.ValueStringBuilder(@string.Length);
1900 }
1902 if ((parts & UriComponents.Scheme) != 0)
1903 {
1904 dest.Append(_syntax.SchemeName);
1905 if (parts != UriComponents.Scheme)
1906 {
1907 dest.Append(':');
1908 if (InFact(Flags.AuthorityFound))
1909 {
1910 dest.Append('/');
1911 dest.Append('/');
1912 }
1913 }
1914 }
1916 if ((parts & UriComponents.UserInfo) != 0 && InFact(Flags.HasUserInfo))
1917 {
1919 if ((nonCanonical & 2u) != 0)
1920 {
1921 switch (formatAs)
1922 {
1923 case UriFormat.UriEscaped:
1924 if (NotAny(Flags.UserEscaped))
1925 {
1926 UriHelper.EscapeString(readOnlySpan, ref dest, checkExistingEscaped: true, '?', '#');
1927 break;
1928 }
1929 InFact(Flags.E_UserNotCanonical);
1930 dest.Append(readOnlySpan);
1931 break;
1932 case UriFormat.SafeUnescaped:
1934 UriHelper.UnescapeString(format[..^1], ref dest, '@', '/', '\\', InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, _syntax, isQuery: false);
1935 dest.Append('@');
1936 break;
1937 case UriFormat.Unescaped:
1938 UriHelper.UnescapeString(readOnlySpan, ref dest, '\uffff', '\uffff', '\uffff', UnescapeMode.Unescape | UnescapeMode.UnescapeAll, _syntax, isQuery: false);
1939 break;
1940 default:
1941 dest.Append(readOnlySpan);
1942 break;
1943 }
1944 }
1945 else
1946 {
1947 dest.Append(readOnlySpan);
1948 }
1949 if (parts == UriComponents.UserInfo)
1950 {
1951 dest.Length--;
1952 }
1953 }
1954 if ((parts & UriComponents.Host) != 0)
1955 {
1956 string text = _info.Host;
1957 if (text.Length != 0)
1958 {
1959 UnescapeMode unescapeMode = ((formatAs != UriFormat.UriEscaped && HostType == Flags.BasicHostType && (nonCanonical & 4u) != 0) ? ((formatAs == UriFormat.Unescaped) ? (UnescapeMode.Unescape | UnescapeMode.UnescapeAll) : (InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape)) : UnescapeMode.CopyOnly);
1962 if ((parts & UriComponents.NormalizedHost) != 0)
1963 {
1964 text = UriHelper.StripBidiControlCharacters(text, text);
1965 if (!DomainNameHelper.TryGetUnicodeEquivalent(text, ref dest2))
1966 {
1967 dest2.Length = 0;
1968 }
1969 }
1970 UriHelper.UnescapeString((dest2.Length == 0) ? ((ReadOnlySpan<char>)text) : dest2.AsSpan(), ref dest, '/', '?', '#', unescapeMode, _syntax, isQuery: false);
1971 dest2.Dispose();
1972 if (((uint)parts & 0x80000000u) != 0 && HostType == Flags.IPv6HostType && _info.ScopeId != null)
1973 {
1974 dest.Length--;
1975 dest.Append(_info.ScopeId);
1976 dest.Append(']');
1977 }
1978 }
1979 }
1980 if ((parts & UriComponents.Port) != 0 && (InFact(Flags.NotDefaultPort) || ((parts & UriComponents.StrongPort) != 0 && _syntax.DefaultPort != -1)))
1981 {
1982 dest.Append(':');
1984 Span<char> destination = dest.AppendSpan(5);
1985 format = default(ReadOnlySpan<char>);
1986 int charsWritten;
1987 bool flag = portValue.TryFormat(destination, out charsWritten, format);
1989 }
1990 if ((parts & UriComponents.Path) != 0)
1991 {
1993 if (parts == UriComponents.Path)
1994 {
1995 int start = ((InFact(Flags.AuthorityFound) && dest.Length != 0 && dest[0] == '/') ? 1 : 0);
1996 format = dest.AsSpan(start);
1997 string result = format.ToString();
1998 dest.Dispose();
1999 return result;
2000 }
2001 }
2002 if ((parts & UriComponents.Query) != 0 && _info.Offset.Query < _info.Offset.Fragment)
2003 {
2004 int num = _info.Offset.Query + 1;
2005 if (parts != UriComponents.Query)
2006 {
2007 dest.Append('?');
2008 }
2010 if ((nonCanonical & 0x20u) != 0)
2011 {
2012 if (formatAs == UriFormat.UriEscaped)
2013 {
2014 if (NotAny(Flags.UserEscaped))
2015 {
2016 UriHelper.EscapeString(@string.AsSpan(num, _info.Offset.Fragment - num), ref dest, checkExistingEscaped: true, '#');
2017 goto IL_04d5;
2018 }
2019 }
2020 else
2021 {
2022 unescapeMode2 = formatAs switch
2023 {
2024 (UriFormat)32767 => (InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape) | UnescapeMode.V1ToStringFlag,
2025 UriFormat.Unescaped => UnescapeMode.Unescape | UnescapeMode.UnescapeAll,
2026 _ => InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape,
2027 };
2028 }
2029 }
2030 UriHelper.UnescapeString(@string, num, _info.Offset.Fragment, ref dest, '#', '\uffff', '\uffff', unescapeMode2, _syntax, isQuery: true);
2031 }
2032 goto IL_04d5;
2033 IL_04d5:
2034 if ((parts & UriComponents.Fragment) != 0 && _info.Offset.Fragment < _info.Offset.End)
2035 {
2036 int num2 = _info.Offset.Fragment + 1;
2037 if (parts != UriComponents.Fragment)
2038 {
2039 dest.Append('#');
2040 }
2042 if ((nonCanonical & 0x40u) != 0)
2043 {
2044 if (formatAs == UriFormat.UriEscaped)
2045 {
2046 if (NotAny(Flags.UserEscaped))
2047 {
2048 UriHelper.EscapeString(@string.AsSpan(num2, _info.Offset.End - num2), ref dest, checkExistingEscaped: true);
2049 goto IL_05d8;
2050 }
2051 }
2052 else
2053 {
2054 unescapeMode3 = formatAs switch
2055 {
2056 (UriFormat)32767 => (InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape) | UnescapeMode.V1ToStringFlag,
2057 UriFormat.Unescaped => UnescapeMode.Unescape | UnescapeMode.UnescapeAll,
2058 _ => InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape,
2059 };
2060 }
2061 }
2062 UriHelper.UnescapeString(@string, num2, _info.Offset.End, ref dest, '#', '\uffff', '\uffff', unescapeMode3, _syntax, isQuery: false);
2063 }
2064 goto IL_05d8;
2065 IL_05d8:
2066 return dest.ToString();
2067 }
string SchemeName
Definition UriParser.cs:81
string Host
Definition Uri.cs:85
string ScopeId
Definition Uri.cs:91
Offset Offset
Definition Uri.cs:81
UriParser _syntax
Definition Uri.cs:193
bool NotAny(Flags flags)
Definition Uri.cs:606
void EnsureHostString(bool allowDnsOptimization)
Definition Uri.cs:644
bool InFact(Flags flags)
Definition Uri.cs:611
string _string
Definition Uri.cs:189
Flags HostType
Definition Uri.cs:209
unsafe void GetCanonicalPath(ref System.Text.ValueStringBuilder dest, UriFormat formatAs)
Definition Uri.cs:3125
UriInfo _info
Definition Uri.cs:197
UriFormat
Definition UriFormat.cs:4
ushort PortValue
Definition Uri.cs:117
ushort User
Definition Uri.cs:113
ushort Query
Definition Uri.cs:121
ushort End
Definition Uri.cs:125
ushort Host
Definition Uri.cs:115
ushort Fragment
Definition Uri.cs:123

References System.Uri._info, System.Uri._string, System.Uri._syntax, System.UriParser.DefaultPort, System.destination, System.Runtime.Serialization.Dictionary, System.Uri.Offset.End, System.Uri.EnsureHostString(), System.UriHelper.EscapeString(), System.format, System.Uri.Offset.Fragment, System.Uri.GetCanonicalPath(), System.Uri.UriInfo.Host, System.Uri.Offset.Host, System.Uri.HostType, System.Uri.InFact(), System.Uri.NotAny(), System.Uri.UriInfo.Offset, System.Uri.Offset.PortValue, System.UriParser.SchemeName, System.Uri.UriInfo.ScopeId, System.start, System.UriHelper.StripBidiControlCharacters(), System.text, System.DomainNameHelper.TryGetUnicodeEquivalent(), System.UriHelper.UnescapeString(), and System.Uri.Offset.User.

Referenced by System.Uri.GetEscapedParts(), and System.Uri.GetUnescapedParts().