Author: atsushi
Date: 2005-07-14 14:21:07 -0400 (Thu, 14 Jul 2005)
New Revision: 47319

Modified:
   trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog
   trunk/mcs/class/corlib/Mono.Globalization.Unicode/SimpleCollator.cs
   trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs
   trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
   trunk/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs
Log:
2005-07-14  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * SimpleCollator.cs : more IsSuffix() simplification, but it will be
          stopped here since it cannot handle extenders (implementing new
          approach one).

        * CompareInfoTest.cs : added tests for IndexOf() and LastIndexOf()
          with ignorable source character. Added some non-working tests.



Modified: trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog 2005-07-14 
18:17:25 UTC (rev 47318)
+++ trunk/mcs/class/corlib/Mono.Globalization.Unicode/ChangeLog 2005-07-14 
18:21:07 UTC (rev 47319)
@@ -1,5 +1,11 @@
 2005-07-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * SimpleCollator.cs : more IsSuffix() simplification, but it will be
+         stopped here since it cannot handle extenders (implementing new
+         approach one).
+
+2005-07-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * SimpleCollator.cs : simplified IsSuffix() code.
 
 2005-07-14  Atsushi Enomoto  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/corlib/Mono.Globalization.Unicode/SimpleCollator.cs
===================================================================
--- trunk/mcs/class/corlib/Mono.Globalization.Unicode/SimpleCollator.cs 
2005-07-14 18:17:25 UTC (rev 47318)
+++ trunk/mcs/class/corlib/Mono.Globalization.Unicode/SimpleCollator.cs 
2005-07-14 18:21:07 UTC (rev 47319)
@@ -107,8 +107,6 @@
                byte [] charSortKey = new byte [4];
                byte [] charSortKey2 = new byte [4];
                byte [] charSortKeyIndexTarget = new byte [4];
-               // temporary expansion store for IsPrefix/Suffix
-               int escapedSourceIndex;
 
                #region Tailoring support classes
                // Possible mapping types are:
@@ -386,6 +384,7 @@
                        this.ignoreKanaType = (options & 
CompareOptions.IgnoreKanaType) != 0;
                        previousChar = previousChar2 = -1;
                        previousSortKey = previousSortKey2 = null;
+                       escape1.Source = escape2.Source = null;
                }
 
                Contraction GetContraction (string s, int start, int end)
@@ -810,23 +809,23 @@
                        return d1.Length == d2.Length ? 0 : d1.Length < 
d2.Length ? -1 : 1;
 #else
                        SetOptions (options);
-                       escape1.Source = null;
-                       escape2.Source = null;
-                       bool dummy;
-                       int ret = CompareInternal (s1, idx1, len1, s2, idx2, 
len2, (options & CompareOptions.StringSort) != 0, out dummy, true);
+                       bool dummy, dummy2;
+                       int ret = CompareInternal (s1, idx1, len1, s2, idx2, 
len2, (options & CompareOptions.StringSort) != 0, out dummy, out dummy2, true);
                        return ret == 0 ? 0 : ret < 0 ? -1 : 1;
 #endif
                }
 
                int CompareInternal (string s1, int idx1, int len1, string s2,
                        int idx2, int len2, bool stringSort,
-                       out bool targetConsumed, bool skipHeadingExtenders)
+                       out bool targetConsumed, out bool sourceConsumed,
+                       bool skipHeadingExtenders)
                {
                        int start1 = idx1;
                        int start2 = idx2;
                        int end1 = idx1 + len1;
                        int end2 = idx2 + len2;
                        targetConsumed = false;
+                       sourceConsumed = false;
 
                        // It holds final result that comes from the comparison
                        // at level 2 or lower. Even if Compare() found the
@@ -1155,8 +1154,12 @@
                                if (finalResult == 0)
                                        finalResult = lv5Value1 - lv5Value2;
                        }
-                       if (finalResult == 0 && idx2 == end2)
-                               targetConsumed = true;
+                       if (finalResult == 0) {
+                               if (idx2 == end2)
+                                       targetConsumed = true;
+                               if (idx1 == end1)
+                                       sourceConsumed = true;
+                       }
                        return idx1 != end1 ? 1 : idx2 == end2 ? finalResult : 
-1;
                }
 
@@ -1178,12 +1181,10 @@
 
                public bool IsPrefix (string s, string target, int start, int 
length, bool stringSort, bool skipHeadingExtenders)
                {
-                       bool consumed;
-                       escape1.Source = null;
-                       escape2.Source = null;
+                       bool consumed, dummy;
                        int ret = CompareInternal (s, start, length,
                                target, 0, target.Length, stringSort,
-                               out consumed, skipHeadingExtenders);
+                               out consumed, out dummy, skipHeadingExtenders);
                        return consumed;
                }
 
@@ -1196,8 +1197,6 @@
 
                public bool IsSuffix (string s, string target, int start, int 
length, CompareOptions opt)
                {
-                       SetOptions (opt);
-
                        // quick check : simple codepoint comparison
                        if (s.Length >= target.Length) {
                                int si = start;
@@ -1209,28 +1208,64 @@
                                        return true;
                        }
 
-                       escapedSourceIndex = -1;
-                       return IsSuffix (s, target, start, length);
+                       SetOptions (opt);
+                       return IsSuffix (s, target, start, length,
+                               (opt & CompareOptions.StringSort) != 0);
                }
 
-               bool IsSuffix (string s, string target, int start, int length)
+               bool New_IsSuffix (string s, string t, int start, int length,
+                       bool stringSort)
                {
+                       int tstart = 0;
+                       for (;tstart < t.Length; tstart++)
+                               if (!IsIgnorable (t [tstart]))
+                                       break;
+                       if (tstart == t.Length)
+                               return true; // as if target is String.Empty.
+
+                       // FIXME: could be more efficient.
+                       bool consumed, dummy;
+                       for (int i = 0; i < length; i++) {
+                               int ret = CompareInternal (s, start - i, i + 1,
+                                       t, tstart, t.Length, stringSort,
+                                       out dummy, out consumed, true);
+                               if (ret == 0)
+                                       return true;
+                       }
+                       return false;
+               }
+
+               // FIXME: This code has a fatal problem that it cannot handle
+               // extenders :(
+               bool IsSuffix (string s, string t, int start, int length,
+                       bool stringSort)
+               {
                        int si = start;
-                       int ti = target.Length - 1;
-                       string source = s;
+                       int ti = t.Length - 1;
                        int end = start - length + 1;
+                       int tend = 0;
 
-                       while (ti >= 0) {
-                               if (IsIgnorable (target [ti])) {
+                       while (true) {
+                               if (ti < tend) {
+                                       if (escape2.Source == null)
+                                               break;
+                                       t = escape2.Source;
+                                       ti = escape2.Index;
+                                       tend = escape2.End;
+                                       escape2.Source = null;
+                                       continue;
+                               }
+                               if (IsIgnorable (t [ti])) {
                                        ti--;
                                        continue;
                                }
-                               if (si < 0) {
-                                       if (s == source)
+                               if (si < end) {
+                                       if (escape1.Source == null)
                                                break;
-                                       s = source;
-                                       si = escapedSourceIndex;
-                                       escapedSourceIndex = -1;
+                                       s = escape1.Source;
+                                       si = escape1.Index;
+                                       end = escape1.End;
+                                       escape1.Source = null;
                                        continue;
                                }
                                if (IsIgnorable (s [si])) {
@@ -1238,30 +1273,53 @@
                                        continue;
                                }
 
+                               ExtenderType ext1 = GetExtenderType (s [si]);
+                               ExtenderType ext2 = GetExtenderType (t [ti]);
+                               int vt = -1;
+                               byte [] sk = null;
+
                                // Check contraction for target.
-                               Contraction ctt = GetTailContraction (target, 
ti, 0);
+                               Contraction ctt = null;
+                               if (ext2 != ExtenderType.None) {
+                                       if (previousChar2 < 0)
+                                               sk = previousSortKey2;
+                                       else
+                                               vt = FilterExtender 
(previousChar2, ext2);
+                               }
+                               else if (escape2.Source == null)
+                                       ctt = GetTailContraction (t, ti, 0);
                                if (ctt != null) {
-                                       ti -= ctt.Source.Length;
                                        if (ctt.SortKey != null) {
-                                               if (!MatchesBackward (ref s, 
ref si, ref end, -1, ctt.SortKey, true))
-                                                       return false;
+                                               ti -= ctt.Source.Length;
+                                               for (int i = 0; i < 
ctt.SortKey.Length; i++)
+                                                       charSortKey2 [i] = 
ctt.SortKey [i];
+                                               previousChar2 = -1;
+                                               previousSortKey2 = charSortKey2;
                                        } else {
-                                               string r = ctt.Replacement;
-                                               int i = r.Length - 1;
-                                               while (i >= 0 && si >= end) {
-                                                       if (!MatchesBackward 
(ref s, ref si, ref end, r [i]))
-                                                               return false;
-                                                       i--;
-                                               }
-                                               if (i >= 0 && si < end)
-                                                       return false;
+                                               escape2.Source = t;
+                                               escape2.Index = ti - 
ctt.Source.Length;
+                                               escape2.End = tend;
+                                               t = ctt.Replacement;
+                                               ti = ctt.Replacement.Length - 1;
+                                               tend = 0;
+                                               continue;
                                        }
-                               }
-                               else {
-                                       if (!MatchesBackward (ref s, ref si, 
ref end, target [ti]))
-                                               return false;
+                               } else if (sk == null) {
+                                       if (vt < 0)
+                                               vt = FilterOptions (t [ti]);
+                                       sk = charSortKey2;
+                                       sk [0] = Category (vt);
+                                       sk [1] = Level1 (vt);
+                                       if (!ignoreNonSpace)
+                                               // FIXME: pass extender type
+                                               sk [2] = Level2 (vt, ext2);
+                                       sk [3] = Uni.Level3 (vt);
+                                       if (sk [1] != 1)
+                                               previousChar2 = vt;
                                        ti--;
                                }
+                               if (!MatchesBackward (ref s, ref si, ref end, 
vt, sk, !Uni.HasSpecialWeight ((char) vt)))
+                                       return false;
                        }
                        if (si < end) {
                                // All codepoints in the compared range
@@ -1269,7 +1327,7 @@
                                // is whether the remaining part of 
                                // "target" is ignorable or not.
                                while (ti >= 0)
-                                       if (!IsIgnorable (target [ti--]))
+                                       if (!IsIgnorable (t [ti--]))
                                                return false;
                                return true;
                        }
@@ -1277,27 +1335,13 @@
                }
 
                // WARNING: Don't invoke it outside IsSuffix().
-               bool MatchesBackward (ref string s, ref int idx, ref int end, 
char target)
-               {
-                       int it = FilterOptions ((int) target);
-                       charSortKey [0] = Category (it);
-                       charSortKey [1] = Level1 (it);
-                       if (!ignoreNonSpace)
-                               // FIXME: pass extender type
-                               charSortKey [2] = Level2 (it, 
ExtenderType.None);
-                       charSortKey [3] = Uni.Level3 (it);
-
-                       return MatchesBackward (ref s, ref idx, ref end, it, 
charSortKey, !Uni.HasSpecialWeight ((char) it));
-               }
-
-               // WARNING: Don't invoke it outside IsSuffix().
                // returns consumed source length (mostly 1, source length in 
case of contraction)
                bool MatchesBackward (ref string s, ref int idx, ref int end, 
int it, byte [] sortkey, bool noLv4)
                {
                        Contraction ct = null;
                        // If there is already expansion, then it should not
                        // process further expansions.
-                       if (escapedSourceIndex < 0)
+                       if (escape1.Source == null)
                                ct = GetTailContraction (s, idx, end);
                        if (ct != null) {
                                if (ct.SortKey != null) {
@@ -1309,7 +1353,9 @@
                                        idx -= ct.Source.Length;
                                        return true;
                                } else {
-                                       escapedSourceIndex = idx - 
ct.Source.Length;
+                                       escape1.Source = s;
+                                       escape1.Index = idx - ct.Source.Length;
+                                       escape1.End = end;
                                        s = ct.Replacement;
                                        idx = s.Length - 1;
                                        end = 0;

Modified: trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs
===================================================================
--- trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs     
2005-07-14 18:17:25 UTC (rev 47318)
+++ trunk/mcs/class/corlib/Mono.Globalization.Unicode/TestDriver.cs     
2005-07-14 18:21:07 UTC (rev 47319)
@@ -31,11 +31,10 @@
                void Run ()
                {
 //IsSuffix ("\u00E6", "ae", CompareOptions.None);
-//IsSuffix ("ae", "\u00E6", CompareOptions.None);
+IsSuffix ("ae", "\u00E6", CompareOptions.None);
 //LastIndexOf ("AE", "A", 1, 2, CompareOptions.None);
 //LastIndexOf ("\u00C6", "AE", CompareOptions.None);
-Compare ("\u30D0\u30FC\u30B9", "\uFF8A\uFF9E\uFF70\uFF7D", 
CompareOptions.IgnoreNonSpace);
-//return;
+return;
                        /*
                        DumpSortKey ("AE");
                        DumpSortKey ("\u00C6");

Modified: trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog  2005-07-14 
18:17:25 UTC (rev 47318)
+++ trunk/mcs/class/corlib/Test/System.Globalization/ChangeLog  2005-07-14 
18:21:07 UTC (rev 47319)
@@ -1,6 +1,11 @@
 2005-07-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * CompareInfoTest.cs : added tests for IndexOf() and LastIndexOf()
+         with ignorable source character. Added some non-working tests.
+
+2005-07-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * CompareInfoTest.cs : added tests for IndexOf() and LastIndexOf()
          that takes an expansion for target char.
 
 2005-07-14  Atsushi Enomoto  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs 
2005-07-14 18:17:25 UTC (rev 47318)
+++ trunk/mcs/class/corlib/Test/System.Globalization/CompareInfoTest.cs 
2005-07-14 18:21:07 UTC (rev 47319)
@@ -864,9 +864,16 @@
                AssertIsSuffix ("#7", true, "ae", "\u00E6", 
CompareOptions.None);
                AssertIsSuffix ("#8", false, "e", "\u00E6", 
CompareOptions.None);
                // U+3007 is completely ignored character.
-               AssertIsSuffix ("#14", true, "\uff21\uff21", "\uff21", 
CompareOptions.None);
-               AssertIsSuffix ("#15", true, "\uff21\uff21", "\u3007\uff21", 
CompareOptions.None);
-               AssertIsSuffix ("#16", true, "\uff21\uff21", "\uff21\u3007", 
CompareOptions.None);
+               AssertIsSuffix ("#9", true, "\uff21\uff21", "\uff21", 
CompareOptions.None);
+               AssertIsSuffix ("#10", true, "\uff21\uff21", "\u3007\uff21", 
CompareOptions.None);
+               AssertIsSuffix ("#11", true, "\uff21\uff21", "\uff21\u3007", 
CompareOptions.None);
+               // extender in target
+               // FIXME: not working
+//             AssertIsSuffix ("#12", false, "\u30D1\u30A2", "\u30D1\u30FC");
+//             AssertIsSuffix ("#13", true, "\u30D1\u30A2", "\u30D1\u30FC", 
CompareOptions.IgnoreNonSpace);
+               // extender in source
+//             AssertIsSuffix ("#14", false, "\u30D1\u30FC", "\u30D1\u30A2");
+//             AssertIsSuffix ("#15", true, "\u30D1\u30FC", "\u30D1\u30A2", 
CompareOptions.IgnoreNonSpace);
        }
 
        [Test]
@@ -901,6 +908,7 @@
                AssertIndexOf ("#13", 0, "\uff21\uff21", "\u3007\uff21", 
CompareOptions.None);
                AssertIndexOf ("#14", 0, "\uff21\uff21", "\uff21\u3007", 
CompareOptions.None);
                AssertIndexOf ("#15", 0, "\uff21\uff21", "\u3007", 
CompareOptions.None);
+               AssertIndexOf ("#15-2", 1, "\u3007\uff21", "\uff21", 
CompareOptions.None);
                // target is "empty" (in culture-sensitive context).
                AssertIndexOf ("#16", -1, String.Empty, "\u3007");
                AssertIndexOf ("#17", 0, "A", "\u3007");
@@ -956,6 +964,7 @@
                AssertLastIndexOf ("#15", 1, "\uff21\uff21", "\u3007\uff21", 
CompareOptions.None);
                AssertLastIndexOf ("#16", 1, "\uff21\uff21", "\uff21\u3007", 
CompareOptions.None);
                AssertLastIndexOf ("#17", 1, "\uff21\uff21", "\u3007", 
CompareOptions.None);
+               AssertLastIndexOf ("#18", 1, "\u3007\uff21", "\uff21", 
CompareOptions.None);
        }
 
        [Test]

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

Reply via email to