public MText Dup ()
{
- return (new MText (sb.ToString ()));
+ MText mt = new MText (sb.ToString ());
+
+ foreach (MPlist p in intervals)
+ mt.intervals.Add (p.Key, ((MInterval) p.Val).Copy (0, Length));
+ return mt;
}
public MText Ins (int pos, int c)
Console.WriteLine (")");
}
+ public void DumpPropNested ()
+ {
+ foreach (MPlist p in intervals)
+ ((MInterval) p.Val).DumpNested (true);
+ }
+
private class MInterval
{
// position: 0 1 2 3 4 5 6 7
MInterval copy, left_copy = null, right_copy = null;
update_from_to ();
+
if (start < From)
{
if (end <= From)
return Left.Copy (start, end);
left_copy = Left.Copy (start, From);
}
- else if (end > To)
+ if (end > To)
{
if (start >= To)
return Right.Copy (start, end);
copy = new MInterval (Key, null, end - start, Stack);
remove_properties (MTextProperty.Flag.Sensitive);
- copy.Left = left_copy;
- copy.Right = right_copy;
-
+ if (left_copy != null)
+ {
+ copy.Left = left_copy;
+ left_copy.Parent = copy;
+ }
+ if (right_copy != null)
+ {
+ copy.Right = right_copy;
+ right_copy.Parent = copy;
+ }
return copy;
}
if (! mergeable (prev))
return false;
+ M17N.DebugPrint ("merging "); DumpOne (false, false);
+ M17N.DebugPrint (" with prev "); prev.DumpOne (false, true);
int len = prev.Length - prev.LeftLength;
// PREV is Left, Left.Right, ..., or Left....Right.
if (prev != Left)
{
+ if (prev.Left != null)
+ prev.Left.Parent = prev.Parent;
prev.Parent.Right = prev.Left;
while (prev.Parent != Left)
{
}
Left.Length -= len;
if (Left.Length == Left.LeftLength)
- Left = Left.Left;
+ {
+ if (Left.Left != null)
+ Left.Left.Parent = this;
+ Left = Left.Left;
+ }
return true;
}
if (! mergeable (next))
return false;
- int len = next.Length - next.LeftLength;
+ M17N.DebugPrint ("merging "); DumpOne (false, false);
+ M17N.DebugPrint (" with next "); next.DumpOne (false, true);
+
+ int len = next.Length - next.RightLength;
// NEXT is Right, Right.Left, ..., or Right....Left.
if (next != Right)
{
+ if (next.Right != null)
+ next.Right.Parent = next.Parent;
next.Parent.Left = next.Right;
while (next.Parent != Right)
{
}
}
Right.Length -= len;
- if (Right.Length == Right.LeftLength)
- Right = Right.Left;
-
+ if (Right.Length == Right.RightLength)
+ {
+ if (Right.Right != null)
+ Right.Right.Parent = this;
+ Right = Right.Right;
+ }
return true;
}
Console.Write (")");
if (newline)
Console.WriteLine ();
+ if (Length <= 0)
+ throw new Exception ("Invalid interval length");
}
}
public void Dump () { Dump (false); }
-
public void Dump (bool force)
{
if (force || M17N.debug)
Right.Dump (force);
}
}
+
+ private int Depth {
+ get { return (Parent == null ? 0 : Parent.Depth + 1); }
+ }
+
+ public void DumpNested (bool force)
+ {
+ DumpNested ("", force);
+ }
+
+ public void DumpNested (string indent, bool force)
+ {
+ if (force || M17N.debug)
+ {
+ int indent_type = (Parent == null ? 1
+ : Parent.Left == this ? 0 : 2);
+
+ update_from_to ();
+ if (Left != null)
+ {
+ if (indent_type <= 1)
+ Left.DumpNested (indent + " ", force);
+ else
+ Left.DumpNested (indent + "| ", force);
+ }
+ if (indent_type == 0)
+ Console.Write (indent + ".-");
+ else if (indent_type == 2)
+ Console.Write (indent + "`-");
+ DumpOne (true, true);
+ if (Right != null)
+ {
+ if (indent_type >= 1)
+ Right.DumpNested (indent + " ", force);
+ else if (indent_type == 2)
+ Right.DumpNested (indent + "| ", force);
+ }
+ }
+ }
}
private class MTextEnum : IEnumerator