}
}
+ private void insert (int pos, int c)
+ {
+ check_pos (pos, true);
+
+ int pos_idx = pos_to_idx (this, pos);
+
+ if (c < 0x10000)
+ {
+ char ch = (char) c;
+ sb.Insert (pos_idx, ch);
+ }
+ else
+ {
+ char high = (char) (0xD800 + ((c - 0x10000) >> 10));
+ char low = (char) (0xDC00 + ((c - 0x10000) & 0x3FF));
+ sb.Insert (pos_idx, low);
+ sb.Insert (pos_idx, high);
+ }
+ nchars++;
+ foreach (MPlist plist in intervals)
+ ((MInterval) plist.Val).Insert (pos,
+ new MInterval (plist.Key, this, 1));
+ }
+
public int this[int i]
{
set {
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)
+ {
+ insert (pos, c);
+ return this;
}
public MText Ins (int pos, MText mt)
return this;
}
+ public MText Cat (int c)
+ {
+ insert (nchars, c);
+ return this;
+ }
+
public MText Del (int from, int to)
{
if (check_range (from, to, true))
{
check_pos (pos, false);
- MInterval i = (MInterval) intervals.Find (key).Val;
-
+ MInterval i = (MInterval) intervals.Get (key);
if (i == null)
return null;
{
check_pos (pos, false);
- MInterval i = (MInterval) intervals.Find (key).Val;
-
+ MInterval i = (MInterval) intervals.Get (key);
if (i == null)
return (prop = null);
prop = i.Get (pos);
{
check_pos (pos, false);
- MInterval i = (MInterval) intervals.Find (key).Val;
-
+ MInterval i = (MInterval) intervals.Get (key);
if (i == null)
return (array = null);
MTextProperty prop = i.Get (pos, out array);
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