Author: atsushi
Date: 2007-05-25 09:24:10 -0400 (Fri, 25 May 2007)
New Revision: 77944

Added:
   trunk/mcs/class/corlib/System.Globalization/IdnMapping.cs
   trunk/mcs/class/corlib/Test/System.Globalization/IdnMappingTest.cs
Modified:
   trunk/mcs/class/corlib/System.Globalization/ChangeLog
   trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
   trunk/mcs/class/corlib/corlib.dll.sources
   trunk/mcs/class/corlib/corlib_test.dll.sources
Log:
2007-05-25  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * IdnMapping.cs : new 2.0 class.

        * IdnMappingTest.cs : new test.

        * corlib.dll.sources : added MissingSatelliteAssemblyException.cs
          and IdnMapping.cs. Removed obsolete 2.0 NotCancelableException.cs.
        * corlib_test.dll.sources : added IdnMappingTest.cs.



Modified: trunk/mcs/class/corlib/System.Globalization/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Globalization/ChangeLog       2007-05-25 
13:18:08 UTC (rev 77943)
+++ trunk/mcs/class/corlib/System.Globalization/ChangeLog       2007-05-25 
13:24:10 UTC (rev 77944)
@@ -1,3 +1,7 @@
+2007-05-25  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * IdnMapping.cs : new 2.0 class.
+
 2007-05-17  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * DateTimeFormatInfo.cs : added roundtrip pattern (only in 2.0).

Added: trunk/mcs/class/corlib/System.Globalization/IdnMapping.cs
===================================================================
--- trunk/mcs/class/corlib/System.Globalization/IdnMapping.cs   2007-05-25 
13:18:08 UTC (rev 77943)
+++ trunk/mcs/class/corlib/System.Globalization/IdnMapping.cs   2007-05-25 
13:24:10 UTC (rev 77944)
@@ -0,0 +1,495 @@
+//
+// IdnMapping.cs
+//
+// Author:
+//     Atsushi Enomoto  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+/*
+
+** related RFCs
+
+       RFC 3490: IDNA
+       RFC 3491: Nameprep
+       RFC 3492: Punycode
+       RFC 3454: STRINGPREP
+
+Prohibited in [Nameprep]: C.1.2, C.2.2, C.3 - C.9 in [STRINGPREP]
+
+       C.1.2 non-ascii spaces (00A0, 1680, 2000-200B, 202F, 205F, 3000)
+       C.2.2 non-ascii controls (0080-009F, 06DD, 070F, 180E, 200C, 200D,
+             2028, 2029, 2060-2063, 206A-206F, FEFF, FFF9-FFFC, 1D173-1D17A)
+       C.3 private use (E000-F8FF, F0000-FFFFD, 100000-10FFFD)
+       C.4 non-characters (FDD0-FDEF, FFFE-FFFF, nFFFE-nFFFF)
+       C.5 surrogate code (D800-DFFF)
+       C.6 inappropriate for plain text (FFF9-FFFD)
+       C.7 inappropriate for canonical representation (2FF0-2FFB)
+       C.8 change display properties or are deprecated (0340, 0341,
+               200E, 200F, 202A-202E, 206A-206F)
+       C.9 tagging characters (E0001, E0020-E007F)
+
+*/
+
+using System;
+using System.Text;
+
+namespace System.Globalization
+{
+       public sealed class IdnMapping
+       {
+               bool allow_unassigned, use_std3;
+               Punycode puny = new Punycode ();
+
+               public IdnMapping ()
+               {
+               }
+
+               public bool AllowUnassigned {
+                       get { return allow_unassigned; }
+                       set { allow_unassigned = value; }
+               }
+
+               public bool UseStd3AsciiRules {
+                       get { return use_std3; }
+                       set { use_std3 = value; }
+               }
+
+               public override bool Equals (object obj)
+               {
+                       IdnMapping other = obj as IdnMapping;
+                       return other != null &&
+                              allow_unassigned == other.allow_unassigned &&
+                              use_std3 == other.use_std3;
+               }
+
+               public override int GetHashCode ()
+               {
+                       return (allow_unassigned ? 2 : 0) + (use_std3 ? 1 : 0);
+               }
+
+               #region GetAscii
+
+               public string GetAscii (string unicode)
+               {
+                       if (unicode == null)
+                               throw new ArgumentNullException ("unicode");
+                       return GetAscii (unicode, 0, unicode.Length);
+               }
+
+               public string GetAscii (string unicode, int index)
+               {
+                       if (unicode == null)
+                               throw new ArgumentNullException ("unicode");
+                       return GetAscii (unicode, index, unicode.Length - 
index);
+               }
+
+               public string GetAscii (string unicode, int index, int count)
+               {
+                       if (unicode == null)
+                               throw new ArgumentNullException ("unicode");
+                       if (index < 0)
+                               throw new ArgumentOutOfRangeException ("index 
must be non-negative value");
+                       if (count < 0 || index + count > unicode.Length)
+                               throw new ArgumentOutOfRangeException ("index + 
count must point inside the argument unicode string");
+
+                       return Convert (unicode, index, count, true);
+               }
+
+               string Convert (string input, int index, int count, bool 
toAscii)
+               {
+                       string s = input.Substring (index, count);
+
+                       // Actually lowering string is done as part of
+                       // Nameprep(), but it is much easier to do it in prior.
+                       for (int i = 0; i < s.Length; i++)
+                               if (s [i] >= '\x80') {
+                                       s = s.ToLower 
(CultureInfo.InvariantCulture);
+                                       break;
+                               }
+
+                       // RFC 3490 section 4. and 4.1
+                       // 1) -> done as AllowUnassigned property
+                       // 2) split the input
+                       string [] labels = s.Split ('.', '\u3002', '\uFF0E', 
'\uFF61');
+                       int iter = 0;
+                       for (int i = 0; i < labels.Length; iter += labels 
[i].Length, i++) {
+                               // 3) -> done as UseStd3AsciiRules property
+                               // 4) ToAscii
+                               if (labels [i].Length == 0 && i + 1 == 
labels.Length)
+                                       // If the input ends with '.', Split()
+                                       // adds another empty string. In that
+                                       // case, we have to ignore it.
+                                       continue;
+                               if (toAscii)
+                                       labels [i] = ToAscii (labels [i], iter);
+                               else
+                                       labels [i] = ToUnicode (labels [i], 
iter);
+                       }
+                       // 5) join them
+                       return String.Join (".", labels);
+               }
+
+               string ToAscii (string s, int offset)
+               {
+                       // 1.
+                       for (int i = 0; i < s.Length; i++) {
+                               // I wonder if this check is really 
RFC-conformant
+                               if (s [i] < '\x20' || s [i] == '\x7F')
+                                       throw new ArgumentException 
(String.Format ("Not allowed character was found, at {0}", offset + i));
+                               if (s [i] >= 0x80) {
+                                       // 2.
+                                       s = NamePrep (s, offset);
+                                       break;
+                               }
+                       }
+
+                       // 3.
+                       if (use_std3)
+                               VerifyStd3AsciiRules (s, offset);
+
+                       // 4.
+                       for (int i = 0; i < s.Length; i++) {
+                               if (s [i] >= 0x80) {
+                                       // 5. check ACE.
+                                       if (s.StartsWith ("xn--", 
StringComparison.OrdinalIgnoreCase))
+                                               throw new ArgumentException 
(String.Format ("The input string must not start with ACE (xn--), at {0}", 
offset + i));
+                                       // 6. Punycode it.
+                                       s = puny.Encode (s, offset);
+                                       // 7. prepend ACE.
+                                       s = "xn--" + s;
+                                       break;
+                               }
+                       }
+
+                       // 8.
+                       VerifyLength (s, offset);
+
+                       return s;
+               }
+
+               void VerifyLength (string s, int offset)
+               {
+                       if (s.Length == 0)
+                               throw new ArgumentException (String.Format ("A 
label in the input string resulted in an invalid zero-length string, at {0}", 
offset));
+                       if (s.Length > 63)
+                               throw new ArgumentException (String.Format ("A 
label in the input string exceeded the length in ASCII representation, at {0}", 
offset));
+               }
+
+               string NamePrep (string s, int offset)
+               {
+                       s = s.Normalize (NormalizationForm.FormKC);
+                       VerifyProhibitedCharacters (s, offset);
+                       // FIXME: check BIDI
+
+                       if (!allow_unassigned) {
+                               for (int i = 0; i < s.Length; i++)
+                                       if (Char.GetUnicodeCategory (s, i) == 
UnicodeCategory.OtherNotAssigned)
+                                               throw new ArgumentException 
(String.Format ("Use of unassigned Unicode characer is prohibited in this 
IdnMapping, at {0}", offset + i));
+                       }
+                       return s;
+               }
+
+               void VerifyProhibitedCharacters (string s, int offset)
+               {
+                       for (int i = 0; i < s.Length; i++) {
+                               switch (Char.GetUnicodeCategory (s, i)) {
+                               case UnicodeCategory.SpaceSeparator:
+                                       if (s [i] < '\x80')
+                                               continue; // valid
+                                       break;
+                               case UnicodeCategory.Control:
+                                       if (s [i] != '\x0' && s [i] < '\x80')
+                                               continue; // valid
+                                       break;
+                               case UnicodeCategory.PrivateUse:
+                               case UnicodeCategory.Surrogate:
+                                       break;
+                               default:
+                                       char c = s [i];
+                                       if (// C.4
+                                           '\uFDDF' <= c && c <= '\uFDEF' ||
+                                           ((int) c & 0xFFFF) == 0xFFFE ||
+                                           // C.6
+                                           '\uFFF9' <= c && c <= '\uFFFD' ||
+                                           // C.7
+                                           '\u2FF0' <= c && c <= '\u2FFB' ||
+                                           // C.8
+                                           '\u202A' <= c && c <= '\u202E' ||
+                                           '\u206A' <= c && c <= '\u206F')
+                                               break;
+                                       switch (c) {
+                                       // C.8
+                                       case '\u0340':
+                                       case '\u0341':
+                                       case '\u200E':
+                                       case '\u200F':
+                                       // C.2.2
+                                       case '\u2028':
+                                       case '\u2029':
+                                               break;
+                                       default:
+                                               continue;
+                                       }
+                                       break;
+                               }
+                               throw new ArgumentException (String.Format 
("Not allowed character was in the input string, at {0}", offset + i));
+                       }
+               }
+
+               void VerifyStd3AsciiRules (string s, int offset)
+               {
+                       if (s.Length > 0 && s [0] == '-')
+                               throw new ArgumentException (String.Format 
("'-' is not allowed at head of a sequence in STD3 mode, found at {0}", 
offset));
+                       if (s.Length > 0 && s [s.Length - 1] == '-')
+                               throw new ArgumentException (String.Format 
("'-' is not allowed at tail of a sequence in STD3 mode, found at {0}", offset 
+ s.Length - 1));
+
+                       for (int i = 0; i < s.Length; i++) {
+                               char c = s [i];
+                               if (c == '-')
+                                       continue;
+                               if (c <= '\x2F' || '\x3A' <= c && c <= '\x40' 
|| '\x5B' <= c && c <= '\x60' || '\x7B' <= c && c <= '\x7F')
+                                       throw new ArgumentException 
(String.Format ("Not allowed character in STD3 mode, found at {0}", offset + 
i));
+                       }
+               }
+
+               #endregion
+
+               public string GetUnicode (string ascii)
+               {
+                       if (ascii == null)
+                               throw new ArgumentNullException ("ascii");
+                       return GetUnicode (ascii, 0, ascii.Length);
+               }
+
+               public string GetUnicode (string ascii, int index)
+               {
+                       if (ascii == null)
+                               throw new ArgumentNullException ("ascii");
+                       return GetUnicode (ascii, index, ascii.Length - index);
+               }
+
+               public string GetUnicode (string ascii, int index, int count)
+               {
+                       if (ascii == null)
+                               throw new ArgumentNullException ("ascii");
+                       if (index < 0)
+                               throw new ArgumentOutOfRangeException ("index 
must be non-negative value");
+                       if (count < 0 || index + count > ascii.Length)
+                               throw new ArgumentOutOfRangeException ("index + 
count must point inside the argument ascii string");
+
+                       return Convert (ascii, index, count, false);
+               }
+
+               string ToUnicode (string s, int offset)
+               {
+                       // 1.
+                       for (int i = 0; i < s.Length; i++) {
+                               if (s [i] >= 0x80) {
+                                       // 2.
+                                       s = NamePrep (s, offset);
+                                       break;
+                               }
+                       }
+
+                       // 3.
+                       if (!s.StartsWith ("xn--", 
StringComparison.OrdinalIgnoreCase))
+                               return s; // failure = return the input string 
as is.
+                       // Actually lowering string is done as part of
+                       // Nameprep(), but it is much easier to do it in prior.
+                       s = s.ToLower (CultureInfo.InvariantCulture);
+
+                       string at3 = s;
+
+                       // 4.
+                       s = s.Substring (4);
+
+                       // 5.
+                       s = puny.Decode (s, offset);
+                       string at5 = s;
+
+                       // 6.
+                       s = ToAscii (s, offset);
+
+                       // 7.
+                       if (String.Compare (at3, s, 
StringComparison.OrdinalIgnoreCase) != 0)
+                               throw new ArgumentException (String.Format 
("ToUnicode() failed at verifying the result, at label part from {0}", offset));
+
+                       // 8.
+                       return at5;
+               }
+       }
+
+       class Bootstring
+       {
+               readonly char delimiter;
+               readonly int base_num, tmin, tmax, skew, damp, initial_bias, 
initial_n;
+               
+               public Bootstring (char delimiter,
+                                int baseNum, int tmin, int tmax,
+                                int skew, int damp,
+                                int initialBias, int initialN)
+               {
+                       this.delimiter = delimiter;
+                       base_num = baseNum;
+                       this.tmin = tmin;
+                       this.tmax = tmax;
+                       this.skew = skew;
+                       this.damp = damp;
+                       initial_bias = initialBias;
+                       initial_n = initialN;
+               }
+
+               public string Encode (string s, int offset)
+               {
+                       int n = initial_n;
+                       int delta = 0;
+                       int bias = initial_bias;
+                       int b = 0, h = 0;
+                       StringBuilder sb = new StringBuilder ();
+                       for (int i = 0; i < s.Length; i++)
+                               if (s [i] < '\x80')
+                                       sb.Append (s [i]);
+                       b = h = sb.Length;
+                       if (b > 0)
+                               sb.Append (delimiter);
+
+                       while (h < s.Length) {
+                               int m = int.MaxValue;
+                               for (int i = 0; i < s.Length; i++)
+                                       if (s [i] >= n && s [i] < m)
+                                               m = s [i];
+                               checked { delta += (m - n) * (h + 1); }
+                               n = m;
+                               for (int i = 0; i < s.Length; i++) {
+                                       char c = s [i];
+                                       if (c < n || c < '\x80')
+                                               checked { delta++; }
+                                       if (c == n) {
+                                               int q = delta;
+                                               for (int k = base_num; ;k += 
base_num) {
+                                                       int t =
+                                                               k <= bias + 
tmin ? tmin :
+                                                               k >= bias + 
tmax ? tmax :
+                                                               k - bias;
+                                                       if (q < t)
+                                                               break;
+                                                       sb.Append (EncodeDigit 
(t + (q - t) % (base_num - t)));
+                                                       q = (q - t) / (base_num 
- t);
+                                               }
+                                               sb.Append (EncodeDigit (q));
+                                               bias = Adapt (delta, h + 1, h 
== b);
+                                               delta = 0;
+                                               h++;
+                                       }
+                               }
+                               delta++;
+                               n++;
+                       }
+
+                       return sb.ToString ();
+               }
+
+               // 41..5A (A-Z) = 0-25
+               // 61..7A (a-z) = 0-25
+               // 30..39 (0-9) = 26-35
+               char EncodeDigit (int d)
+               {
+                       return (char) (d < 26 ? d + 'a' : d - 26 + '0');
+               }
+
+               int DecodeDigit (char c)
+               {
+                       return  c - '0' < 10 ? c - 22 :
+                               c - 'A' < 26 ? c - 'A' :
+                               c - 'a' < 26 ? c - 'a' : base_num;
+               }
+
+               int Adapt (int delta, int numPoints, bool firstTime)
+               {
+                       if (firstTime)
+                               delta = delta / damp;
+                       else
+                               delta = delta / 2;
+                       delta = delta + (delta / numPoints);
+                       int k = 0;
+                       while (delta > ((base_num - tmin) * tmax) / 2) {
+                               delta = delta / (base_num - tmin);
+                               k += base_num;
+                       }
+                       return k + (((base_num - tmin + 1) * delta) / (delta + 
skew));
+               }
+
+               public string Decode (string s, int offset)
+               {
+                       int n = initial_n;
+                       int i = 0;
+                       int bias = initial_bias;
+                       int b = 0;
+                       StringBuilder sb = new StringBuilder ();
+
+                       for (int j = 0; j < s.Length; j++) {
+                               if (s [j] == delimiter)
+                                       b = j;
+                       }
+                       if (b < 0)
+                               return s;
+                       sb.Append (s, 0, b);
+
+                       for (int z = b > 0 ? b + 1 : 0; z < s.Length; ) {
+                               int old_i = i;
+                               int w = 1;
+                               for (int k = base_num; ; k += base_num) {
+                                       int digit = DecodeDigit (s [z++]);
+                                       i = i + digit * w;
+                                       int t = k <= bias + tmin ? tmin :
+                                               k >= bias + tmax ? tmax :
+                                               k - bias;
+                                       if (digit < t)
+                                               break;
+                                       w = w * (base_num - t);
+                               }
+                               bias = Adapt (i - old_i, sb.Length + 1, old_i 
== 0);
+                               n = n + i / (sb.Length + 1);
+                               i = i % (sb.Length + 1);
+                               if (n < '\x80')
+                                       throw new ArgumentException 
(String.Format ("Invalid Bootstring decode result, at {0}", offset + z));
+                               sb.Insert (i, (char) n);
+                               i++;
+                       }
+
+                       return sb.ToString ();
+               }
+       }
+
+       class Punycode : Bootstring
+       {
+               public Punycode ()
+                       : base ('-', 36, 1, 26, 38, 700, 72, 0x80)
+               {
+               }
+       }
+}
+#endif

Modified: trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog  2007-05-25 
13:18:08 UTC (rev 77943)
+++ trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog  2007-05-25 
13:24:10 UTC (rev 77944)
@@ -1,3 +1,7 @@
+2007-05-25  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * IdnMappingTest.cs : new test.
+
 2007-05-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * RegionInfoTest.cs : new tests.

Added: trunk/mcs/class/corlib/Test/System.Globalization/IdnMappingTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/IdnMappingTest.cs  
2007-05-25 13:18:08 UTC (rev 77943)
+++ trunk/mcs/class/corlib/Test/System.Globalization/IdnMappingTest.cs  
2007-05-25 13:24:10 UTC (rev 77944)
@@ -0,0 +1,197 @@
+//
+// IdnMappingTest.cs
+//
+// Author:
+//     Atsushi Enomoto  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2007 Novell, Inc. (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using NUnit.Framework;
+using System.IO;
+using System;
+using System.Globalization;
+using System.Threading;
+using System.Text;
+
+namespace MonoTests.System.Globalization
+{
+       [TestFixture]
+       public class IdnMappingTest
+       {
+               void GetAscii (IdnMapping m, string source, string expected, 
object label)
+               {
+                       Assert.AreEqual (expected, m.GetAscii (source), label 
!= null ? label.ToString () : expected);
+               }
+
+               void GetAsciiInvalid (IdnMapping m, string s, object label)
+               {
+                       try {
+                               m.GetAscii (s);
+                               Assert.Fail (label != null ? label.ToString () 
+ ":" + s : s);
+                       } catch (ArgumentException) {
+                       }
+               }
+
+               void GetUnicode (IdnMapping m, string source, string expected, 
object label)
+               {
+                       Assert.AreEqual (expected, m.GetUnicode (source), label 
!= null ? label.ToString () : expected);
+               }
+
+               void GetUnicodeInvalid (IdnMapping m, string s, object label)
+               {
+                       try {
+                               m.GetUnicode (s);
+                               Assert.Fail (label != null ? label.ToString () 
+ ":" + s : s);
+                       } catch (ArgumentException) {
+                       }
+               }
+
+               [Test]
+               public void GetAsciiInvalid ()
+               {
+                       // hmm... according to RFC 3490, there are couple of
+                       // invalid characters in RFC 3491 [Nameprop] ...
+                       // comment out them for now.
+
+                       IdnMapping m = new IdnMapping ();
+                       GetAsciiInvalid (m, "\x0", 1);
+                       GetAsciiInvalid (m, "\xD\xA", 2);
+                       GetAsciiInvalid (m, "\x1F", 3);
+                       GetAsciiInvalid (m, "\x7F", 4);
+                       GetAsciiInvalid (m, "\x80", 5);
+                       // GetAsciiInvalid (m, "\xA0", 6);
+                       // GetAsciiInvalid (m, "\u1680", 7);
+                       GetAsciiInvalid (m, "\u200E", 8);
+                       // GetAsciiInvalid (m, "\u0341", 9);
+                       GetAsciiInvalid (m, "\uE000", 10);
+                       GetAsciiInvalid (m, "\uFFFF", 11);
+                       GetAsciiInvalid (m, "\u2028", 12);
+                       GetAsciiInvalid (m, "\uD800", 13);
+                       // GetAsciiInvalid (m, "\u3000", 14);
+               }
+
+               [Test]
+               public void GetAscii ()
+               {
+                       IdnMapping m = new IdnMapping ();
+                       GetAscii (m, "www.mono-project.com", 
"www.mono-project.com", 1);
+                       GetAscii (m, "a\uFF61b", "a.b", 2);
+
+                       // umm... does it reject anything larger than U+FFFF ??
+                       // GetAscii (m, "\uD800\uDC00", "", 3);
+
+                       // hmm, according to RFC 3490, ToASCII never changes
+                       // the input whose codepoints are all within ASCII.
+                       GetAscii (m, "A\uFF61B", "a.b", 4);
+                       GetAscii (m, "A.B", "A.B", 5); // no lowercasing
+               }
+
+               [Test]
+               public void Dots ()
+               {
+                       IdnMapping m = new IdnMapping ();
+                       GetAsciiInvalid (m, ".", 1);
+                       GetAsciiInvalid (m, "\uFF61", 2);
+                       GetAscii (m, "Am running now.", "Am running now.", 3);
+                       GetAsciiInvalid (m, ".bashrc", 4);
+               }
+
+               [Test]
+               public void UnassignedCharacter ()
+               {
+                       IdnMapping m = new IdnMapping ();
+                       GetAsciiInvalid (m, "\u0221.com", 1);
+                       m.AllowUnassigned = true;
+                       GetAscii (m, "\u0221.com", "xn--6la.com", 2);
+               }
+
+               [Test]
+               public void UseStd3AsciiRules ()
+               {
+                       IdnMapping m = new IdnMapping ();
+                       GetAscii (m, "-_-.com", "-_-.com", 1);
+                       m.UseStd3AsciiRules = true;
+                       GetAsciiInvalid (m, "a b.com", 1.5);
+                       GetAsciiInvalid (m, "_.com", 2);
+                       GetAsciiInvalid (m, "-abc.com", 3);
+                       GetAscii (m, "abc-def.com", "abc-def.com", 4); // 
hyphen in the middle is okay
+                       GetAsciiInvalid (m, "abc-.def.com", 5); // hyphen is 
*not* in the middle.
+               }
+
+               [Test]
+               public void AcePrefix ()
+               {
+                       IdnMapping m = new IdnMapping ();
+                       GetAscii (m, "bl--.com", "bl--.com", 1); // only ascii
+                       GetAscii (m, "bl--\xC0.com", "xn--bl---3na.com", 2);
+                       GetAscii (m, "xn--.com", "xn--.com", 3); // only ascii
+                       GetAsciiInvalid (m, "xn--\xC0.com", 4);
+                       GetAsciiInvalid (m, "xN--\xC0.com", 5);
+                       GetAsciiInvalid (m, "Xn--\xC0.com", 6);
+                       GetAsciiInvalid (m, "XN--\xC0.com", 7);
+                       GetAscii (m, "xN\xC0.com", "xn--xn-kia.com", 8);
+                       GetAscii (m, "bl--\xC0.wl--\xC0.com", 
"xn--bl---3na.xn--wl---3na.com", 9);
+               }
+
+               [Test]
+               public void GetAsciiRFC3492Examples ()
+               {
+                       IdnMapping m = new IdnMapping ();
+                       // 3<nen>B<gumi><kin><pachi><sen><sei>
+                       GetAscii (m, "3\u5E74B\u7D44\u91D1\u516B\u5148\u751F", 
"xn--3b-ww4c5e180e575a65lsy2b", "(L)");
+                       // Maji<de>Koi<suru>5<byoumae>
+                       GetAscii (m, "Maji\u3067Koi\u3059\u308B5\u79D2\u524D", 
"xn--majikoi5-783gue6qz075azm5e", "(P)");
+               }
+
+               [Test]
+               public void GetUnicode ()
+               {
+                       IdnMapping m = new IdnMapping ();
+                       GetAscii (m, "www.mono-project.com", 
"www.mono-project.com", 1);
+                       GetAscii (m, "a\uFF61b", "a.b", 2);
+
+                       // umm... does it reject anything larger than U+FFFF ??
+                       // GetAscii (m, "\uD800\uDC00", "", 3);
+
+                       // hmm, according to RFC 3490, ToASCII never changes
+                       // the input whose codepoints are all within ASCII.
+                       GetAscii (m, "A\uFF61B", "a.b", 4);
+                       GetAscii (m, "A.B", "A.B", 5); // no lowercasing
+               }
+
+               [Test]
+               public void GetUnicodeRFC3492Examples ()
+               {
+                       // uppercases in the ASCII strings are ignored.
+                       IdnMapping m = new IdnMapping ();
+                       // 3<nen>B<gumi><kin><pachi><sen><sei>
+                       GetUnicode (m, "xn--3B-ww4c5e180e575a65lsy2b", 
"3\u5E74b\u7D44\u91D1\u516B\u5148\u751F", "(L)");
+                       // Maji<de>Koi<suru>5<byoumae>
+                       GetUnicode (m, "xn--MajiKoi5-783gue6qz075azm5e", 
"maji\u3067koi\u3059\u308B5\u79D2\u524D", "(P)");
+               }
+       }
+}
+
+#endif

Modified: trunk/mcs/class/corlib/corlib.dll.sources
===================================================================
--- trunk/mcs/class/corlib/corlib.dll.sources   2007-05-25 13:18:08 UTC (rev 
77943)
+++ trunk/mcs/class/corlib/corlib.dll.sources   2007-05-25 13:24:10 UTC (rev 
77944)
@@ -216,7 +216,6 @@
 System/RuntimeMethodHandle.cs
 System/RuntimeTypeHandle.cs
 System/ModuleHandle.cs
-System/NotCancelableException.cs
 System/SByte.cs
 System/SerializableAttribute.cs
 System/Single.cs
@@ -333,6 +332,7 @@
 System.Globalization/GregorianCalendarTypes.cs
 System.Globalization/HebrewCalendar.cs
 System.Globalization/HijriCalendar.cs
+System.Globalization/IdnMapping.cs
 System.Globalization/JapaneseCalendar.cs
 System.Globalization/JulianCalendar.cs
 System.Globalization/KoreanCalendar.cs
@@ -524,6 +524,7 @@
 System.Resources/IResourceReader.cs
 System.Resources/IResourceWriter.cs
 System.Resources/MissingManifestResourceException.cs
+System.Resources/MissingSatelliteAssemblyException.cs
 System.Resources/NeutralResourcesLanguageAttribute.cs
 System.Resources/ResourceManager.cs
 System.Resources/ResourceReader.cs

Modified: trunk/mcs/class/corlib/corlib_test.dll.sources
===================================================================
--- trunk/mcs/class/corlib/corlib_test.dll.sources      2007-05-25 13:18:08 UTC 
(rev 77943)
+++ trunk/mcs/class/corlib/corlib_test.dll.sources      2007-05-25 13:24:10 UTC 
(rev 77944)
@@ -58,6 +58,7 @@
 System.Globalization/CompareInfoTest.cs
 System.Globalization/CultureInfoTest.cs
 System.Globalization/DaylightTimeTest.cs
+System.Globalization/IdnMappingTest.cs
 System.Globalization/RegionInfoTest.cs
 System.Globalization/TextInfoTest.cs
 System/GuidTest.cs

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

Reply via email to