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 ()
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;
}
return str + ")";
}
- public MPlist find (MSymbol key)
+ public MPlist Find (MSymbol key)
{
MPlist p;
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);
return this;
}
- public object pop ()
+ public object Pop ()
{
if (IsEmpty)
return null;
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.
{
if (current == null)
current = plist;
- else if (current.IsEmpty)
- return false;
else
current = current.next;
- return true;
+ return (! current.IsEmpty);
}
}
}
private class MSymbolData
{
public string name;
- public Object value;
+ public object value;
public MPlist plist;
public MSymbolData (string name)
return str;
}
- public override bool Equals (Object sym)
+ public override bool Equals (object sym)
{
return (this.data == ((MSymbol) sym).data);
}
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);
}
}
}
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)
}
}
- 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
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);
MInterval c1;
if (parent == null)
- mtext.intervals.put (key, right);
+ mtext.intervals.Put (key, right);
else if (parent.left == this)
parent.left = right;
else
MInterval c1;
if (parent == null)
- mtext.intervals.put (key, left);
+ mtext.intervals.Put (key, left);
else if (parent.left == this)
parent.left = left;
else
MInterval interval = new MInterval (key, to - pos, stack);
total_length -= to - pos;
+ to = pos;
if (right != null)
{
right.parent = interval;
MInterval interval = new MInterval (key, to - pos, stack);
total_length -= to - pos;
+ from = pos;
if (left != null)
{
left.parent = interval;
MTextProperty prop = (MTextProperty) p.Val;
if ((prop.flags & flags) == flags)
- p.pop ();
+ p.Pop ();
else
p = p.Next;
}
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);
}
}
private void update_parent (MInterval i)
{
if (parent == null)
- mtext.intervals.put (key, i);
+ mtext.intervals.Put (key, i);
else
{
int diff;
}
}
- 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)
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
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}
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
--- /dev/null
+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);
+ }
+}
--- /dev/null
+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);
+ }
+}
--- /dev/null
+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));
+ }
+}
+++ /dev/null
-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);
- }
-}
+++ /dev/null
-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);
- }
-}
+++ /dev/null
-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));
- }
-}
--- /dev/null
+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));
+ }
+}