Esempio n. 1
0
        private static IEnumerable <OtChange> Normalize(IEnumerable <OtChange> changes)
        {
            var      result = new List <OtChange>();
            OtChange prev   = null;

            foreach (var curr in changes)
            {
                if (curr.IsId())
                {
                    continue;
                }

                if (prev is Retain && curr is Retain)
                {
                    prev = new Retain(((Retain)prev).Offset + ((Retain)curr).Offset);
                }
                else if (prev is InsertText && curr is InsertText)
                {
                    prev = new InsertText(((InsertText)prev).Text + ((InsertText)curr).Text);
                }
                else if (prev is DeleteText && curr is DeleteText)
                {
                    prev = new DeleteText(((DeleteText)prev).Text + ((DeleteText)curr).Text);
                }
                else
                {
                    if (prev != null)
                    {
                        result.Add(prev);
                    }
                    prev = curr;
                }
            }

            if (prev != null)
            {
                result.Add(prev);
            }
            if (result.Count == 0)
            {
                result.Add(new Retain(0));
            }

            return(result);
        }
Esempio n. 2
0
 protected bool Equals(Retain other)
 {
     return(Offset == other.Offset);
 }