*** empty log message ***
[m17n/m17n-lib-cs.git] / MText.cs
index 39f9359..05e6fcf 100644 (file)
--- a/MText.cs
+++ b/MText.cs
@@ -152,6 +152,13 @@ namespace M17N.Core
        intervals = new MPlist ();
       }
 
+    public MText (byte[] str, int offset, int length)
+      {
+       sb = new StringBuilder (utf8.GetString (str, offset, length));
+       nchars = count_chars (sb);
+       intervals = new MPlist ();
+      }
+
     public MText (String str)
       {
        sb = new StringBuilder (str);
@@ -969,21 +976,25 @@ namespace M17N.Core
        MInterval head = find_head (start);
        MInterval tail = find_tail (end);
 
+       M17n.DebugPrint ("Copying: {0}", copy);
+
        if (! head.Stack.IsEmpty
            && (isSensitive && head.From < start
-               || isFrontSensitive && ! first))
+               || (isFrontSensitive && ! first)))
          {
+           M17n.DebugPrint (" clear head");
            head = copy.find_head (0);
            head.Stack.Clear ();
          }
        if (! tail.Stack.IsEmpty
-           && (isSensitive && end < head.To
-               || isRearSensitive && ! last))
+           && (isSensitive && end < tail.To
+               || (isRearSensitive && ! last)))
          {
+           M17n.DebugPrint (" clear tail");
            tail = copy.find_tail (copy.Length);
            tail.Stack.Clear ();
          }
-       M17n.DebugPrint ("Copied: {0}\n", copy);
+       M17n.DebugPrint ("\n");
        return copy;
       }
 
@@ -1315,7 +1326,7 @@ namespace M17N.Core
              interval = interval.Copy (mtext, start, end,
                                        front_grafted,
                                        (rear_grafted
-                                        || (next == null && end < interval.mtext.Length)));
+                                        || (next == null && end == interval.mtext.Length)));
            else
              interval = new MInterval (Key, mtext, end - start, null);