コード例 #1
0
ファイル: UriExt.cs プロジェクト: naricc/runtime-bak
        private unsafe string GetRelativeSerializationString(UriFormat format)
        {
            if (format == UriFormat.UriEscaped)
            {
                return(UriHelper.EscapeString(_string, checkExistingEscaped: true, UriHelper.UnreservedReservedTable));
            }
            else if (format == UriFormat.Unescaped)
            {
                return(UnescapeDataString(_string));
            }
            else if (format == UriFormat.SafeUnescaped)
            {
                if (_string.Length == 0)
                {
                    return(string.Empty);
                }

                char[] dest     = new char[_string.Length];
                int    position = 0;
                dest = UriHelper.UnescapeString(_string, 0, _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(nameof(format));
            }
        }
コード例 #2
0
        private unsafe string GetRelativeSerializationString(UriFormat format)
        {
            if (format == UriFormat.UriEscaped)
            {
                return(UriHelper.EscapeString(_string, checkExistingEscaped: true, UriHelper.UnreservedReservedTable));
            }
            else if (format == UriFormat.Unescaped)
            {
                return(UnescapeDataString(_string));
            }
            else if (format == UriFormat.SafeUnescaped)
            {
                if (_string.Length == 0)
                {
                    return(string.Empty);
                }

                var vsb = new ValueStringBuilder(stackalloc char[StackallocThreshold]);
                UriHelper.UnescapeString(_string, ref vsb, c_DummyChar, c_DummyChar, c_DummyChar, UnescapeMode.EscapeUnescape, null, false);
                return(vsb.ToString());
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(format));
            }
        }
コード例 #3
0
        private unsafe string GetRelativeSerializationString(UriFormat format)
        {
            if (format == UriFormat.UriEscaped)
            {
                if (_string.Length == 0)
                {
                    return(string.Empty);
                }
                int    position = 0;
                char[] dest     = UriHelper.EscapeString(_string, 0, _string.Length, null, ref position, true,
                                                         c_DummyChar, c_DummyChar, '%');
                if ((object)dest == null)
                {
                    return(_string);
                }
                return(new string(dest, 0, position));
            }

            else if (format == UriFormat.Unescaped)
            {
                return(UnescapeDataString(_string));
            }

            else if (format == UriFormat.SafeUnescaped)
            {
                if (_string.Length == 0)
                {
                    return(string.Empty);
                }

                char[] dest     = new char[_string.Length];
                int    position = 0;
                dest = UriHelper.UnescapeString(_string, 0, _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");
            }
        }
コード例 #4
0
        //
        // Where stringToEscape is intended to be URI data, but not an entire URI.
        // This method will escape any character that is not an unreserved character, including percent signs.
        //
        public static string EscapeDataString(string stringToEscape)
        {
            if ((object)stringToEscape == null)
            {
                throw new ArgumentNullException("stringToEscape");
            }

            if (stringToEscape.Length == 0)
            {
                return(string.Empty);
            }

            int position = 0;

            char[] dest = UriHelper.EscapeString(stringToEscape, 0, stringToEscape.Length, null, ref position, false,
                                                 c_DummyChar, c_DummyChar, c_DummyChar);
            if (dest == null)
            {
                return(stringToEscape);
            }
            return(new string(dest, 0, position));
        }
コード例 #5
0
ファイル: UriExt.cs プロジェクト: naricc/runtime-bak
 // Where stringToEscape is intended to be URI data, but not an entire URI.
 // This method will escape any character that is not an unreserved character, including percent signs.
 public static string EscapeDataString(string stringToEscape) =>
 UriHelper.EscapeString(stringToEscape, checkExistingEscaped: false, UriHelper.UnreservedTable);