From: handa Date: Mon, 20 Apr 2009 12:37:39 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80a46f5fb11e98798ea0490008ec61cd36c9f5a5;p=m17n%2Fm17n-lib-cs.git *** empty log message *** --- diff --git a/M17N.cs b/M17N.cs index 2e13847..bc72060 100644 --- a/M17N.cs +++ b/M17N.cs @@ -10,6 +10,12 @@ namespace M17N public static bool debug = false; + public static void DebugPrint (object arg) + { + if (debug) + Console.Write (arg); + } + public static void DebugPrint (string fmt, object arg) { if (debug) diff --git a/MPlist.cs b/MPlist.cs index 4212184..6bf1f0c 100644 --- a/MPlist.cs +++ b/MPlist.cs @@ -39,6 +39,11 @@ namespace M17N.Core public bool IsEmpty { get { return next == null; } } public MPlist Next { get { return next; } } + internal bool IsSymbol { get { return Key == MSymbol.symbol; } } + internal bool IsMText { get { return Key == MSymbol.mtext; } } + internal bool IsPlist { get { return Key == MSymbol.plist; } } + internal bool IsInteger { get { return Key == MSymbol.integer; } } + public int Count { get diff --git a/MText.cs b/MText.cs index b7f273e..57a847b 100644 --- a/MText.cs +++ b/MText.cs @@ -478,10 +478,8 @@ namespace M17N.Core public void DumpPropNested () { - Console.Write ("("); foreach (MPlist p in intervals) ((MInterval) p.Val).DumpNested (true); - Console.WriteLine (")"); } private class MInterval @@ -1217,11 +1215,15 @@ namespace M17N.Core if (! mergeable (prev)) return false; + M17N.DebugPrint ("merging "); DumpOne (false, false); + M17N.DebugPrint (" with prev "); prev.DumpOne (false, true); int len = prev.Length - prev.LeftLength; // PREV is Left, Left.Right, ..., or Left....Right. if (prev != Left) { + if (prev.Left != null) + prev.Left.Parent = prev.Parent; prev.Parent.Right = prev.Left; while (prev.Parent != Left) { @@ -1231,7 +1233,11 @@ namespace M17N.Core } Left.Length -= len; if (Left.Length == Left.LeftLength) - Left = Left.Left; + { + if (Left.Left != null) + Left.Left.Parent = this; + Left = Left.Left; + } return true; } @@ -1242,11 +1248,16 @@ namespace M17N.Core if (! mergeable (next)) return false; - int len = next.Length - next.LeftLength; + M17N.DebugPrint ("merging "); DumpOne (false, false); + M17N.DebugPrint (" with next "); next.DumpOne (false, true); + + int len = next.Length - next.RightLength; // NEXT is Right, Right.Left, ..., or Right....Left. if (next != Right) { + if (next.Right != null) + next.Right.Parent = next.Parent; next.Parent.Left = next.Right; while (next.Parent != Right) { @@ -1255,9 +1266,12 @@ namespace M17N.Core } } Right.Length -= len; - if (Right.Length == Right.LeftLength) - Right = Right.Left; - + if (Right.Length == Right.RightLength) + { + if (Right.Right != null) + Right.Right.Parent = this; + Right = Right.Right; + } return true; } @@ -1350,26 +1364,52 @@ namespace M17N.Core } } + private int Depth { + get { return (Parent == null ? 0 : Parent.Depth + 1); } + } + + private void DumpNestedOne () + { + int depth; + MInterval i; + + for (depth = 0, i = this; i.Parent != null; depth++, i = i.Parent) + Console.Write (" "); + DumpOne (true, true); + } + public void DumpNested (bool force) { + DumpNested ("", force); + } + + public void DumpNested (string indent, bool force) + { if (force || M17N.debug) { - update_from_to (); + int indent_type = (Parent == null ? 1 + : Parent.Left == this ? 0 : 2); - Console.Write ("#{0}({1} {2} {3}", ID, Length, From, To); - foreach (MPlist p in Stack) - Console.Write (" " + p.Val); + update_from_to (); if (Left != null) { - Console.Write (" left="); - Left.DumpNested (force); + if (indent_type <= 1) + Left.DumpNested (indent + " ", force); + else + Left.DumpNested (indent + "| ", force); } + if (indent_type == 0) + Console.Write (indent + ".-"); + else if (indent_type == 2) + Console.Write (indent + "`-"); + DumpOne (true, true); if (Right != null) { - Console.Write (" right="); - Right.DumpNested (force); + if (indent_type >= 1) + Right.DumpNested (indent + " ", force); + else if (indent_type == 2) + Right.DumpNested (indent + "| ", force); } - Console.Write (")"); } } } diff --git a/textprop.cs b/textprop.cs index c0502ef..88af7cd 100644 --- a/textprop.cs +++ b/textprop.cs @@ -9,12 +9,27 @@ public class Test { String str = "0123456789"; MText mt = new MText (str); - MSymbol sym = new MSymbol ("sym"); - MTextProperty prop1 = new MTextProperty (sym, "test1"); - MTextProperty prop2 = new MTextProperty (sym, "test2"); + MSymbol sym = new MSymbol ("key"); + MTextProperty prop1 = new MTextProperty (sym, "val0"); + MTextProperty prop2 = new MTextProperty (sym, "val1"); M17N.M17N.debug = true; + mt.PushProp (1, 3, prop1); + mt.PushProp (0, 1, prop1); + mt.PushProp (0, 1, prop2); + mt.PushProp (3, 5, prop1); + mt.PushProp (3, 5, prop2); + mt.PushProp (7, 8, prop2); + mt.PushProp (5, 7, prop2); + mt.PushProp (5, 7, prop1); + mt.PushProp (8, 10, prop1); + mt.PopProp (8, 9, sym); + mt.DumpPropNested (); + mt.PopProp (5, 9, sym); + mt.DumpPropNested (); + + mt = new MText (str); mt.PushProp (2, 5, prop1); mt.DumpProp (); mt.PushProp (3, 6, prop2); @@ -23,6 +38,7 @@ public class Test mt.DumpProp (); mt.Ins (5, new MText ("45678")); mt.DumpProp (); + mt.Dup ().DumpProp (); mt.PopProp (0, 3, sym); mt.DumpProp (); mt.PopProp (2, 8, sym);