From 7dc73cfdf3e4a0359fcd41b1f1ae541ac01797e4 Mon Sep 17 00:00:00 2001 From: handa Date: Fri, 3 Apr 2009 12:15:30 +0000 Subject: [PATCH] *** empty log message *** --- MPlist.cs | 13 +++++++--- MText.cs | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/MPlist.cs b/MPlist.cs index 0b077a4..ca6022a 100644 --- a/MPlist.cs +++ b/MPlist.cs @@ -56,7 +56,7 @@ namespace M17N.Core return str + ")"; } - public MPlist Find (MSymbol key) + private MPlist find (MSymbol key) { MPlist p; @@ -66,9 +66,16 @@ namespace M17N.Core return p; } + public MPlist Find (MSymbol key) + { + MPlist p = find (key); + + return (p.IsEmpty ? null : p); + } + public object Get (MSymbol key) { - return Find (key).Val; + return find (key).Val; } public MPlist Set (MSymbol key, object val) @@ -82,7 +89,7 @@ namespace M17N.Core public MPlist Put (MSymbol key, object val) { - return Find (key).Set (key, val); + return find (key).Set (key, val); } public MPlist Push (MSymbol key, object val) diff --git a/MText.cs b/MText.cs index cfa688b..cbf5c8a 100644 --- a/MText.cs +++ b/MText.cs @@ -239,11 +239,12 @@ namespace M17N.Core 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) @@ -265,7 +266,7 @@ namespace M17N.Core 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); @@ -321,7 +322,8 @@ namespace M17N.Core 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; @@ -373,9 +375,8 @@ namespace M17N.Core 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) @@ -388,17 +389,47 @@ namespace M17N.Core } 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 ("("); @@ -744,7 +775,7 @@ namespace M17N.Core if ((prop.flags & MTextProperty.Flag.RearSticky) == MTextProperty.Flag.RearSticky) - i.stack.Push (prop.key, prop); + i.stack.Add (prop.key, prop); } } } @@ -761,7 +792,7 @@ namespace M17N.Core if ((prop.flags & MTextProperty.Flag.FrontSticky) == MTextProperty.Flag.FrontSticky) - i.stack.Push (prop.key, prop); + i.stack.Add (prop.key, prop); } } } @@ -974,6 +1005,41 @@ namespace M17N.Core 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); -- 1.7.10.4