Author: krasnov
Date: 2006-12-07 11:31:37 -0500 (Thu, 07 Dec 2006)
New Revision: 69188

Modified:
   trunk/mcs/class/System/System/ChangeLog
   trunk/mcs/class/System/System/Uri.cs
   trunk/mcs/class/System/Test/System/ChangeLog
   trunk/mcs/class/System/Test/System/UriTest3.cs
Log:
* Uri.cs: implemented UnescapeDataString method
* UriTest3.cs: Added tests for Uri.UnescapeDataString

Modified: trunk/mcs/class/System/System/ChangeLog
===================================================================
--- trunk/mcs/class/System/System/ChangeLog     2006-12-07 16:26:38 UTC (rev 
69187)
+++ trunk/mcs/class/System/System/ChangeLog     2006-12-07 16:31:37 UTC (rev 
69188)
@@ -1,3 +1,7 @@
+2006-12-07  Vladimir Krasnov  <[EMAIL PROTECTED]>
+
+       * Uri.cs: implemented UnescapeDataString method
+
 2006-09-28  Andrew Skiba  <[EMAIL PROTECTED]>
 
        * UriParser.cs: TARGET_JVM

Modified: trunk/mcs/class/System/System/Uri.cs
===================================================================
--- trunk/mcs/class/System/System/Uri.cs        2006-12-07 16:26:38 UTC (rev 
69187)
+++ trunk/mcs/class/System/System/Uri.cs        2006-12-07 16:31:37 UTC (rev 
69188)
@@ -1796,14 +1796,101 @@
                        }
                }
 
-               [MonoTODO]
                public static string UnescapeDataString (string 
stringToUnescape)
                {
                        if (stringToUnescape == null)
                                throw new ArgumentNullException 
("stringToUnescape");
 
-                       throw new NotImplementedException ();
+                       if (stringToUnescape.IndexOf ('%') == -1 && 
stringToUnescape.IndexOf ('+') == -1)
+                               return stringToUnescape;
+
+                       StringBuilder output = new StringBuilder ();
+                       long len = stringToUnescape.Length;
+                       MemoryStream bytes = new MemoryStream ();
+                       int xchar;
+
+                       for (int i = 0; i < len; i++) {
+                               if (stringToUnescape [i] == '%' && i + 2 < len 
&& stringToUnescape [i + 1] != '%') {
+                                       if (stringToUnescape [i + 1] == 'u' && 
i + 5 < len) {
+                                               if (bytes.Length > 0) {
+                                                       output.Append (GetChars 
(bytes, Encoding.UTF8));
+                                                       bytes.SetLength (0);
+                                               }
+
+                                               xchar = GetChar 
(stringToUnescape, i + 2, 4);
+                                               if (xchar != -1) {
+                                                       output.Append ((char) 
xchar);
+                                                       i += 5;
+                                               }
+                                               else {
+                                                       output.Append ('%');
+                                               }
+                                       }
+                                       else if ((xchar = GetChar 
(stringToUnescape, i + 1, 2)) != -1) {
+                                               bytes.WriteByte ((byte) xchar);
+                                               i += 2;
+                                       }
+                                       else {
+                                               output.Append ('%');
+                                       }
+                                       continue;
+                               }
+
+                               if (bytes.Length > 0) {
+                                       output.Append (GetChars (bytes, 
Encoding.UTF8));
+                                       bytes.SetLength (0);
+                               }
+
+                               output.Append (stringToUnescape [i]);
+                       }
+
+                       if (bytes.Length > 0) {
+                               output.Append (GetChars (bytes, Encoding.UTF8));
+                       }
+
+                       bytes = null;
+                       return output.ToString ();
                }
+
+               private static int GetInt (byte b)
+               {
+                       char c = (char) b;
+                       if (c >= '0' && c <= '9')
+                               return c - '0';
+
+                       if (c >= 'a' && c <= 'f')
+                               return c - 'a' + 10;
+
+                       if (c >= 'A' && c <= 'F')
+                               return c - 'A' + 10;
+
+                       return -1;
+               }
+
+               private static int GetChar (string str, int offset, int length)
+               {
+                       int val = 0;
+                       int end = length + offset;
+                       for (int i = offset; i < end; i++) {
+                               char c = str [i];
+                               if (c > 127)
+                                       return -1;
+
+                               int current = GetInt ((byte) c);
+                               if (current == -1)
+                                       return -1;
+                               val = (val << 4) + current;
+                       }
+
+                       return val;
+               }
+
+               private static char [] GetChars (MemoryStream b, Encoding e)
+               {
+                       return e.GetChars (b.GetBuffer (), 0, (int) b.Length);
+               }
+               
+
 #endif
        }
 }

Modified: trunk/mcs/class/System/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System/ChangeLog        2006-12-07 16:26:38 UTC 
(rev 69187)
+++ trunk/mcs/class/System/Test/System/ChangeLog        2006-12-07 16:31:37 UTC 
(rev 69188)
@@ -1,3 +1,7 @@
+2006-12-07  Vladimir Krasnov  <[EMAIL PROTECTED]>
+
+       * UriTest3.cs: Added tests for Uri.UnescapeDataString
+
 2006-08-01  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * UriTest.cs : added Equals3(), for bug #78799.

Modified: trunk/mcs/class/System/Test/System/UriTest3.cs
===================================================================
--- trunk/mcs/class/System/Test/System/UriTest3.cs      2006-12-07 16:26:38 UTC 
(rev 69187)
+++ trunk/mcs/class/System/Test/System/UriTest3.cs      2006-12-07 16:31:37 UTC 
(rev 69188)
@@ -297,6 +297,14 @@
                        // it doesn't work. MS.NET also returns incorrect URI: 
..303/?query
                        // Assert.AreEqual 
("http://www.mono-project.com:303/foo?query";, e.OriginalString, "#4");
                }
+
+               [Test]
+               public void UnescapeDataString ()
+               {
+                       Assert.AreEqual ("/new folder/", Uri.UnescapeDataString 
("/new%20folder/"));
+                       Assert.AreEqual ("/new folder/", Uri.UnescapeDataString 
("/new%20%66older/"));
+                       Assert.AreEqual ("/new+folder/", Uri.UnescapeDataString 
("/new+folder/"));
+               }
        }
 }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to