Пример #1
0
        public static System.String encode(System.String s, System.String enc)
        {
            if (!needsEncoding(s))
            {
                return(s);
            }

            int length = s.Length;

            System.Text.StringBuilder out_Renamed = new System.Text.StringBuilder(length);

            System.IO.MemoryStream buf = new System.IO.MemoryStream(10);             // why 10? w3c says so.

            //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
            //UPGRADE_TODO: Constructor 'java.io.OutputStreamWriter.OutputStreamWriter' was converted to 'System.IO.StreamWriter.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioOutputStreamWriterOutputStreamWriter_javaioOutputStream_javalangString'"
            System.IO.StreamWriter writer = new System.IO.StreamWriter(new System.IO.StreamWriter(buf, System.Text.Encoding.GetEncoding(enc)).BaseStream, new System.IO.StreamWriter(buf, System.Text.Encoding.GetEncoding(enc)).Encoding);

            for (int i = 0; i < length; i++)
            {
                int c = (int)s[i];
                if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == ' ')
                {
                    if (c == ' ')
                    {
                        c = '+';
                    }

                    toHex(out_Renamed, SupportClass.ToSByteArray(buf.ToArray()));
                    //UPGRADE_ISSUE: Method 'java.io.ByteArrayOutputStream.reset' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioByteArrayOutputStreamreset'"
                    buf.reset();

                    out_Renamed.Append((char)c);
                }
                else
                {
                    try
                    {
                        writer.Write((System.Char)c);

                        if (c >= 0xD800 && c <= 0xDBFF && i < length - 1)
                        {
                            int d = (int)s[i + 1];
                            if (d >= 0xDC00 && d <= 0xDFFF)
                            {
                                writer.Write((System.Char)d);
                                i++;
                            }
                        }

                        writer.Flush();
                    }
                    catch (System.IO.IOException ex)
                    {
                        throw new System.ArgumentException(s);
                    }
                }
            }

            toHex(out_Renamed, SupportClass.ToSByteArray(buf.ToArray()));

            return(out_Renamed.ToString());
        }
Пример #2
0
		public static System.String encode(System.String s, System.String enc)
		{
			if (!needsEncoding(s))
			{
				return s;
			}
			
			int length = s.Length;
			
			System.Text.StringBuilder out_Renamed = new System.Text.StringBuilder(length);
			
			System.IO.MemoryStream buf = new System.IO.MemoryStream(10); // why 10? w3c says so.
			
			//UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
			//UPGRADE_TODO: Constructor 'java.io.OutputStreamWriter.OutputStreamWriter' was converted to 'System.IO.StreamWriter.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioOutputStreamWriterOutputStreamWriter_javaioOutputStream_javalangString'"
			System.IO.StreamWriter writer = new System.IO.StreamWriter(new System.IO.StreamWriter(buf, System.Text.Encoding.GetEncoding(enc)).BaseStream, new System.IO.StreamWriter(buf, System.Text.Encoding.GetEncoding(enc)).Encoding);
			
			for (int i = 0; i < length; i++)
			{
				int c = (int) s[i];
				if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == ' ')
				{
					if (c == ' ')
					{
						c = '+';
					}
					
					toHex(out_Renamed, SupportClass.ToSByteArray(buf.ToArray()));
					//UPGRADE_ISSUE: Method 'java.io.ByteArrayOutputStream.reset' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioByteArrayOutputStreamreset'"
					buf.reset();
					
					out_Renamed.Append((char) c);
				}
				else
				{
					try
					{
						writer.Write((System.Char) c);
						
						if (c >= 0xD800 && c <= 0xDBFF && i < length - 1)
						{
							int d = (int) s[i + 1];
							if (d >= 0xDC00 && d <= 0xDFFF)
							{
								writer.Write((System.Char) d);
								i++;
							}
						}
						
						writer.Flush();
					}
					catch (System.IO.IOException ex)
					{
						throw new System.ArgumentException(s);
					}
				}
			}
			
			toHex(out_Renamed, SupportClass.ToSByteArray(buf.ToArray()));
			
			return out_Renamed.ToString();
		}