System.Runtime.Remoting.Channels.Http.HttpChannelHelper.DecodeUriInPlace C# (CSharp) Метод

DecodeUriInPlace() статический приватный Метод

static private DecodeUriInPlace ( byte uriBytes, int &length ) : void
uriBytes byte
length int
Результат void
        internal static void DecodeUriInPlace(byte[] uriBytes, out int length)
        {
            int percentsFound = 0;
            int count = uriBytes.Length;
            length = count;
            int co = 0;
            while (co < count)
            {
                if (uriBytes[co] == (byte)'%')
                {
                    // determine location to write to (we skip 2 character for each percent)
                    int writePos = co - (percentsFound * 2);

                    // decode in place by collapsing bytes "%XY" (actual byte is 16*Dec(X) + Dec(Y))
                    uriBytes[writePos] = (byte)
                        (16 * CharacterHexDigitToDecimal(uriBytes[co + 1]) +
                         CharacterHexDigitToDecimal(uriBytes[co + 2]));

                    percentsFound++;      
                    length -= 2; // we eliminated 2 characters from the length
                    co += 3;
                }
                else
                {
                    if (percentsFound != 0)
                    {
                        // we have to copy characters back into place since we will skip some characters

                        // determine location to write to (we skip 2 character for each percent)
                        int writePos = co - (percentsFound * 2);

                        // copy character back into place
                        uriBytes[writePos] = uriBytes[co];
                    }

                    co++;
                }
            }
            
        } // DecodeUri

Usage Example

        internal static string DecodeUri(string uri)
        {
            int num;

            byte[] bytes = Encoding.UTF8.GetBytes(uri);
            HttpChannelHelper.DecodeUriInPlace(bytes, out num);
            return(Encoding.UTF8.GetString(bytes, 0, num));
        }
All Usage Examples Of System.Runtime.Remoting.Channels.Http.HttpChannelHelper::DecodeUriInPlace