3 using System.Collections;
4 using System.Collections.Generic;
11 public enum MTextFormat
13 MTEXT_FORMAT_US_ASCII,
15 MTEXT_FORMAT_UTF_16BE,
16 MTEXT_FORMAT_UTF_16LE,
17 MTEXT_FORMAT_UTF_32BE,
18 MTEXT_FORMAT_UTF_32LE,
22 public class MProperty
28 /// A text inserted before a character that has this property
29 /// inherits this property. If the text already has properties
30 /// of the same key, they are deleted. See the documentation of
31 /// Sensitive for exception.
33 /// A text inserted after a character that has this property
34 /// inherits this property. If the text already has properties
35 /// of the same key, they are deleted. See the documentation of
36 /// Sensitive for exception.
38 /// This property is deleted from a span of text if the span is
39 /// modified (i.e. a character is changed, a text is inserted,
40 /// some part is deleted). This propery is also deleted if a
41 /// property of the same key is added, which means that this
42 /// property is not stackable. If this property is also
43 /// FrontSticky (or RearSticky), text insertion just before (or
44 /// after) the span also deletes this property from the span of
52 public MSymbol Key { get { return key; } }
53 public object Val { get { return val; } }
55 public MProperty (MSymbol key, object val)
57 if (key.flags == null)
58 key.flags = MProperty.Flags.None;
63 public MProperty (string name, object val)
65 key = MSymbol.PropertyKey (name);
69 public override string ToString ()
71 return key.ToString () + ":" + val;
75 public class MText : IEnumerable, IEquatable<MText>, IComparable<MText>
78 public enum MTextFormat format;
80 private StringBuilder sb;
82 private int cache_pos;
83 private int cache_idx;
84 private MPlist intervals;
85 private MPlist default_property;
86 private bool read_only;
88 private static UTF8Encoding utf8 = new UTF8Encoding ();
90 private static int count_chars (String str)
92 int len = str.Length, n = 0;
94 for (int i = 0; i < len; i++, n++)
95 if (surrogate_high_p (str[i]))
100 private static int count_chars (StringBuilder str)
102 int len = str.Length, n = 0;
104 for (int i = 0; i < len; i++, n++)
105 if (surrogate_high_p (str[i]))
112 sb = new StringBuilder ();
113 intervals = new MPlist ();
116 public MText (byte[] str)
118 sb = new StringBuilder (utf8.GetString (str));
119 nchars = count_chars (sb);
120 intervals = new MPlist ();
123 public MText (String str)
125 sb = new StringBuilder (str);
126 nchars = count_chars (str);
127 intervals = new MPlist ();
130 public MText (StringBuilder str)
133 nchars = count_chars (str);
134 intervals = new MPlist ();
137 public static MText operator+ (object obj, MText mt)
140 return new MText ((string) obj) + mt;
141 throw new Exception ("Unknown object type: " + obj.GetType());
144 public static MText operator+ (MText mt1, MText mt2)
146 MText mt = new MText ();
148 mt.sb.Append (mt1.sb);
149 mt.sb.Append (mt2.sb);
150 mt.nchars = mt1.nchars + mt2.nchars;
154 public static MText operator+ (string str, MText mt)
156 MText mtnew = new MText (str);
158 mtnew.sb.Append (mt.sb);
159 mtnew.nchars += mt.nchars;
164 public bool ReadOnly { get { return read_only; } }
165 public int Length { get { return nchars; } }
169 // for IEnumerable interface
170 public IEnumerator GetEnumerator() { return new MTextEnum (this); }
172 // for IEquatable interface
173 public bool Equals (MText other) { return this.sb.Equals (other.sb); }
175 // for IComparable interface
176 public int CompareTo (MText other)
178 return this.sb.ToString ().CompareTo (other.sb.ToString ());
181 public override String ToString () { return "\"" + sb.ToString () + "\""; }
183 private static bool surrogate_high_p (char c)
185 return (c >= 0xD800 && c < 0xDC00);
188 private static bool surrogate_low_p (char c)
190 return (c >= 0xDC00 && c < 0xE000);
193 private static int inc_idx (StringBuilder sb, int i)
195 return (i + (surrogate_high_p (sb[i]) ? 2 : 1));
198 private static int dec_idx (StringBuilder sb, int i)
200 return (i - (surrogate_low_p (sb[i - 1]) ? 2 : 1));
203 private static int pos_to_idx (MText mt, int pos)
205 if (pos == mt.cache_pos)
211 if (pos < mt.cache_pos)
213 if (mt.cache_pos == mt.cache_idx)
215 if (pos < mt.cache_pos - pos)
222 p = mt.cache_pos; i = mt.cache_idx;
228 if (mt.nchars - mt.cache_pos == mt.sb.Length - mt.cache_idx)
229 return (mt.cache_idx + pos - mt.cache_pos);
230 if (pos - mt.cache_pos < mt.nchars - pos)
232 p = mt.cache_pos; i = mt.cache_idx;
237 p = mt.nchars; i = mt.sb.Length;
242 for (; p < pos; i = inc_idx (mt.sb, i), p++);
244 for (; p > pos; i = dec_idx (mt.sb, i), p--);
250 private void check_pos (int pos, bool tail_ok)
252 if (pos < 0 || (tail_ok ? pos > nchars : pos >= nchars))
253 throw new Exception ("Invalid MText position:" + pos);
256 private bool check_range (int from, int to, bool zero_ok)
258 if (from < 0 || (zero_ok ? from > to : from >= to)
260 throw new Exception ("Invalid MText range");
264 private void insert (int pos, MText mt2, int from, int to)
266 check_pos (pos, true);
270 Console.Write ("inserting {0} to {1} of ", from, to);
271 mt2.DumpPropNested ();
275 foreach (MPlist plist in intervals)
277 MInterval root = (MInterval) plist.Val;
278 MPlist p = mt2.intervals.Find (plist.Key);
279 MInterval i = p == null ? null : (MInterval) p.Val;
281 root.Insert (pos, i, from, to);
283 foreach (MPlist plist in mt2.intervals)
284 if (intervals.Find (plist.Key) == null)
289 root = ((MInterval) plist.Val).Copy (this, from, to);
292 root = new MInterval (plist.Key, this);
293 root.Insert (pos, (MInterval) plist.Val, from, to);
295 intervals.Push (plist.Key, root);
298 int pos_idx = pos_to_idx (this, pos);
299 int from_idx = pos_to_idx (mt2, from);
300 int to_idx = pos_to_idx (mt2, to);
302 sb.Insert (pos_idx, mt2.sb.ToString (from_idx, to_idx - from_idx));
306 private void insert (int pos, int c)
308 check_pos (pos, true);
310 int pos_idx = pos_to_idx (this, pos);
315 sb.Insert (pos_idx, ch);
319 char high = (char) (0xD800 + ((c - 0x10000) >> 10));
320 char low = (char) (0xDC00 + ((c - 0x10000) & 0x3FF));
321 sb.Insert (pos_idx, low);
322 sb.Insert (pos_idx, high);
325 foreach (MPlist plist in intervals)
326 ((MInterval) plist.Val).Insert (pos, null, 0, 1);
329 public int this[int i]
332 i = pos_to_idx (this, i);
335 if (surrogate_high_p (sb[i]))
337 sb[i] = (char) value;
341 char high = (char) (0xD800 + ((value - 0x10000) >> 10));
342 char low = (char) (0xDC00 + ((value - 0x10000) & 0x3FF));
344 if (! surrogate_high_p (sb[i]))
351 i = pos_to_idx (this, i);
352 return (surrogate_high_p (sb[i])
353 ? ((sb[i] - 0xD800) << 10) + (sb[i + 1] - 0xDC00) + 0x10000
360 MText mt = new MText (sb.ToString ());
362 foreach (MPlist p in intervals)
363 mt.intervals.Add (p.Key, ((MInterval) p.Val).Copy (mt, 0, Length));
367 public MText Dup (int from, int to)
369 if (check_range (from, to, true))
371 int from_idx = pos_to_idx (this, from);
372 int len = pos_to_idx (this, to) - from_idx;
373 MText mt = new MText (sb.ToString ().Substring (from_idx, len));
375 foreach (MPlist p in intervals)
376 mt.intervals.Add (p.Key, ((MInterval) p.Val).Copy (mt, from, to));
380 public MText Ins (int pos, int c)
386 public MText Ins (int pos, MText mt)
388 insert (pos, mt, 0, mt.nchars);
392 public MText Ins (int pos, MText mt, int from, int to)
394 insert (pos, mt, from, to);
398 public MText Cat (int c)
404 public MText Del (int from, int to)
406 if (check_range (from, to, true))
409 sb.Remove (from, pos_to_idx (this, to) - pos_to_idx (this, from));
413 foreach (MPlist plist in intervals)
415 MInterval root = (MInterval) plist.Val;
416 root.Delete (from, to);
417 if (from > 0 && from < nchars)
418 ((MInterval) plist.Val).MergeAfterChange (from, from);
427 public object GetProp (int pos, MSymbol key)
429 check_pos (pos, false);
431 MInterval i = (MInterval) intervals.Get (key);
435 MProperty prop = i.Get (pos);
436 return (prop != null ? prop.Val : null);
439 public object GetProp (int pos, MSymbol key, out MProperty prop)
441 check_pos (pos, false);
443 MInterval i = (MInterval) intervals.Get (key);
445 return (prop = null);
447 return (prop != null ? prop.Val : null);
450 public object GetProp (int pos, MSymbol key, out MProperty[] array)
452 check_pos (pos, false);
454 MInterval i = (MInterval) intervals.Get (key);
456 return (array = null);
457 MProperty prop = i.Get (pos, out array);
458 return (prop != null ? prop.Val : null);
461 public void PushProp (int from, int to, MSymbol key, object val)
463 if (! check_range (from, to, true))
464 PushProp (from, to, new MProperty (key, val));
467 public void PushProp (int from, int to, MProperty prop)
471 if (default_property == null)
472 default_property = new MPlist ();
473 default_property.Push (prop.key, prop.val);
477 if (check_range (from, to, true))
480 MPlist p = intervals.Find (prop.key);
485 root = new MInterval (prop.key, this);
486 intervals.Push (prop.key, root);
489 root = (MInterval) p.Val;
491 if (root.isSensitive)
492 root.PopSensitive (from, to);
493 root.Push (from, to, prop);
494 root.MergeAfterChange (from, to);
499 public void PopProp (int from, int to, MSymbol key)
503 if (default_property == null)
505 MPlist p = default_property.Find (key);
512 if (check_range (from, to, true))
515 MPlist p = intervals.Find (key);
519 MInterval root = (MInterval) p.Val;
520 if (root.isSensitive)
521 root.PopSensitive (from, to);
524 root.MergeAfterChange (from, to);
530 public void DumpProp ()
533 foreach (MPlist p in intervals)
534 ((MInterval) p.Val).Dump (true);
535 Console.WriteLine (")");
538 public void DumpPropNested ()
540 Console.WriteLine ("total length = {0}", Length);
541 foreach (MPlist p in intervals)
542 ((MInterval) p.Val).DumpNested (true);
545 private class MInterval
547 // position: 0 1 2 3 4 5 6 7
548 // | A | B | C | D | E F | G |
549 // interval |---|---|---|<->|-------|---|
550 // |---|<->|---| |<----->|---|
554 // [3 (1 2)] [3 (4 6)]
555 // [1 (0 1)] [2 (2 3)] [1 (6 7)]
557 private static int count = 0;
560 private int From, To;
562 private MPlist Stack;
563 private MInterval Left, Right, Parent;
566 public MInterval (MSymbol key, MText mt, int length)
569 throw new Exception ("Invalid interval length");
573 Stack = new MPlist ();
577 public MInterval (MSymbol key, MText mt)
581 Length = mt.sb.Length;
584 Stack = new MPlist ();
588 /// POS must be smaller than Length;
589 public MProperty Get (int pos)
591 MInterval i = find_head (pos);
593 return (i.Stack.IsEmpty ? null : (MProperty) i.Stack.Val);
596 /// POS must be smaller than Length;
597 public MProperty Get (int pos, out MProperty[] array)
599 MInterval i = find_head (pos);
608 array = new MProperty[i.Stack.Count];
612 for (idx = 0, p = i.Stack; ! p.IsEmpty; idx++, p = p.Next)
613 array[idx] = (MProperty) p.Val;
617 private MInterval (MSymbol key, MText mt, int length, MPlist stack)
624 Stack = stack == null ? new MPlist () : stack.Clone ();
628 private bool isRearSticky
630 get { return ((Key.flags & MProperty.Flags.RearSticky)
631 != MProperty.Flags.None); }
634 private bool isFrontSticky
636 get { return ((Key.flags & MProperty.Flags.FrontSticky)
637 != MProperty.Flags.None); }
640 public bool isSensitive
642 get { return ((Key.flags & MProperty.Flags.Sensitive)
643 != MProperty.Flags.None); }
646 private void update_from_to ()
651 To = Length - RightLength;
653 else if (Parent.Left == this)
655 From = Parent.From - Length + LeftLength;
656 To = Parent.From - RightLength;
660 From = Parent.To + LeftLength;
661 To = Parent.To + Length - RightLength;
665 private int LeftLength
667 get { return (Left == null ? 0 : Left.Length); }
670 private int RightLength
672 get { return (Right == null ? 0 : Right.Length); }
675 private MInterval LeftMost
681 return Left.LeftMost;
685 private MInterval RightMost
691 return Right.RightMost;
695 private MInterval Prev {
701 for (i = Left; i.Right != null; i = i.Right)
707 MInterval child = this;
708 for (i = Parent; i != null && i.Left == child;
709 child = i, i = i.Parent);
715 private MInterval Next {
721 for (i = Right; i.Left != null; i = i.Left)
727 MInterval child = this;
728 for (i = Parent; i != null && i.Right == child;
729 child = i, i = i.Parent);
735 private MInterval find_head (int pos)
739 return Left.find_head (pos);
741 return Right.find_head (pos);
745 private MInterval find_tail (int pos)
749 return Left.find_tail (pos);
751 return Right.find_tail (pos);
755 private bool mergeable (MInterval i)
759 for (p1 = Stack, p2 = i.Stack; ! p1.IsEmpty && ! p2.IsEmpty;
760 p1 = p1.Next, p2 = p2.Next)
761 if (p1.Val != p2.Val)
763 return (p1.IsEmpty && p2.IsEmpty);
766 // p-. or .-p p-. or .-p
767 // .-this-. .-right-.
768 // left .-right-. -> .-this-. c2
770 private MInterval promote_right ()
772 MInterval c1 = Right.Left;
776 mtext.intervals.Put (Key, Right);
777 else if (Parent.Left == this)
780 Parent.Right = Right;
783 Right.Parent = Parent;
785 Right.Length += LeftLength + (To - From);
790 Length = LeftLength + (To - From) + RightLength;
792 // Update C1 if necessary.
796 Parent.update_from_to ();
800 // p-. or .-p p-. or .-p
802 // .-left-. .-right-. -> c1 .-this-.
804 private MInterval promote_left ()
806 MInterval c2 = Left.Right;
810 mtext.intervals.Put (Key, Left);
811 else if (Parent.Left == this)
817 Left.Parent = Parent;
819 Left.Length += (To - From) + RightLength;
824 Length = LeftLength + (To - From) + RightLength;
826 // Update C2 if necessary.
830 Parent.update_from_to ();
834 public MInterval Balance ()
842 // .-left-. .-right-.
844 int diff = i.LeftLength - i.RightLength;
849 new_diff = (i.Length - i.LeftLength
850 + i.Left.RightLength - i.Left.LeftLength);
851 if (Math.Abs (new_diff) >= diff)
853 M17n.DebugPrint ("balancing #{0} by promoting left...", i.ID);
854 i = i.promote_left ();
855 M17n.DebugPrint ("done\n");
860 new_diff = (i.Length - i.RightLength
861 + i.Right.LeftLength - i.Right.RightLength);
862 if (Math.Abs (new_diff) >= diff)
864 M17n.DebugPrint ("balancing #{0} by promoting right\n", i.ID);
865 i = i.promote_right ();
874 public MInterval Copy (MText mt, int start, int end)
876 MInterval copy, left_copy = null, right_copy = null;
883 return Left.Copy (mt, start, end);
884 left_copy = Left.Copy (mt, start, From);
889 return Right.Copy (mt, start, end);
890 right_copy = Right.Copy (mt, To, end);
893 copy = new MInterval (Key, null, end - start, Stack);
895 if (isSensitive && (From < start || end < To))
897 if (left_copy != null)
899 copy.Left = left_copy;
900 left_copy.Parent = copy;
902 if (right_copy != null)
904 copy.Right = right_copy;
905 right_copy.Parent = copy;
913 private MInterval divide_right (int pos)
915 MInterval interval = new MInterval (Key, mtext, To - pos, Stack);
917 M17n.DebugPrint ("divide-right({0}) at ", pos); DumpOne (false, true);
921 interval.Right = Right;
922 Right.Parent = interval;
923 interval.Length += Right.Length;
925 interval.Parent = this;
933 private MInterval divide_left (int pos)
935 MInterval interval = new MInterval (Key, mtext, pos - From, Stack);
937 M17n.DebugPrint ("divide-left({0}) at ", pos); DumpOne (false, true);
941 interval.Left = Left;
942 Left.Parent = interval;
943 interval.Length += Left.Length;
945 interval.Parent = this;
950 private void set_mtext (MText mt)
956 Right.set_mtext (mt);
959 private void enlarge (int len)
963 for (MInterval prev = this, i = this.Parent; i != null;
964 prev = i, i = i.Parent)
975 private int graft_forward (MInterval interval, int start, int end)
979 if (! Stack.IsEmpty && isRearSticky)
981 else if (interval == null)
982 len = Stack.IsEmpty ? end - start : 0;
985 MInterval i = interval.find_head (start);
988 while (i != null && mergeable (i))
990 M17n.DebugPrint (" grafting "); i.DumpOne (false, false);
991 len += i.To - i.From;
993 len -= start - i.From;
1003 M17n.DebugPrint (" grafted {0} in ", len); DumpOne (false, true);
1009 private int graft_backward (MInterval interval, int start, int end)
1013 if (! Stack.IsEmpty && isFrontSticky)
1015 else if (interval == null)
1016 len = Stack.IsEmpty ? end - start : 0;
1019 MInterval i = interval.find_tail (end);
1022 while (i != null && mergeable (i))
1024 M17n.DebugPrint (" grafting "); i.DumpOne (false, false);
1025 len += i.To - i.From;
1028 if (i.From <= start)
1030 len -= start - i.From;
1037 M17n.DebugPrint (" grafted {0} in ", len); DumpOne (false, true);
1043 public void Insert (int pos, MInterval interval, int start, int end)
1047 M17n.DebugPrint ("insert({0} to {1}) at {2} in ", start, end, pos);
1048 DumpOne (false, false);
1051 Left.Insert (pos, interval, start, end);
1052 else if (pos == From)
1056 MInterval prev = Prev;
1058 if (prev.isSensitive && prev.isRearSticky)
1059 prev.Stack.Clear ();
1060 start += prev.graft_forward (interval, start, end);
1062 if (isSensitive && isFrontSticky)
1066 end -= graft_backward (interval, start, end);
1069 if (interval != null)
1070 interval = interval.Copy (mtext, start, end);
1072 interval = new MInterval (Key, mtext, end - start, null);
1077 // .-this-. ==> .-this-.
1089 interval.Parent = i;
1090 for (; i != null; i = i.Parent)
1091 i.Length += interval.Length;
1100 int len = graft_forward (interval, start, end);
1105 end -= graft_backward (interval, start, end);
1108 if (interval != null)
1109 interval = interval.Copy (mtext, start, end);
1111 interval = new MInterval (Key, mtext, end - start, null);
1114 Right.Left = interval;
1115 interval.Parent = Right;
1116 for (MInterval i = Right; i != null; i = i.Parent)
1117 i.Length += interval.Length;
1125 MInterval next = Next;
1127 if (next.isSensitive && next.isFrontSticky)
1128 next.Stack.Clear ();
1129 end -= next.graft_backward (interval, start, end);
1131 if (isSensitive && isRearSticky)
1135 start += graft_forward (interval, start, end);
1138 if (interval != null)
1139 interval = interval.Copy (mtext, start, end);
1141 interval = new MInterval (Key, mtext, end - start, null);
1146 // .-this-. ==> .-this-.
1159 interval.Parent = i;
1160 for (; i != null; i = i.Parent)
1161 i.Length += interval.Length;
1166 Next.Insert (pos, interval, start, end);
1167 M17n.DebugPrint (" done\n");
1170 private void vacate_node (MInterval interval)
1172 vacate_node (interval, null);
1175 private void vacate_node (MInterval interval, MInterval stop)
1177 if (interval != null)
1178 M17n.DebugPrint ("vacate #{0} to #{1}\n", ID, interval.ID);
1180 M17n.DebugPrint ("vacate #{0} to null\n", ID);
1181 if (interval != null)
1182 interval.Parent = Parent;
1186 mtext.intervals.Put (Key, interval);
1190 if (this == Parent.Right)
1191 Parent.Right = interval;
1193 Parent.Left = interval;
1196 if (interval != null)
1197 diff -= interval.Length;
1198 for (MInterval i = Parent; i != stop; i = i.Parent)
1203 public void Delete (int start, int end)
1206 M17n.DebugPrint ("delete({0} {1}) from ", start, end); DumpOne (false, true);
1211 Left.Delete (start, end);
1214 Left.Delete (start, From);
1216 end -= From - start;
1223 Right.Delete (start, end);
1226 Right.Delete (To, end);
1229 if (start == From && end == To)
1241 for (i = Right; i.Left != null; i = i.Left)
1242 i.Length += Left.Length;
1243 i.Length += Left.Length;
1247 vacate_node (Right);
1252 int len = end - start;
1254 for (MInterval i = this; i != null; i = i.Parent)
1259 public void Push (int start, int end, MProperty prop)
1262 M17n.DebugPrint ("push({0} {1}) at ", start, end); DumpOne (false, true);
1267 Left.Push (start, end, prop);
1270 Left.Push (start, From, prop);
1277 Right.Push (start, end, prop);
1280 Right.Push (To, end, prop);
1285 divide_left (start);
1288 Stack.Push (prop.key, prop);
1291 /// Combine intervals between HEAD and TAIL (both inclusive) to
1292 /// the common parent of HEAD and TAIL while assuming that the
1293 /// intervals are mergeable.
1294 private static void combine (MInterval head, MInterval tail)
1296 M17n.DebugPrint ("merging "); head.DumpOne (true, false);
1297 M17n.DebugPrint (" through "); tail.DumpOne (true, false);
1299 int from = head.From;
1301 // The nearest common parent of HEAD and TAIL.
1304 for (root = head; root.To + root.RightLength < to;
1305 root = root.Parent);
1307 M17n.DebugPrint (" common root is "); root.DumpOne (false, true);
1309 if (from < root.From)
1311 MInterval prev = root.Prev;
1315 M17n.DebugPrint ("merging "); prev.DumpOne (false, true);
1316 prev.vacate_node (prev.Left, root);
1319 if (prev.Left != null)
1320 prev = prev.Left.RightMost;
1327 MInterval next = root.Next;
1331 M17n.DebugPrint ("merging "); next.DumpOne (false, true);
1332 next.vacate_node (next.Right, root);
1335 if (next.Right != null)
1336 next = next.Right.LeftMost;
1343 public void MergeAfterChange (int start, int end)
1347 MInterval head = find_head (start), tail = head, i;
1349 if (start == head.From && start > 0)
1352 if (head.mergeable (i))
1355 while (tail.To < end)
1358 if (! tail.mergeable (i))
1361 combine (head, tail);
1369 if (i == null || ! tail.mergeable (i))
1374 combine (head, tail);
1377 public void Pop (int start, int end)
1380 M17n.DebugPrint ("pop({0} {1}) at ", start, end); DumpOne (false, true);
1385 Left.Pop (start, end);
1388 Left.Pop (start, From);
1395 Right.Pop (start, end);
1398 Right.Pop (To, end);
1402 if (! Stack.IsEmpty)
1405 divide_left (start);
1412 public void PopSensitive (int start, int end)
1415 MInterval head = find_head (start);
1416 MInterval tail = find_tail (end);
1417 while (! head.Stack.IsEmpty && head.From > 0)
1419 MInterval prev = head.Prev;
1421 if (prev.Stack.IsEmpty || head.Stack.Val != prev.Stack.Val)
1425 while (! tail.Stack.IsEmpty && tail.To < mtext.Length)
1427 MInterval next = tail.Next;
1429 if (next.Stack.IsEmpty || tail.Stack.Val != next.Stack.Val)
1433 Pop (head.From, tail.To);
1436 private void DumpOne (bool with_prop, bool newline)
1438 DumpOne (with_prop, newline, false);
1441 private void DumpOne (bool with_prop, bool newline, bool force)
1443 if (force || M17n.debug)
1445 Console.Write ("#{0}({1} {2} {3}", ID, Length, From, To);
1447 foreach (MPlist p in Stack)
1448 Console.Write (" " + p.Val);
1449 Console.Write (")");
1451 Console.WriteLine ();
1453 throw new Exception ("Invalid interval length");
1457 public void Dump () { Dump (false); }
1459 public void Dump (bool force)
1461 if (force || M17n.debug)
1468 Console.Write (" ");
1469 DumpOne (true, false, force);
1476 get { return (Parent == null ? 0 : Parent.Depth + 1); }
1479 public void DumpNested (bool force)
1481 DumpNested (Key.ToString () + ":", force);
1484 public void DumpNested (string indent, bool force)
1486 if (force || M17n.debug)
1488 int indent_type = (Parent == null ? 1
1489 : Parent.Left == this ? 0 : 2);
1494 if (indent_type <= 1)
1495 Left.DumpNested (indent + " ", force);
1497 Left.DumpNested (indent + "| ", force);
1499 Console.Write (indent);
1500 if (indent_type == 0)
1501 Console.Write (".-");
1502 else if (indent_type == 2)
1503 Console.Write ("`-");
1504 DumpOne (true, true, true);
1507 if (indent_type >= 1)
1508 Right.DumpNested (indent + " ", force);
1510 Right.DumpNested (indent + "| ", force);
1516 private class MTextEnum : IEnumerator
1519 private int pos = -1;
1521 public MTextEnum (MText mt)
1526 public bool MoveNext ()
1529 return (pos < mt.nchars);
1532 public void Reset ()
1537 public object Current
1540 //if (pos < 0 || pos >= mt.nchars)
1541 //throw new InvalidOperationException ();