*** empty log message ***
[m17n/m17n-lib-cs.git] / MText.cs
index 4a8d448..52d1943 100644 (file)
--- a/MText.cs
+++ b/MText.cs
@@ -24,26 +24,29 @@ namespace M17N.Core
     [FlagsAttribute]
     public enum Flags
     {
-      None =           0,
+      None =           0x00,
       /// A text inserted before a character that has this property
       /// inherits this property.  If the text already has properties
-      /// of the same key, they are deleted.  See the documentation of
-      /// Sensitive for exception.
-      FrontSticky =    1,
+      /// of the same key, they are deleted.
+      FrontSticky =    0x01,
       /// A text inserted after a character that has this property
       /// inherits this property.  If the text already has properties
-      /// of the same key, they are deleted.  See the documentation of
-      /// Sensitive for exception.
-      RearSticky =     2,
+      /// of the same key, they are deleted.
+      RearSticky =     0x02,
       /// This property is deleted from a span of text if the span is
       /// modified (i.e. a character is changed, a text is inserted,
       /// some part is deleted).  This propery is also deleted if a
       /// property of the same key is added, which means that this
-      /// property is not stackable.  If this property is also
-      /// FrontSticky (or RearSticky), text insertion just before (or
-      /// after) the span also deletes this property from the span of
-      /// text.
-      Sensitive =      4,
+      /// property is not stackable.
+      Sensitive =      0x04,
+      /// Like Sensitive but also this property is deleted from a span
+      /// of text if a text just before the span is modified,
+      /// inserted, or deleted.
+      FrontSensitive = 0x08,
+      /// Like Sensitive but also this property is deleted from a span
+      /// of text if a text just after the span is modified, inserted,
+      /// or deleted.
+      RearSensitive =  0x10
     };
 
     internal MSymbol key;
@@ -55,7 +58,7 @@ namespace M17N.Core
     public MProperty (MSymbol key, object val)
     {
       if (key.flags == null)
-       key.flags = MProperty.Flags.None;
+       key.flags = Flags.None;
       this.key = key;
       this.val = val;
     }
@@ -66,6 +69,11 @@ namespace M17N.Core
       this.val = val;
     }
 
+    public static bool HasFlags (MSymbol key, Flags flags)
+    {
+      return ((key.flags & flags) != Flags.None);
+    }
+
     public override string ToString ()
     {
       return key.ToString () + ":" + val;
@@ -137,27 +145,27 @@ namespace M17N.Core
     public static MText operator+ (object obj, MText mt)
     {
       if (obj is string)
-       return new MText ((string) obj) + mt;
+       {
+         MText mtnew = new MText ((string) obj);
+         return mtnew.Ins (mtnew.Length, mt);
+       }
       throw new Exception ("Unknown object type: " + obj.GetType());
     }
 
-    public static MText operator+ (MText mt1, MText mt2)
+    public static MText operator+ (MText mt, object obj)
     {
-      MText mt = new MText ();
-
-      mt.sb.Append (mt1.sb);
-      mt.sb.Append (mt2.sb);
-      mt.nchars = mt1.nchars + mt2.nchars;
-      return mt;
+      if (obj is string)
+       return mt + new MText ((string) obj);
+      if (obj is int)
+       return mt.Dup ().Ins (mt.Length, (int) obj);
+      if (obj is char)
+       return mt.Dup ().Ins (mt.Length, (int) ((char) obj));
+      throw new Exception ("Unknown object type: " + obj.GetType());
     }
 
-    public static MText operator+ (string str, MText mt)
+    public static MText operator+ (MText mt1, MText mt2)
     {
-      MText mtnew = new MText (str);
-
-      mtnew.sb.Append (mt.sb);
-      mtnew.nchars += mt.nchars;
-      return mtnew;
+      return mt1.Dup ().Ins (mt1.Length, mt2);
     }
 
     // Public properties
@@ -178,7 +186,7 @@ namespace M17N.Core
       return this.sb.ToString ().CompareTo (other.sb.ToString ());
     }
 
-    public override String ToString () { return "\"" + sb.ToString () + "\""; }
+    public override string ToString () { return sb.ToString (); }
 
     private static bool surrogate_high_p (char c)
     {
@@ -521,6 +529,9 @@ namespace M17N.Core
                root.PopSensitive (from, to);
              else
                root.Pop (from, to);
+             root = (MInterval) p.Val;
+             if (M17n.debug)
+               DumpPropNested ();
              root.MergeAfterChange (from, to);
              root.Balance ();
            }
@@ -627,20 +638,37 @@ namespace M17N.Core
 
       private bool isRearSticky
       {
-       get { return ((Key.flags & MProperty.Flags.RearSticky)
-                     != MProperty.Flags.None); }
+       get { return MProperty.HasFlags (Key, MProperty.Flags.RearSticky) ; }
       }
 
       private bool isFrontSticky
       {
-       get { return ((Key.flags & MProperty.Flags.FrontSticky)
-                     != MProperty.Flags.None); }
+       get { return MProperty.HasFlags (Key, MProperty.Flags.FrontSticky) ; }
       }
 
       public bool isSensitive
       {
-       get { return ((Key.flags & MProperty.Flags.Sensitive)
-                     != MProperty.Flags.None); }
+       get { return MProperty.HasFlags (Key, MProperty.Flags.Sensitive) ; }
+      }
+
+      public bool isFrontSensitive
+      {
+       get { return MProperty.HasFlags (Key,
+                                        MProperty.Flags.FrontSensitive) ; }
+      }
+
+      public bool isRearSensitive
+      {
+       get { return MProperty.HasFlags (Key,
+                                        MProperty.Flags.RearSensitive) ; }
+      }
+
+      public bool isAnySensitive
+      {
+       get { return MProperty.HasFlags (Key,
+                                        (MProperty.Flags.Sensitive
+                                         | MProperty.Flags.RearSensitive
+                                         | MProperty.Flags.FrontSensitive)) ; }
       }
 
       private void update_from_to ()
@@ -907,6 +935,30 @@ namespace M17N.Core
        return copy;
       }
 
+      public MInterval Copy (MText mt, int start, int end,
+                            bool first, bool last)
+      {
+       MInterval copy = Copy (mt, start, end);
+       MInterval head = find_head (start);
+       MInterval tail = find_tail (end);
+
+       if (! head.Stack.IsEmpty
+           && (isAnySensitive && head.From < start
+               || isFrontSensitive && ! first))
+         {
+           head = copy.find_head (0);
+           head.Stack.Clear ();
+         }
+       if (! tail.Stack.IsEmpty
+           && (isAnySensitive && end < head.To
+               || isRearSensitive && ! last))
+         {
+           tail = copy.find_tail (copy.Length);
+           tail.Stack.Clear ();
+         }
+       return copy;
+      }
+
       //  this-.   ==>   this-.
       //     right          newright-.
       //                            right
@@ -914,7 +966,7 @@ namespace M17N.Core
       {
        MInterval interval = new MInterval (Key, mtext, To - pos, Stack);
 
-       M17n.DebugPrint ("divide-right({0}) at ", pos); DumpOne (false, true);
+       M17n.DebugPrint ("divide-right({0}) at {1}\n", pos, this);
        To = pos;
        if (Right != null)
          {
@@ -934,7 +986,7 @@ namespace M17N.Core
       {
        MInterval interval = new MInterval (Key, mtext, pos - From, Stack);
 
-       M17n.DebugPrint ("divide-left({0}) at ", pos); DumpOne (false, true);
+       M17n.DebugPrint ("divide-left({0}) at {1}\n", pos, this);
        From = pos;
        if (Left != null)
          {
@@ -985,9 +1037,20 @@ namespace M17N.Core
            MInterval i = interval.find_head (start);
 
            len = 0;
-           while (i != null && mergeable (i))
+           if (Stack.IsEmpty
+               && (isFrontSensitive
+                   || ((isSensitive || isRearSensitive) && i.From < start)))
+             {
+               M17n.DebugPrint (" grafting {0}", i);
+               if (i.To < end)
+                 len = i.To - start;
+               else
+                 len = end - start;
+               i = i.Next;
+             }
+           while (i != null && i.From < end && mergeable (i))
              {
-               M17n.DebugPrint (" grafting "); i.DumpOne (false, false);
+               M17n.DebugPrint (" grafting {0}", i);
                len += i.To - i.From;
                if (i.From < start)
                  len -= start - i.From;
@@ -1000,7 +1063,7 @@ namespace M17N.Core
              }
          }
 
-       M17n.DebugPrint (" grafted {0} in ", len); DumpOne (false, true);
+       M17n.DebugPrint (" grafted {0} in {1}\n", len, this);
        if (len > 0)
          enlarge (len);
        return len;
@@ -1019,9 +1082,20 @@ namespace M17N.Core
            MInterval i = interval.find_tail (end);
 
            len = 0;
-           while (i != null && mergeable (i))
+           if (Stack.IsEmpty
+               && (isRearSensitive
+                   || ((isSensitive || isFrontSensitive) && end < i.To)))
              {
-               M17n.DebugPrint (" grafting "); i.DumpOne (false, false);
+               M17n.DebugPrint (" grafting {0}", i);
+               if (i.From <= start)
+                 len = end - start;
+               else
+                 len = end - i.From;
+               i = i.Prev;
+             }
+           while (i != null && i.To <= start && mergeable (i))
+             {
+               M17n.DebugPrint (" grafting {0}", i);
                len += i.To - i.From;
                if (end < i.To)
                  len -= i.To - end;
@@ -1034,7 +1108,7 @@ namespace M17N.Core
              }
          }
 
-       M17n.DebugPrint (" grafted {0} in ", len); DumpOne (false, true);
+       M17n.DebugPrint (" grafted {0} in {1}\n", len, this);
        if (len > 0)
          enlarge (len);
        return len;
@@ -1044,126 +1118,178 @@ namespace M17N.Core
       {
        update_from_to ();
 
-       M17n.DebugPrint ("insert({0} to {1}) at {2} in ", start, end, pos);
-       DumpOne (false, false);
+       M17n.DebugPrint ("insert({0} to {1}) at {2} in {3}",
+                        start, end, pos, this);
 
        if (pos < From)
          Left.Insert (pos, interval, start, end);
        else if (pos == From)
          {
-           if (Left != null)
-             {
-               MInterval prev = Prev;
+           MInterval prev = Left != null ? Prev : null;
 
-               if (prev.isSensitive && prev.isRearSticky)
-                 prev.Stack.Clear ();
-               start += prev.graft_forward (interval, start, end);
-             }
-           if (isSensitive && isFrontSticky)
+           if (isFrontSensitive)
              Stack.Clear ();
-           if (start < end)
+           if (prev != null && isRearSensitive)
+             prev.Stack.Clear ();
+           if (prev != null && isRearSticky && ! prev.Stack.IsEmpty)
              {
-               end -= graft_backward (interval, start, end);
-               if (start < end)
-                 {
-                   if (interval != null)
-                     interval = interval.Copy (mtext, start, end);
-                   else
-                     interval = new MInterval (Key, mtext, end - start, null);
+               prev.enlarge (end - start);
+               return;
+             }
+           if (isFrontSticky && ! Stack.IsEmpty)
+             {
+               enlarge (end - start);
+               return;
+             }
+           bool front_grafted = false, rear_grafted = false;
+           int grafted;
+           if (prev != null
+               && (grafted = prev.graft_forward (interval, start, end)) > 0)
+             {
+               start += grafted;
+               if (start == end)
+                 return;
+               front_grafted = true;
+             }
+           if ((grafted = graft_backward (interval, start, end)) > 0)
+             {
+               end -= grafted;
+               if (start == end)
+                 return;
+               rear_grafted = true;
+             }
 
-                   MInterval i;
-                   if (Left != null)
-                     {
-                       //    .-this-.   ==>          .-this-.
-                       // left-.                 .-left-.
-                       //    child                     child-.
-                       //                                 interval
-                       i = Left.RightMost;
-                       i.Right = interval;
-                     }
-                   else
-                     {
-                       Left = interval;
-                       i = this;
-                     }
-                   interval.Parent = i;
-                   for (; i != null; i = i.Parent)
-                     i.Length += interval.Length;
-                 }
+           if (interval != null)
+             interval = interval.Copy (mtext, start, end,
+                                       front_grafted || prev == null,
+                                       rear_grafted);
+           else
+             interval = new MInterval (Key, mtext, end - start, null);
+
+           MInterval i;
+           if (Left != null)
+             {
+               //    .-this-.   ==>          .-this-.
+               // left-.                 .-left-.
+               //    child                     child-.
+               //                                 interval
+               i = Left.RightMost;
+               i.Right = interval;
              }
+           else
+             {
+               Left = interval;
+               i = this;
+             }
+           interval.Parent = i;
+           for (; i != null; i = i.Parent)
+             i.Length += interval.Length;
          }
        else if (pos < To)
          {
-           if (isSensitive)
-             Stack.Clear ();
-
-           int len = graft_forward (interval, start, end);
-           start += len;
-           pos += len;
-           if (start < end)
+           if (! Stack.IsEmpty)
              {
-               end -= graft_backward (interval, start, end);
-               if (start < end)
+               if (isSensitive || isFrontSensitive || isRearSensitive)
+                 Stack.Clear ();
+               else if (isFrontSticky || isRearSticky)
                  {
-                   if (interval != null)
-                     interval = interval.Copy (mtext, start, end);
-                   else
-                     interval = new MInterval (Key, mtext, end - start, null);
-
-                   divide_right (pos);
-                   Right.Left = interval;
-                   interval.Parent = Right;
-                   for (MInterval i = Right; i != null; i = i.Parent)
-                     i.Length += interval.Length;
+                   enlarge (end - start);
+                   return;
                  }
              }
+           bool front_grafted = false, rear_grafted = false;
+           int grafted;
+           if ((grafted = graft_forward (interval, start, end)) > 0)
+             {
+               start += grafted;
+               if (start == end)
+                 return;
+               front_grafted = true;
+               pos += grafted;
+             }
+           if ((grafted = graft_backward (interval, start, end)) > 0)
+             {
+               end -= grafted;
+               if (start == end)
+                 return;
+               rear_grafted = true;
+             }
+           if (interval != null)
+             interval = interval.Copy (mtext, start, end,
+                                       front_grafted, rear_grafted);
+           else
+             interval = new MInterval (Key, mtext, end - start, null);
+
+           divide_right (pos);
+           Right.Left = interval;
+           interval.Parent = Right;
+           for (MInterval i = Right; i != null; i = i.Parent)
+             i.Length += interval.Length;
          }
        else if (pos == To)
          {
+           MInterval next = Right != null ? Next : null;
+
+           if (isRearSensitive)
+             Stack.Clear ();
+           if (next != null && isFrontSensitive)
+             next.Stack.Clear ();
+           if (isRearSticky && ! Stack.IsEmpty)
+             {
+               enlarge (end - start);
+               return;
+             }
+           if (next != null && isFrontSticky && ! next.Stack.IsEmpty)
+             {
+               next.enlarge (end - start);
+               return;
+             }
+           bool front_grafted = false, rear_grafted = false;
+           int grafted;
+           if (next != null
+               && (grafted = next.graft_backward (interval, start, end)) > 0)
+             {
+               end -= grafted;
+               if (start == end)
+                 return;
+               rear_grafted = true;
+             }
+           if ((grafted = graft_forward (interval, start, end)) > 0)
+             {
+               start += grafted;
+               if (start == end)
+                 return;
+               front_grafted = true;
+             }
+           if (interval != null)
+             interval = interval.Copy (mtext, start, end,
+                                       front_grafted,
+                                       rear_grafted || next == null);
+           else
+             interval = new MInterval (Key, mtext, end - start, null);
+
+           MInterval i;
            if (Right != null)
              {
-               MInterval next = Next;
+               //    .-this-.   ==>          .-this-.
+               //         .-right                 .-right
+               //     child                  .-child
+               //                        interval
 
-               if (next.isSensitive && next.isFrontSticky)
-                 next.Stack.Clear ();
-               end -= next.graft_backward (interval, start, end);
+               i = Right.LeftMost;
+               i.Left = interval;
              }
-           if (isSensitive && isRearSticky)
-             Stack.Clear ();
-           if (start < end)
+           else
              {
-               start += graft_forward (interval, start, end);
-               if (start < end)
-                 {
-                   if (interval != null)
-                     interval = interval.Copy (mtext, start, end);
-                   else
-                     interval = new MInterval (Key, mtext, end - start, null);
-
-                   MInterval i;
-                   if (Right != null)
-                     {
-                       //    .-this-.   ==>          .-this-.
-                       //         .-right                 .-right
-                       //     child                  .-child
-                       //                        interval
-
-                       i = Right.LeftMost;
-                       i.Left = interval;
-                     }
-                   else
-                     {
-                       Right = interval;
-                       i = this;
-                     }
-                   interval.Parent = i;
-                   for (; i != null; i = i.Parent)
-                     i.Length += interval.Length;
-                 }
+               Right = interval;
+               i = this;
              }
+           interval.Parent = i;
+           for (; i != null; i = i.Parent)
+             i.Length += interval.Length;
          }
        else                    // (pos > To)
-         Next.Insert (pos, interval, start, end);
+         Right.Insert (pos, interval, start, end);
        M17n.DebugPrint (" done\n");
       }
 
@@ -1203,31 +1329,53 @@ namespace M17N.Core
       public void Delete (int start, int end)
       {
        update_from_to ();
-       M17n.DebugPrint ("delete({0} {1}) from ", start, end); DumpOne (false, true);
+       M17n.DebugPrint ("delete({0} {1}) from {2}\n", start, end, this);
+
+       bool front_checked = false;
+       bool rear_checked = false;
+
        if (start < From)
          {
            if (end <= From)
              {
+               if (end == From && isFrontSensitive)
+                 Stack.Clear ();
                Left.Delete (start, end);
                return;
              }
+           if (isSensitive || isFrontSensitive)
+             Stack.Clear ();
            Left.Delete (start, From);
            To -= From - start;
            end -= From - start;
            From = start;
+           front_checked = true;
          }
        if (end > To)
          {
            if (start >= To)
              {
+               if (start == To && isRearSensitive)
+                 Stack.Clear ();
                Right.Delete (start, end);
                return;
              }
+           if (isSensitive || isRearSensitive)
+             Stack.Clear ();
            Right.Delete (To, end);
            end = To;
+           rear_checked = true;
          }
        if (start == From && end == To)
          {
+           if (! front_checked
+               && start > 0
+               && isRearSensitive)
+             Prev.Stack.Clear ();
+           if (! rear_checked
+               && end < mtext.Length
+               && isFrontSensitive)
+             Next.Stack.Clear ();
            if (Right == null)
              {
                vacate_node (Left);
@@ -1251,6 +1399,8 @@ namespace M17N.Core
          {
            int len = end - start;
 
+           if (isAnySensitive)
+             Stack.Clear ();
            for (MInterval i = this; i != null; i = i.Parent)
              i.Length -= len;
          }
@@ -1259,7 +1409,7 @@ namespace M17N.Core
       public void Push (int start, int end, MProperty prop)
       {
        update_from_to ();
-       M17n.DebugPrint ("push({0} {1}) at ", start, end); DumpOne (false, true);
+       M17n.DebugPrint ("push({0} {1}) at {2}\n", start, end, this);
        if (start < From)
          {
            if (end <= From)
@@ -1281,6 +1431,8 @@ namespace M17N.Core
            end = To;
          }
 
+       if (! Stack.IsEmpty && isAnySensitive)
+         Stack.Clear ();
        if (start > From)
          divide_left (start);
        if (end < To)
@@ -1289,22 +1441,23 @@ namespace M17N.Core
       }
 
       /// Combine intervals between HEAD and TAIL (both inclusive) to
-      /// the common parent of HEAD and TAIL while assuming that the
-      /// intervals are mergeable.
+      /// the common parent of HEAD and TAIL.  Callers should assure
+      /// that the intervals are mergeable in advance.
       private static void combine (MInterval head, MInterval tail)
       {
-       M17n.DebugPrint ("merging "); head.DumpOne (true, false);
-       M17n.DebugPrint (" through "); tail.DumpOne (true, false);
+       M17n.DebugPrint ("combining {0} through {1}", head, tail);
 
+       head.update_from_to ();
+       tail.update_from_to ();
        int from = head.From;
        int to = tail.To;
+
        // The nearest common parent of HEAD and TAIL.
        MInterval root;
-
        for (root = head; root.To + root.RightLength < to;
             root = root.Parent);
        
-       M17n.DebugPrint (" common root is "); root.DumpOne (false, true);
+       M17n.DebugPrint (" with common root {0}\n", root);
 
        if (from < root.From)
          {
@@ -1312,7 +1465,7 @@ namespace M17N.Core
 
            while (true)
              {
-               M17n.DebugPrint ("merging "); prev.DumpOne (false, true);
+               M17n.DebugPrint ("merging {0}\n", prev);
                prev.vacate_node (prev.Left, root);
                if (prev == head)
                  break;
@@ -1321,6 +1474,7 @@ namespace M17N.Core
                else
                  prev = prev.Parent;
              }
+           root.update_from_to ();
          }
        if (root.To < to)
          {
@@ -1328,7 +1482,7 @@ namespace M17N.Core
 
            while (true)
              {
-               M17n.DebugPrint ("merging "); next.DumpOne (false, true);
+               M17n.DebugPrint ("merging {0}\n", next);
                next.vacate_node (next.Right, root);
                if (next == tail)
                  break;
@@ -1337,6 +1491,7 @@ namespace M17N.Core
                else
                  next = next.Parent;
              }
+           root.update_from_to ();
          }
       }
 
@@ -1344,40 +1499,39 @@ namespace M17N.Core
       {
        update_from_to ();
 
-       MInterval head = find_head (start), tail = head, i;
+       MInterval head = find_head (start), i = head;
+       MInterval tail = start < end ? find_tail (end) : head;
+
+       if (tail.To < Length)
+         tail = tail.Next;
 
        if (start == head.From && start > 0)
          {
-           i = head.Prev;
-           if (head.mergeable (i))
-             head = i;
+           MInterval prev = head.Prev;
+           if (head.mergeable (prev))
+             head = prev;
          }
-       while (tail.To < end)
+       M17n.DebugPrint ("merge between {0} and {1}\n", head, tail);
+       while (i != tail)
          {
-           i = tail.Next;
-           if (! tail.mergeable (i))
+           MInterval next = i.Next;
+
+           if (! i.mergeable (next))
              {
-               if (head != tail)
-                 combine (head, tail);
-               head = i;
+               if (head != i)
+                 combine (head, i);
+               head = next;
              }
-           tail = i;
-         }
-       while (true)
-         {
-           i = tail.Next;
-           if (i == null || ! tail.mergeable (i))
-             break;
-           tail = i;
+           i = next;
          }
-       if (head != tail)
-         combine (head, tail);
+       if (head != i)
+         combine (head, i);
       }
 
       public void Pop (int start, int end)
       {
        update_from_to ();
-       M17n.DebugPrint ("pop({0} {1}) at ", start, end); DumpOne (false, true);
+       M17n.DebugPrint ("pop({0} {1}) at {2}\n", start, end, this);
        if (start < From)
          {
            if (end <= From)
@@ -1401,11 +1555,16 @@ namespace M17N.Core
 
        if (! Stack.IsEmpty)
          {
-           if (start > From)
-             divide_left (start);
-           if (end < To)
-             divide_right (end);
-           Stack.Pop ();
+           if (isAnySensitive)
+             Stack.Clear ();
+           else
+             {
+               if (start > From)
+                 divide_left (start);
+               if (end < To)
+                 divide_right (end);
+               Stack.Pop ();
+             }
          }
       }
 
@@ -1433,9 +1592,21 @@ namespace M17N.Core
        Pop (head.From, tail.To);
       }
 
-      private void DumpOne (bool with_prop, bool newline)
+      public override string ToString ()
       {
-       DumpOne (with_prop, newline, false);
+       string str = String.Format ("#{0}({1} {2} {3} [", ID, Length, From, To);
+       bool first = true;
+       foreach (MPlist p in Stack)
+         {
+           if (first)
+             {
+               str += ((MProperty) p.Val).Val;
+               first = false;
+             }
+           else
+             str += " " + ((MProperty) p.Val).Val;
+         }
+       return (str + "])");
       }
 
       private void DumpOne (bool with_prop, bool newline, bool force)
@@ -1443,9 +1614,16 @@ namespace M17N.Core
        if (force || M17n.debug)
          {
            Console.Write ("#{0}({1} {2} {3}", ID, Length, From, To);
-           if (with_prop)
-             foreach (MPlist p in Stack)
-               Console.Write (" " + p.Val);
+           if (with_prop && ! Stack.IsEmpty)
+             {
+               string prepend = " [";
+               foreach (MPlist p in Stack)
+                 {
+                   Console.Write (prepend + ((MProperty) p.Val).Val);
+                   prepend = " ";
+                 }
+               Console.Write ("]");
+             }
            Console.Write (")");
            if (newline)
              Console.WriteLine ();