예제 #1
0
 /// <summary>
 ///     Implementation of flattening the MarkupString. This assumes the wrapper has given us a mixed markup for the first
 ///     step.
 /// </summary>
 /// <param name="markupStringList">A reference to a markupStringList to put the generated MarkupString instances into.</param>
 /// <param name="mup">The Markup of our parent to Markup.Mix()</param>
 private void FlattenInto(ref List <MarkupString> markupStringList, Markup mup)
 {
     if (!this.IsString())
     {
         foreach (MarkupString each in this.beneathList)
         {
             each.FlattenInto(ref markupStringList, this.MyMarkup.Mix(mup));
         }
     }
     else
     {
         var myMarkupParent = new MarkupString(mup);
         myMarkupParent.Insert(this.bareString.ToString(), 0);
         markupStringList.Add(myMarkupParent);
     }
 }
예제 #2
0
        /// <summary>
        /// StringTest tests strings. To be converted into a UnitTest later.
        /// </summary>
        public static void StringTest()
        {
            Console.Read();

            const MarkupRule hiLite = MarkupRule.HiLight;
            var hiLiteAsList        = new HashSet <MarkupRule> {
                hiLite
            };
            var testString1 = new MarkupString(new Markup(hiLiteAsList));
            var testString2 = new MarkupString();

            /* ----------------------------------
             *  Testing Ansi Insert and Remove
             * ---------------------------------- */
            Console.WriteLine("Inserting DOOD into HiLite markup string 1 at position 0.");
            testString1.Insert("DOOD", 0);
            Console.WriteLine("Inserting Omnomnom into markup string 2 at position 0.");
            testString2.Insert("Omnomnom", 0);
            Console.WriteLine("Inserting markup string 1 into markup string 2 at position 4.");
            testString2.Insert(testString1, 4);
            Console.WriteLine("Printing markup string 2: ");
            Console.WriteLine(testString2.ToString());
            Console.WriteLine("Removing 4 characters starting at position 3 from markup string 2.");
            testString2.Remove(3, 4);
            Console.WriteLine("Printing markup string 2: ");
            Console.WriteLine(testString2.ToString());

            /* ----------------------------------
             *  Testing Ansi Flattening
             * ---------------------------------- */
            Console.WriteLine("Ansi Flattening Tests");
            var testString3 = new List <MarkupString>();

            testString2.FlattenInto(ref testString3);

            Console.WriteLine("Flattening string 2 into string 3, and printing.");
            Console.WriteLine(testString2.ToString());

            var sb2 = new StringBuilder();

            foreach (MarkupString each in testString3)
            {
                sb2.Append(each.ToTestString());
            }

            Console.WriteLine(sb2.ToString());
            Console.WriteLine("\n\n\n");
            Console.ReadLine();


            Console.WriteLine("Creating string 4 from string 2 (" + testString2 + "), starting at position 2, length 4.");
            var testString4 = new MarkupString(testString2, 2, 4);

            Console.WriteLine(testString4.ToString());

            Console.WriteLine("\nInserting 'Graaaa' into string 4 at position 2.");
            testString4.Insert("Graaaa", 2);

            Console.WriteLine("Printing test string 4");
            Console.WriteLine(testString4);

            Console.WriteLine("Replacing string 4 at position 3 for length 4 with 'IttyBittyKittyCommitty'");
            testString4.Replace(new MarkupString("IttyBittyKittyCommitty"), 3, 4);
            Console.WriteLine("Printing test string 4");
            Console.WriteLine(testString4);

            Console.WriteLine("Replacing string 4 at position 4 for length 2 with string 2 (" + testString2 + ")");
            testString4.Replace(testString2, 4, 2);
            Console.WriteLine("Printing test string 4");
            Console.WriteLine(testString4);
            Console.ReadLine();
        }