From: handa Date: Thu, 15 Jan 2009 10:07:06 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=8c8f06334e4d30e5c3c6e7e5877bfaf5a6936b42;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/M17N.cs b/M17N.cs index 3663570..4ded12d 100644 --- a/M17N.cs +++ b/M17N.cs @@ -3,10 +3,11 @@ using M17N.Core; public class Test { - public static void Main() + static void symbol_test () { MSymbol sym1, sym2; + Console.WriteLine ("### Symbol test ###"); sym1 = new MSymbol ("abc"); Console.WriteLine (sym1.ToString ()); sym2 = new MSymbol ("abc"); @@ -24,4 +25,28 @@ public class Test Console.WriteLine (pp.ToString ()); Console.WriteLine (p.get (MSymbol.t)); } + + static void mtext_test () + { + MText mt; + + Console.WriteLine ("### MText test ###"); + mt = new MText ("abc"); + Console.WriteLine (mt); + Console.WriteLine (mt + new MText ("def")); + Console.WriteLine (mt); + } + + static void mtext_property_test () + { + Console.WriteLine ("### MTextProperty test ###"); + } + + public static void Main() + { + symbol_test (); + mtext_test (); + mtext_property_test (); + } + } diff --git a/MText.cs b/MText.cs index dc31f78..261ffaa 100644 --- a/MText.cs +++ b/MText.cs @@ -53,7 +53,7 @@ namespace M17N.Core private int cache_pos; private int cache_idx; private MInterval root_interval; - private bool unmodifiable; + private bool read_only; private static UTF8Encoding utf8 = new UTF8Encoding (); @@ -100,13 +100,15 @@ namespace M17N.Core public static MText operator+ (MText mt1, MText mt2) { - MText mt = new MText (mt1.sb); + MText mt = new MText (mt1.sb.ToString); mt.sb.Append (mt2.sb); mt.nchars = mt1.nchars + mt2.nchars; return mt; } + public bool ReadOnly { get { return read_only; } } + public override string ToString () { return sb.ToString (); @@ -242,6 +244,13 @@ namespace M17N.Core return this; } + public void PushProp (int from, int to, MTextProperty prop) + { + if (root_interval == null) + root_interval = new MInterval (0, true, sb.Length, true); + root_interval.Push (from, to, prop); + } + private class MInterval { // Start and end positions of this interval and its children. @@ -324,7 +333,7 @@ namespace M17N.Core } } - public void Push (MTextProperty prop, int start, int end) + public void Push (int start, int end, MTextProperty prop) { start <<= 2; if (prop.FrontSticky) @@ -339,7 +348,7 @@ namespace M17N.Core if (start >= end) throw new Exception ("Invalid Text Property Range"); - push (prop, start, end); + push (start, end, prop); } private MInterval divide_right (int pos) @@ -414,7 +423,7 @@ namespace M17N.Core return interval; } - private void push (MTextProperty prop, int start, int end) + private void push (int start, int end, MTextProperty prop) { int this_start = Start; int this_end = End; @@ -422,29 +431,28 @@ namespace M17N.Core if (start < this_start) { if (end <= this_start) - Left.push (prop, start, end); - else { - Left.push (prop, start, this_start); - if (end < this_end) - { - divide_right (end); - stack.Push (prop); - } - else - { - stack.Push (prop); - if (this_end < end) - Right.Push (prop, this_end, end); - } + Left.push (start, end, prop); + return; } + Left.push (start, this_start, prop); + start = this_start; } - else if (start < this_end) + if (this_end < end) { - divide_right (start).Push (prop, start, end); + if (this_end < start) + { + Right.push (start, end, prop); + return; + } + Right.push (this_end, end, prop); + end = this_end; } - else - Right.Push (prop, start, end); + if (this_start < start) + divide_left (start); + if (end < this_end) + divide_right (end); + stack.Push (prop); } } }