コード例 #1
0
        /// <summary>
        ///     Wrapper for flattening the MarkupString. This is meant to create an equivalent MarkupString List.
        ///     <remarks>
        ///         This should call Mix as we move down, and then when we hit text, create the new MarkupString representation
        ///         of that string, with a parent that holds this new Mixed Markup.
        ///     </remarks>
        /// </summary>
        /// <param name="markupStringList">A reference to a markupStringList to put the generated MarkupString instances into.</param>
        public void FlattenInto(ref List <MarkupString> markupStringList)
        {
            var myMarkup = new Markup();

            this.FlattenInto(ref markupStringList, this.MyMarkup.Mix(myMarkup));
        }
コード例 #2
0
 /// <summary>
 ///     Destructively copies the current Markup of this instance to the markup object given.
 /// </summary>
 /// <param name="newMarkup">A new Markup object made with the default Constructor.</param>
 private void CopyMarkup(Markup newMarkup)
 {
     newMarkup.MyMarkup.UnionWith(this.MyMarkup);
 }
コード例 #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MarkupString" /> class.
 /// </summary>
 public MarkupString()
 {
     beneathList  = new List <MarkupString>();
     stringWeight = new List <int>();
     MyMarkup     = new Markup();
 }
コード例 #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MarkupString" /> class.
 ///     <remark>
 ///         This is used for creating a Markup node.
 ///     </remark>
 /// </summary>
 /// <param name="markup">The Markup to use the left side of this MarkupString Node.</param>
 public MarkupString(Markup markup)
 {
     MyMarkup     = new Markup(markup);
     beneathList  = new List <MarkupString>();
     stringWeight = new List <int>();
 }
コード例 #5
0
        /// <summary>
        ///     The InsertString will put markupStringArg into the position in the MarkupString structure.
        ///     To do this, it may split up a string beneath it. After all, the node is expected to be Marked Up.
        /// </summary>
        /// <param name="markupStringArg">The MarkupString to insert. Please make sure to give it a Copy!</param>
        /// <param name="position">The position into which to insert. See remarks for insertion logic.</param>
        /// <returns>The MarkupString itself.</returns>
        public MarkupString Insert(MarkupString markupStringArg, int position)
        {
            if (IsString())
            {
                beneathList  = new List <MarkupString>();
                stringWeight = new List <int>();
                MyMarkup     = new Markup(); // Blank Markup Transition

                var rightside = bareString.ToString().Substring(position);
                var leftside  = bareString.ToString().Substring(0, bareString.Length - rightside.Length);

                beneathList.Add(new MarkupString(leftside));
                beneathList.Add(new MarkupString(markupStringArg));
                beneathList.Add(new MarkupString(rightside));

                bareString = null;

                stringWeight.Add(beneathList[0].Weight());
                stringWeight.Add(beneathList[1].Weight());
                stringWeight.Add(beneathList[2].Weight());
            }
            else
            {
                var targetPosition = position;

                // We need to find the way this string is now 'split', and leave the 'remainder' up to another call of InsertString.
                var passedWeights = stringWeight.TakeWhile(val => (targetPosition -= val) >= 0).Count();

                /* Warning: here, a position of 3 generates a targetPosition of -5 after noticing a weight 8. The position it needs to
                 *  go into is 3. But had it passed over a weight of 2, the targetposition would be '1' for the /next/ unit. Which is correct.
                 *
                 * But if that had a weight of 4, it'd end up being 1-4 = -3. We need to re-add the last step, on which the evaluation failed.
                 */
                if (targetPosition == 0)
                {
                    // We must place it 'between', at the beginning, or at the 'end' of a beneathList.
                    // We know how many elements in we should be... so:
                    // If count is at 0, it's an insert.
                    // If count is equal to stringWeight.Count, append at end.
                    // Otherwise, pass the new targetPosition to insert into the String.
                    beneathList.Insert(passedWeights, markupStringArg);
                    stringWeight.Insert(passedWeights, markupStringArg.Weight());
                }
                else
                {
                    // This is the adjustment for the 'last step reduction' error.
                    targetPosition += stringWeight[passedWeights];

                    beneathList[passedWeights].Insert(markupStringArg, targetPosition);
                    stringWeight[passedWeights] += markupStringArg.Weight();

                    if (!beneathList[passedWeights].MyMarkup.IsOnlyInherit())
                    {
                        return(this);
                    }

                    // If the below is now an empty (OnlyInherit) Markup, we can 'pull it up'.
                    // That is to say, we can put its individual beneathLists in the position where we had our old one.
                    // If the item below is not an empty (OnlyInherit) Markup, then it wasn't the item below that we did
                    // the final insert into.
                    var reference = beneathList[passedWeights];
                    beneathList.RemoveAt(passedWeights);
                    stringWeight.RemoveAt(passedWeights);
                    beneathList.InsertRange(passedWeights, reference.beneathList);
                    stringWeight.InsertRange(passedWeights, reference.stringWeight);
                }
            }

            return(this);
        }