コード例 #1
0
ファイル: UriCodec.cs プロジェクト: zhouweiaccp/XobotOS
 /// <param name="convertPlus">true to convert '+' to ' '.</param>
 public static string decode(string s, bool convertPlus, java.nio.charset.Charset
                             charset)
 {
     if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1))
     {
         return(s);
     }
     java.lang.StringBuilder       result = new java.lang.StringBuilder(s.Length);
     java.io.ByteArrayOutputStream @out   = new java.io.ByteArrayOutputStream();
     {
         for (int i = 0; i < s.Length;)
         {
             char c = s[i];
             if (c == '%')
             {
                 do
                 {
                     if (i + 2 >= s.Length)
                     {
                         throw new System.ArgumentException("Incomplete % sequence at: " + i);
                     }
                     int d1 = hexToInt(s[i + 1]);
                     int d2 = hexToInt(s[i + 2]);
                     if (d1 == -1 || d2 == -1)
                     {
                         throw new System.ArgumentException("Invalid % sequence " + Sharpen.StringHelper.Substring
                                                                (s, i, i + 3) + " at " + i);
                     }
                     @out.write(unchecked ((byte)((d1 << 4) + d2)));
                     i += 3;
                 }while (i < s.Length && s[i] == '%');
                 result.append(XobotOS.Runtime.Util.GetStringForBytes(@out.toByteArray(), charset)
                               );
                 @out.reset();
             }
             else
             {
                 if (convertPlus && c == '+')
                 {
                     c = ' ';
                 }
                 result.append(c);
                 i++;
             }
         }
     }
     return(result.ToString());
 }
コード例 #2
0
ファイル: UriCodec.cs プロジェクト: hakeemsm/XobotOS
		/// <param name="convertPlus">true to convert '+' to ' '.</param>
		public static string decode(string s, bool convertPlus, java.nio.charset.Charset 
			charset)
		{
			if (s.IndexOf('%') == -1 && (!convertPlus || s.IndexOf('+') == -1))
			{
				return s;
			}
			java.lang.StringBuilder result = new java.lang.StringBuilder(s.Length);
			java.io.ByteArrayOutputStream @out = new java.io.ByteArrayOutputStream();
			{
				for (int i = 0; i < s.Length; )
				{
					char c = s[i];
					if (c == '%')
					{
						do
						{
							if (i + 2 >= s.Length)
							{
								throw new System.ArgumentException("Incomplete % sequence at: " + i);
							}
							int d1 = hexToInt(s[i + 1]);
							int d2 = hexToInt(s[i + 2]);
							if (d1 == -1 || d2 == -1)
							{
								throw new System.ArgumentException("Invalid % sequence " + Sharpen.StringHelper.Substring
									(s, i, i + 3) + " at " + i);
							}
							@out.write(unchecked((byte)((d1 << 4) + d2)));
							i += 3;
						}
						while (i < s.Length && s[i] == '%');
						result.append(XobotOS.Runtime.Util.GetStringForBytes(@out.toByteArray(), charset)
							);
						@out.reset();
					}
					else
					{
						if (convertPlus && c == '+')
						{
							c = ' ';
						}
						result.append(c);
						i++;
					}
				}
			}
			return result.ToString();
		}