From 8229459f2ea89e4941a348a69998428f88d9ef4a Mon Sep 17 00:00:00 2001 From: handa Date: Tue, 31 Mar 2009 07:57:09 +0000 Subject: [PATCH] *** empty log message *** --- M17N.cs | 10 +++--- MPlist.cs | 36 +++++++++++---------- MSymbol.cs | 21 ++++++++----- MText.cs | 97 +++++++++++++++++++++++++++++++++++---------------------- Makefile | 17 +++++----- mtext.cs | 22 +++++++++++++ plist.cs | 22 +++++++++++++ symbol.cs | 25 +++++++++++++++ test-mtext.cs | 22 ------------- test-plist.cs | 20 ------------ test-sym.cs | 25 --------------- textprop.cs | 19 +++++++++++ 12 files changed, 195 insertions(+), 141 deletions(-) create mode 100644 mtext.cs create mode 100644 plist.cs create mode 100644 symbol.cs delete mode 100644 test-mtext.cs delete mode 100644 test-plist.cs delete mode 100644 test-sym.cs create mode 100644 textprop.cs diff --git a/M17N.cs b/M17N.cs index 65eabfb..31eb4fe 100644 --- a/M17N.cs +++ b/M17N.cs @@ -13,17 +13,17 @@ public class Test sym2 = new MSymbol ("abc"); Console.WriteLine (sym2.ToString ()); Console.WriteLine (sym1 == sym2 ? "OK" : "NO"); - sym1.put (MSymbol.nil, MSymbol.t); + sym1.Put (MSymbol.nil, MSymbol.t); MPlist p = new MPlist (); - p.put (MSymbol.t, sym1); - p.push (MSymbol.t, sym2); + p.Put (MSymbol.t, sym1); + p.Push (MSymbol.t, sym2); MPlist pp = new MPlist (); - pp.put (MSymbol.t, p); + pp.Put (MSymbol.t, p); Console.WriteLine (pp.ToString ()); - Console.WriteLine (p.get (MSymbol.t)); + Console.WriteLine (p.Get (MSymbol.t)); } static void mtext_test () diff --git a/MPlist.cs b/MPlist.cs index 23ef0a1..0b077a4 100644 --- a/MPlist.cs +++ b/MPlist.cs @@ -41,7 +41,7 @@ namespace M17N.Core MPlist plist = new MPlist (), pl = plist; for (MPlist p = this; p.next != null; p = p.next) - pl = pl.add (p.Key, p.Val); + pl = pl.Add (p.Key, p.Val); return plist; } @@ -56,7 +56,7 @@ namespace M17N.Core return str + ")"; } - public MPlist find (MSymbol key) + public MPlist Find (MSymbol key) { MPlist p; @@ -66,22 +66,26 @@ namespace M17N.Core return p; } - public object get (MSymbol key) + public object Get (MSymbol key) { - return find (key).Val; + return Find (key).Val; } - public MPlist put (MSymbol key, object val) + public MPlist Set (MSymbol key, object val) { - MPlist p = find (key); + if (IsEmpty) + Push (key, val); + else + Val = val; + return this; + } - if (p.IsEmpty) - return p.push (key, val); - p.Val = val; - return p; + public MPlist Put (MSymbol key, object val) + { + return Find (key).Set (key, val); } - public MPlist push (MSymbol key, object val) + public MPlist Push (MSymbol key, object val) { MPlist p = new MPlist (Key, Val); @@ -92,7 +96,7 @@ namespace M17N.Core return this; } - public object pop () + public object Pop () { if (IsEmpty) return null; @@ -105,12 +109,12 @@ namespace M17N.Core return val; } - public MPlist add (MSymbol key, object val) + public MPlist Add (MSymbol key, object val) { MPlist p; for (p = this; ! p.IsEmpty; p = p.next); - return p.push (key, val); + return p.Push (key, val); } // Implement IEnumerable interface. @@ -149,11 +153,9 @@ namespace M17N.Core { if (current == null) current = plist; - else if (current.IsEmpty) - return false; else current = current.next; - return true; + return (! current.IsEmpty); } } } diff --git a/MSymbol.cs b/MSymbol.cs index 1fdd4ac..5bfc64a 100644 --- a/MSymbol.cs +++ b/MSymbol.cs @@ -11,7 +11,7 @@ namespace M17N.Core private class MSymbolData { public string name; - public Object value; + public object value; public MPlist plist; public MSymbolData (string name) @@ -49,7 +49,7 @@ namespace M17N.Core return str; } - public override bool Equals (Object sym) + public override bool Equals (object sym) { return (this.data == ((MSymbol) sym).data); } @@ -61,24 +61,29 @@ namespace M17N.Core public static bool operator== (MSymbol sym1, MSymbol sym2) { - return ((object) sym1.data == (object) sym2.data); + return (sym1.data == sym2.data); } public static bool operator!= (MSymbol sym1, MSymbol sym2) { - return ((object) sym1.data != (object) sym2.data); + return (sym1.data != sym2.data); } - public object get (MSymbol key) + public MPlist Find (MSymbol key) { - return (data.plist == null ? null : data.plist.get (key)); + return (data.plist == null ? null : data.plist.Find (key)); } - public object put (MSymbol key, object val) + public object Get (MSymbol key) + { + return (data.plist == null ? null : data.plist.Get (key)); + } + + public object Put (MSymbol key, object val) { if (data.plist == null) data.plist = new MPlist (); - return data.plist.put (key, val); + return data.plist.Put (key, val); } } } diff --git a/MText.cs b/MText.cs index a86bc29..ad343f1 100644 --- a/MText.cs +++ b/MText.cs @@ -238,11 +238,11 @@ namespace M17N.Core nchars += to - from; foreach (MPlist plist in mt2.intervals) - if (intervals.find (plist.Key) == null) - intervals.push (plist.Key, new MInterval (plist.Key, this)); + if (intervals.Find (plist.Key) == null) + intervals.Push (plist.Key, new MInterval (plist.Key, this)); foreach (MPlist plist in intervals) { - MPlist p = mt2.intervals.find (plist.Key); + MPlist p = mt2.intervals.Find (plist.Key); MInterval interval; if (p.IsEmpty) @@ -282,90 +282,96 @@ namespace M17N.Core } } - public MText dup () + public MText Dup () { return (new MText (sb.ToString ())); } - public MText ins (int pos, MText mt) + public MText Ins (int pos, MText mt) { insert (pos, mt, 0, mt.nchars); return this; } - public MText ins (int pos, MText mt, int from, int to) + public MText Ins (int pos, MText mt, int from, int to) { insert (pos, mt, from, to); return this; } - public MText del (int from, int to) + public MText Del (int from, int to) { sb.Remove (from, pos_to_idx (this, to) - pos_to_idx (this, from)); nchars -= to - from; foreach (MPlist plist in intervals) - ((MInterval) plist.Val).delete (from, to); + ((MInterval) plist.Val).Delete (from, to); return this; } - public object get_prop (int pos, MSymbol key) + public object GetProp (int pos, MSymbol key) { - MInterval i = (MInterval) intervals.find (key).Val; + MInterval i = (MInterval) intervals.Find (key).Val; if (i == null) return null; - MTextProperty prop = i.get (pos); + MTextProperty prop = i.Get (pos); return (prop != null ? prop.Val : null); } - public object get_prop (int pos, MSymbol key, out MTextProperty prop) + public object GetProp (int pos, MSymbol key, out MTextProperty prop) { - MInterval i = (MInterval) intervals.find (key).Val; + MInterval i = (MInterval) intervals.Find (key).Val; if (i == null) return (prop = null); - prop = i.get (pos); + prop = i.Get (pos); return (prop != null ? prop.Val : null); } - public object get_prop (int pos, MSymbol key, out MTextProperty[] array) + public object GetProp (int pos, MSymbol key, out MTextProperty[] array) { - MInterval i = (MInterval) intervals.find (key).Val; + MInterval i = (MInterval) intervals.Find (key).Val; if (i == null) return (array = null); - MTextProperty prop = i.get (pos, out array); + MTextProperty prop = i.Get (pos, out array); return (prop != null ? prop.Val : null); } - public void push_prop (int from, int to, MSymbol key, object val) + public void PushProp (int from, int to, MSymbol key, object val) { - push_prop (from, to, new MTextProperty (key, val)); + PushProp (from, to, new MTextProperty (key, val)); } - public void push_prop (int from, int to, MTextProperty prop) + public void PushProp (int from, int to, MTextProperty prop) { if (from < 0) { if (default_property == null) default_property = new MPlist (); - default_property.push (prop.key, prop.val); + default_property.Push (prop.key, prop.val); } else { - MInterval root = (MInterval) intervals.find (prop.key).Val; + MInterval root = (MInterval) intervals.Find (prop.key).Val; if (root == null) { root = new MInterval (prop.key, this); - intervals.push (prop.key, root); + intervals.Push (prop.key, root); } root.Push (from, to, prop); } } + public void DumpProp () + { + foreach (MPlist p in intervals) + ((MInterval) p.Val).Dump (); + } + private class MInterval { // position: 0 1 2 3 4 5 6 7 @@ -403,14 +409,14 @@ namespace M17N.Core stack = new MPlist (); } - public MTextProperty get (int pos) + public MTextProperty Get (int pos) { MInterval i = find (pos); return (i.stack.IsEmpty ? null : (MTextProperty) i.stack.Val); } - public MTextProperty get (int pos, out MTextProperty[] array) + public MTextProperty Get (int pos, out MTextProperty[] array) { MInterval i = find (pos); @@ -510,7 +516,7 @@ namespace M17N.Core MInterval c1; if (parent == null) - mtext.intervals.put (key, right); + mtext.intervals.Put (key, right); else if (parent.left == this) parent.left = right; else @@ -542,7 +548,7 @@ namespace M17N.Core MInterval c1; if (parent == null) - mtext.intervals.put (key, left); + mtext.intervals.Put (key, left); else if (parent.left == this) parent.left = left; else @@ -632,6 +638,7 @@ namespace M17N.Core MInterval interval = new MInterval (key, to - pos, stack); total_length -= to - pos; + to = pos; if (right != null) { right.parent = interval; @@ -652,6 +659,7 @@ namespace M17N.Core MInterval interval = new MInterval (key, to - pos, stack); total_length -= to - pos; + from = pos; if (left != null) { left.parent = interval; @@ -669,7 +677,7 @@ namespace M17N.Core MTextProperty prop = (MTextProperty) p.Val; if ((prop.flags & flags) == flags) - p.pop (); + p.Pop (); else p = p.Next; } @@ -686,8 +694,8 @@ namespace M17N.Core MTextProperty prop = (MTextProperty) p.Val; if ((prop.flags & flags) == flags - && stack.get (prop.Key) == null) - stack.push (prop.key, prop); + && stack.Get (prop.Key) == null) + stack.Push (prop.key, prop); } } @@ -793,7 +801,7 @@ namespace M17N.Core private void update_parent (MInterval i) { if (parent == null) - mtext.intervals.put (key, i); + mtext.intervals.Put (key, i); else { int diff; @@ -813,27 +821,27 @@ namespace M17N.Core } } - public void delete (int start, int end) + public void Delete (int start, int end) { update_from_to (); if (start < from) { if (end <= from) { - left.delete (start, end); + left.Delete (start, end); return; } - left.delete (start, from); + left.Delete (start, from); start = from; } else if (end > to) { if (start >= to) { - right.delete (start, end); + right.Delete (start, end); return; } - right.delete (to, end); + right.Delete (to, end); end = to; } if (start == from && end == to) @@ -884,9 +892,24 @@ namespace M17N.Core divide_left (from); if (end < to) divide_right (end); - stack.push (prop.key, prop); + stack.Push (prop.key, prop); + Console.WriteLine ("push({0},{1})", from, to); return prop; } + + public Dump () + { + update_from_to (); + + if (left != null) + left.Dump (); + if (stack.IsEmpty) + Console.WriteLine ("({0} {1})", from, to); + else + Console.WriteLine ("({0} {1} {2})", from, to, stack.Val); + if (right != null) + right.Dump (); + } } private class MTextEnum : IEnumerator diff --git a/Makefile b/Makefile index 3151245..7dfec74 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CORE_SRC = MSymbol.cs MPlist.cs MText.cs CS=gmcs -all: M17N.exe test-sym.exe test-plist.exe test-mtext.exe +all: M17N.exe symbol.exe plist.exe mtext.exe textprop.exe M17NCore.dll: ${CORE_SRC} $(CS) /out:$@ /t:library ${CORE_SRC} @@ -9,14 +9,17 @@ M17NCore.dll: ${CORE_SRC} M17N.exe: M17N.cs M17NCore.dll $(CS) /r:M17NCore M17N.cs -test-mtext.exe: test-mtext.cs M17NCore.dll - $(CS) -codepage:65001 /r:M17NCore test-mtext.cs +mtext.exe: mtext.cs M17NCore.dll + $(CS) -codepage:65001 /r:M17NCore mtext.cs -test-sym.exe: test-sym.cs M17NCore.dll - $(CS) -codepage:65001 /r:M17NCore test-sym.cs +symbol.exe: symbol.cs M17NCore.dll + $(CS) -codepage:65001 /r:M17NCore symbol.cs -test-plist.exe: test-plist.cs M17NCore.dll - $(CS) -codepage:65001 /r:M17NCore test-plist.cs +plist.exe: plist.cs M17NCore.dll + $(CS) -codepage:65001 /r:M17NCore plist.cs + +textprop.exe: textprop.cs M17NCore.dll + $(CS) -codepage:65001 /r:M17NCore textprop.cs clean: rm -f *.dll *.exe diff --git a/mtext.cs b/mtext.cs new file mode 100644 index 0000000..4ed6e5d --- /dev/null +++ b/mtext.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using M17N.Core; + +public class Test +{ + public static void Main() + { + String str = "a𝄀あc"; + MText mt = new MText (str); + + Console.WriteLine ("{0}, Length={1}", mt, mt.Length); + foreach (int c in mt) + Console.WriteLine ("U+{0:X4}", c); + Console.WriteLine (mt + new MText ("漢字")); + + MText mt2 = mt.Dup (); + mt[1] = 'b'; + Console.WriteLine (mt); + Console.WriteLine (mt2); + } +} diff --git a/plist.cs b/plist.cs new file mode 100644 index 0000000..e9caa80 --- /dev/null +++ b/plist.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using M17N.Core; + +public class Test +{ + public static void Main() + { + MSymbol sym1 = new MSymbol ("sym1"); + MSymbol sym2 = new MSymbol ("sym2"); + MPlist plist = new MPlist (); + MText mt1 = new MText ("abc"); + MText mt2 = new MText ("ABC"); + + plist.Put (sym1, mt1); + plist.Put (sym2, mt2); + + Console.WriteLine (plist); + foreach (MPlist p in plist) + Console.WriteLine (p.Key + ":" + p.Val); + } +} diff --git a/symbol.cs b/symbol.cs new file mode 100644 index 0000000..b92921f --- /dev/null +++ b/symbol.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using M17N.Core; + +public class Test +{ + public static void Main() + { + MSymbol sym1 = new MSymbol ("symbol"); + MSymbol sym2 = new MSymbol ("symbol"); + MSymbol sym3 = new MSymbol ("another sym:bol"); + + Console.WriteLine ("sym1 = {0}", sym1); + Console.WriteLine ("sym2 = {0}", sym2); + Console.WriteLine ("sym3 = {0}", sym3); + Console.WriteLine ("sym1 {0} sym2", sym1 == sym2 ? "==" : "!="); + Console.WriteLine ("sym1 {0} sym3", sym1 == sym3 ? "==" : "!="); + + sym1.Put (sym2, "prop1"); + sym1.Put (sym3, "prop2"); + Console.WriteLine (sym1.Get (sym2) + "," + sym1.Get (sym3)); + Console.WriteLine (sym2.Get (sym2) + "," + sym2.Get (sym3)); + Console.WriteLine (sym3.Get (sym2)); + } +} diff --git a/test-mtext.cs b/test-mtext.cs deleted file mode 100644 index e212bf7..0000000 --- a/test-mtext.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using M17N.Core; - -public class Test -{ - public static void Main() - { - String str = "a𝄀あc"; - MText mt = new MText (str); - - Console.WriteLine ("{0}, Length={1}", mt, mt.Length); - foreach (int c in mt) - Console.WriteLine ("U+{0:X4}", c); - Console.WriteLine (mt + new MText ("漢字")); - - MText mt2 = mt.dup (); - mt[1] = 'b'; - Console.WriteLine (mt); - Console.WriteLine (mt2); - } -} diff --git a/test-plist.cs b/test-plist.cs deleted file mode 100644 index 958170c..0000000 --- a/test-plist.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using M17N.Core; - -public class Test -{ - public static void Main() - { - MSymbol sym1 = new MSymbol ("sym1"); - MSymbol sym2 = new MSymbol ("sym2"); - MPlist plist = new MPlist (); - MText mt1 = new MText ("abc"); - MText mt2 = new MText ("ABC"); - - plist.put (sym1, mt1); - plist.put (sym2, mt2); - - Console.WriteLine (plist); - } -} diff --git a/test-sym.cs b/test-sym.cs deleted file mode 100644 index 9160c5a..0000000 --- a/test-sym.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using M17N.Core; - -public class Test -{ - public static void Main() - { - MSymbol sym1 = new MSymbol ("symbol"); - MSymbol sym2 = new MSymbol ("symbol"); - MSymbol sym3 = new MSymbol ("another sym:bol"); - - Console.WriteLine ("sym1 = {0}", sym1); - Console.WriteLine ("sym2 = {0}", sym2); - Console.WriteLine ("sym3 = {0}", sym3); - Console.WriteLine ("sym1 {0} sym2", sym1 == sym2 ? "==" : "!="); - Console.WriteLine ("sym1 {0} sym3", sym1 == sym3 ? "==" : "!="); - - sym1.put (sym2, "prop1"); - sym1.put (sym3, "prop2"); - Console.WriteLine (sym1.get (sym2) + "," + sym1.get (sym3)); - Console.WriteLine (sym2.get (sym2) + "," + sym2.get (sym3)); - Console.WriteLine (sym3.get (sym2)); - } -} diff --git a/textprop.cs b/textprop.cs new file mode 100644 index 0000000..29652d8 --- /dev/null +++ b/textprop.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using M17N.Core; + +public class Test +{ + public static void Main () + { + String str = "0123456789"; + MText mt = new MText (str); + MSymbol sym = new MSymbol ("sym"); + MTextProperty prop = new MTextProperty (sym, "test"); + + mt.PushProp (2, 4, prop); + Console.WriteLine (mt.GetProp (7, sym)); + mt.Del (2, 4); + Console.WriteLine (mt.GetProp (3, sym)); + } +} -- 1.7.10.4