throw new Exception ("Invalid MText position:" + pos);
}
- private void check_range (int from, int to, bool zero_ok)
+ private bool check_range (int from, int to, bool zero_ok)
{
if (from < 0 || (zero_ok ? from > to : from >= to)
|| to > nchars)
throw new Exception ("Invalid MText range");
+ return (from == to);
}
private void insert (int pos, MText mt2, int from, int to)
MPlist p = mt2.intervals.Find (plist.Key);
MInterval interval;
- if (p.IsEmpty)
+ if (p == null)
interval = new MInterval (plist.Key, to - from);
else
interval = ((MInterval) p.Val).copy (from, to);
public MText Del (int from, int to)
{
- check_range (from, to, true);
+ if (check_range (from, to, true))
+ return this;
sb.Remove (from, pos_to_idx (this, to) - pos_to_idx (this, from));
nchars -= to - from;
public void PushProp (int from, int to, MSymbol key, object val)
{
- check_range (from, to, false);
-
- PushProp (from, to, new MTextProperty (key, val));
+ if (! check_range (from, to, true))
+ PushProp (from, to, new MTextProperty (key, val));
}
public void PushProp (int from, int to, MTextProperty prop)
}
else
{
- MInterval root = (MInterval) intervals.Find (prop.key).Val;
+ if (check_range (from, to, true))
+ return;
- if (root == null)
+ MPlist p = intervals.Find (prop.key);
+ MInterval root;
+
+ if (p == null)
{
root = new MInterval (prop.key, this);
intervals.Push (prop.key, root);
}
+ else
+ root = (MInterval) p.Val;
+
root.Push (from, to, prop);
}
}
+ public void PopProp (int from, int to, MSymbol key)
+ {
+ if (from < 0)
+ {
+ if (default_property == null)
+ return;
+ MPlist p = default_property.Find (key);
+
+ if (p != null)
+ p.Pop ();
+ }
+ else
+ {
+ if (check_range (from, to, true))
+ return;
+
+ MPlist p = intervals.Find (key);
+
+ if (p != null)
+ ((MInterval) p.Val).Pop (from, to);
+ }
+ }
+
public void DumpProp ()
{
Console.Write ("(");
if ((prop.flags & MTextProperty.Flag.RearSticky)
== MTextProperty.Flag.RearSticky)
- i.stack.Push (prop.key, prop);
+ i.stack.Add (prop.key, prop);
}
}
}
if ((prop.flags & MTextProperty.Flag.FrontSticky)
== MTextProperty.Flag.FrontSticky)
- i.stack.Push (prop.key, prop);
+ i.stack.Add (prop.key, prop);
}
}
}
stack.Push (prop.key, prop);
}
+ public void Pop (int start, int end)
+ {
+ update_from_to ();
+ Console.Write ("pop({0} {1}) at ", start, end); DumpOne (false, true);
+ if (start < from)
+ {
+ if (end <= from)
+ {
+ left.Pop (start, end);
+ return;
+ }
+ left.Pop (start, from);
+ start = from;
+ }
+ if (end > to)
+ {
+ if (start >= to)
+ {
+ right.Pop (start, end);
+ return;
+ }
+ right.Pop (to, end);
+ end = to;
+ }
+
+ if (! stack.IsEmpty)
+ {
+ if (start > from)
+ divide_left (start);
+ if (end < to)
+ divide_right (end);
+ stack.Pop ();
+ }
+ }
+
private void DumpOne (bool with_prop, bool newline)
{
Console.Write ("#{0}({1} {2} {3}", id, total_length, from, to);