Author: atsushi
Date: 2005-06-29 03:02:42 -0400 (Wed, 29 Jun 2005)
New Revision: 46706

Modified:
   trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog
   trunk/mcs/class/corlib/Mono.Globalization.Unicode/Collation-notes.txt
   trunk/mcs/class/corlib/Mono.Globalization.Unicode/SortKeyBuffer.cs
   trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs
Log:
2005-06-29  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * SortKeyBuffer.cs : handle special weight (category 06) characters.
        * Collation-notes.txt : Updated description on special weight (it was
          incorrect).
        * TestDriver.cs : added special weight cases.



Modified: trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog 2005-06-29 
06:39:48 UTC (rev 46705)
+++ trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog 2005-06-29 
07:02:42 UTC (rev 46706)
@@ -1,5 +1,12 @@
 2005-06-29  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * SortKeyBuffer.cs : handle special weight (category 06) characters.
+       * Collation-notes.txt : Updated description on special weight (it was
+         incorrect).
+       * TestDriver.cs : added special weight cases.
+
+2005-06-29  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * MSCompatUnicodeTable.template : added GetTailoringInfo().
        * SimpleCollator.cs : Now tailoring information is acquired and used.
          (FrenchSort is supported but Compare() won't work expectedly since

Modified: trunk/mcs/class/corlib/Mono.Globalization.Unicode/Collation-notes.txt
===================================================================
--- trunk/mcs/class/corlib/Mono.Globalization.Unicode/Collation-notes.txt       
2005-06-29 06:39:48 UTC (rev 46705)
+++ trunk/mcs/class/corlib/Mono.Globalization.Unicode/Collation-notes.txt       
2005-06-29 07:02:42 UTC (rev 46706)
@@ -299,16 +299,37 @@
 
 **** level 5
 
-       [offsetL]* [offsetM + 0x7F]? [3 + offsetS * 4] [6] [char-weight]
+       UPDATED: I noticed offsetL does not exist, so removed it from here.
 
-       where all "offsetL" "offsetM" and "offsetS" represents the offset
-       from the previous level 5 character in the resulting string.
-       "offsetL" continues until the value is 0xFF.
-       "offsetM" is always larger than 0x80.
+       [offsetM + 0x80]? [const 3 + (offsetS + 1) * 4] [category] [level1]
 
-       The actual offset is 8064 * numOffsetL + 63 * offsetM + offsetS
+       where "offsetM" and "offsetS" represents the offset in the input
+       string. "offsetM" is always larger than 0x80.
+       LAMESPEC: This design results in a buggy overflow.
 
-       ('3' may actually vary and/or represent another values but no idea.
+       <xmp>
+       byte [] data = new CultureInfo ("").CompareInfo.GetSortKey (s).KeyData;
+       int idx = 0;
+       for (int i = 0; i < 4; i++, idx++)
+               for (; data [idx] != 1; idx++)
+                       ;
+       for (; idx < data.Length; idx++)
+               Console.Write ("{0:X02} ", data [idx]);
+       Console.WriteLine ();
+       </xmp>
+
+       inputs (s) and results:
+
+       80 07 06 82 80 2F 06 82 00 // '-' + new string ('A', 10) + '-'
+       80 07 06 82 81 97 06 82 00 // (100)
+       80 07 06 82 8F A7 06 82 00 // (1000)
+       80 07 06 82 9C 47 06 82 00 // (10000)
+       80 07 06 82 9A 87 06 82 00 // (100000)
+       80 07 06 82 89 07 06 82 00 // (1000000)
+
+       The actual offset is 63 * offsetM + offsetS
+
+       (const '3' may actually vary but no idea.
        At least 00, 01 and 02 are not acceptable since they are reserved.
        02 is not reserved by definition above, but the key-size optimizer
        uses it as a special mark, as mentioned above.)

Modified: trunk/mcs/class/corlib/Mono.Globalization.Unicode/SortKeyBuffer.cs
===================================================================
--- trunk/mcs/class/corlib/Mono.Globalization.Unicode/SortKeyBuffer.cs  
2005-06-29 06:39:48 UTC (rev 46705)
+++ trunk/mcs/class/corlib/Mono.Globalization.Unicode/SortKeyBuffer.cs  
2005-06-29 07:02:42 UTC (rev 46706)
@@ -121,6 +121,12 @@
                        if (lv3 == 0)
                                lv3 = 2;
 
+                       // Special weight processing
+                       if (category == 6 && (options & 
CompareOptions.StringSort) == 0) {
+                               AppendLevel5 (category, lv1);
+                               return;
+                       }
+
                        // non-primary diacritical weight is added to that of
                        // the previous character (and does not reset level 3
                        // weight).
@@ -139,22 +145,31 @@
                }
 
                // Append variable-weight character.
-               internal void AppendLevel5 (byte [] table, int idx, int 
currentIndex)
+               // It uses level 2 index for counting offsets (since level1
+               // might be longer than 1).
+               private void AppendLevel5 (byte category, byte lv1)
                {
                        // offset
-                       int offsetValue = currentIndex - level5LastPos;
+#if FALSE
+                       // If it strictly matches to Windows, offsetValue is 
always l2.
+                       int offsetValue = l2 - level5LastPos;
+                       // If it strictly matches ti Windows, no 0xFF here.
                        for (; offsetValue > 8064; offsetValue -= 8064)
                                AppendBufferPrimitive (0xFF, ref l5b, ref l5);
-                       if (offsetValue > 63)
-                               AppendBufferPrimitive ((byte) (offsetValue - 63 
/ 4 + 0x80), ref l5b, ref l5);
-                       AppendBufferPrimitive ((byte) (offsetValue % 63), ref 
l5b, ref l5);
+#else
+                       // LAMESPEC: Windows cannot compute lv5 values for
+                       // those string that has length larger than 8064.
+                       // (It reminds me of SQL Server varchar length).
+                       int offsetValue = l2 % 8064;
+#endif
+                       AppendBufferPrimitive ((byte) ((offsetValue / 63) * 4 + 
0x80), ref l5b, ref l5);
+                       AppendBufferPrimitive ((byte) (offsetValue % 63 * 4 + 
7), ref l5b, ref l5);
 
-                       level5LastPos = currentIndex;
+                       level5LastPos = l2;
 
                        // sortkey value
-                       idx++; // skip the "variable" mark: 01
-                       while (table [idx] != 0)
-                               AppendBufferPrimitive (table [idx++], ref l5b, 
ref l5);
+                       AppendBufferPrimitive (category, ref l5b, ref l5);
+                       AppendBufferPrimitive (lv1, ref l5b, ref l5);
                }
 
                private void AppendBufferPrimitive (byte value, ref byte [] 
buf, ref int bidx)

Modified: trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs
===================================================================
--- trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs     
2005-06-29 06:39:48 UTC (rev 46705)
+++ trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs     
2005-06-29 07:02:42 UTC (rev 46706)
@@ -24,6 +24,9 @@
                        DumpSortKey ("AE");
                        DumpSortKey ("\u00C6");
                        DumpSortKey ("ABCABC", 5, 1, CompareOptions.IgnoreCase);
+                       DumpSortKey ("-");
+                       DumpSortKey ("--");
+                       DumpSortKey ("A-B-C");
 
                        Compare ("1", "2");
                        Compare ("A", "a");

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

Reply via email to