DecimalToCharacterHexDigit() static private method

static private DecimalToCharacterHexDigit ( int i ) : char
i int
return char
コード例 #1
0
        internal static String EncodeUriAsXLinkHref(String uri)
        {
            if (uri == null)
            {
                return(null);
            }

            // uses modified encoding rules from xlink href spec for encoding uri's.
            // http://www.w3.org/TR/2000/PR-xlink-20001220/#link-locators

            byte[] uriBytes = Encoding.UTF8.GetBytes(uri);

            StringBuilder sb = new StringBuilder(uri.Length);

            // iterate over uri bytes and build up an encoded string.
            foreach (byte b in uriBytes)
            {
                if (!EscapeInXLinkHref(b))
                {
                    sb.Append((char)b);
                }
                else
                {
                    // the character needs to be encoded as %HH
                    sb.Append('%');
                    sb.Append(HttpChannelHelper.DecimalToCharacterHexDigit(b >> 4));
                    sb.Append(HttpChannelHelper.DecimalToCharacterHexDigit(b & 0xF));
                }
            }

            return(sb.ToString());
        } // EncodeUriAsXLinkHref
コード例 #2
0
        internal static string EncodeUriAsXLinkHref(string uri)
        {
            if (uri == null)
            {
                return(null);
            }
            byte[]        bytes   = Encoding.UTF8.GetBytes(uri);
            StringBuilder builder = new StringBuilder(uri.Length);

            foreach (byte num in bytes)
            {
                if (!EscapeInXLinkHref(num))
                {
                    builder.Append((char)num);
                }
                else
                {
                    builder.Append('%');
                    builder.Append(HttpChannelHelper.DecimalToCharacterHexDigit(num >> 4));
                    builder.Append(HttpChannelHelper.DecimalToCharacterHexDigit(num & 15));
                }
            }
            return(builder.ToString());
        }