Beispiel #1
0
        private static int UpdatePossibleOverlaps(
            Dictionary <TextFormattingRule, ICollection <Position> > dict,
            List <WrappedFormat> possibleOverlaps,
            int totalShift,
            TextFormattingRule rule,
            Position toProcess)
        {
            Func <Position, WrappedFormat, bool> toRemovePredicate = (pos2, outside) => outside.OriginalPosition.GetOverlap(pos2) == Position.OverlapType.None;
            IEnumerable <WrappedFormat>          toRemove          = from p in possibleOverlaps where toRemovePredicate(toProcess, p) select p;

            foreach (var item in toRemove.ToList())
            {
                totalShift += item.Rule.TotalLength;
                FixDict(dict, item);
                possibleOverlaps.Remove(item);
            }

            //TODO: Extracting this snippet back would remove the rule variable.
            foreach (var item in possibleOverlaps)
            {
                item.AddRule(rule, item.OriginalPosition.GetOverlap(toProcess));
            }

            return(totalShift);
        }
Beispiel #2
0
        /// <summary>
        /// Returns all the positions of an available for a formatting rule, or an empty collection if nothing exists.
        /// </summary>
        /// <param name="rule">The formatting rule to look for.</param>
        /// <returns></returns>
        private IEnumerable <Position> IfFound(TextFormattingRule rule)
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }

            return(Positions.ContainsKey(rule) ? Positions[rule] : new List <Position>());
        }
Beispiel #3
0
        public void IncrementPosition(Position p, TextFormattingRule rule)
        {
            if (p.Start < previousStart)
            {
                throw new ArgumentException("The supplied string position starts before the end of the processed and finalised data. Most likely caused by passing an unsorted collection to the state machine.");
            }


            if (p.Start > previousStart)
            {
                var toApply = from r in todo where r.Position.Start <= p.Start orderby r.Position.Start ascending select r;


                int currentStart = previousStart;
                foreach (var r in toApply)
                {
                    if (r.Position.Start > currentStart)
                    {
                        builder.Append(value.Substring(currentStart, r.Position.Start - currentStart));
                    }
                    currentStart = r.Position.Start;

                    builder.Append(r.Value);
                }

                //TODO: Add rest of string.
                builder.Append(value.Substring(currentStart, p.Start - currentStart));

                previousStart = p.Start;

                foreach (var pp in toApply)
                {
                    todo.Remove(pp);
                }
            }


            var rules = rule.UnProcess(value, p);

            var toProcess = from r in rules where r.Position.Start == p.Start select r;

            foreach (var r in toProcess)
            {
                builder.Append(r.Value);
            }

            //The range is inserted at 0 to keep the ordering of the tags if the position is the same,
            //for example; <u><b> should be matched to </b></u>
            todo.InsertRange(0, rules.Except(toProcess));
        }
Beispiel #4
0
 public replacement(Position p, TextFormattingRule rule)
 {
     this.p    = p;
     this.rule = rule;
 }