示例#1
0
        public static DocTransform Deserialize(dynamic _reader)
        {
            DocTransform transform = new DocTransform(_reader.ReadInt32());

            int iOpCount = _reader.ReadInt32();

            List <DocOp> lOps = new List <DocOp>();

            for (int iOp = 0; iOp < iOpCount; iOp++)
            {
                DocOpType opType = (DocOpType)_reader.ReadByte();

                switch (opType)
                {
                case DocOpType.Insert:
                    lOps.Add(DocOp.Insert(_reader.ReadUInt16(), _reader.ReadInt32(), (char)_reader.ReadUInt16()));
                    break;

                case DocOpType.Delete:
                    lOps.Add(DocOp.Delete(_reader.ReadUInt16(), _reader.ReadInt32()));
                    break;
                }
            }

            transform.Append(lOps);

            return(transform);
        }
示例#2
0
        //----------------------------------------------------------------------
        public static List <DocOp> Insert(UInt16 _uiSite, int _iPosition, string _strValue)
        {
            List <DocOp> lOps = new List <DocOp>();

            for (int i = _strValue.Length - 1; i >= 0; i--)
            {
                DocOp insertOp = DocOp.Insert(_uiSite, _iPosition, _strValue[i]);
                lOps.Add(insertOp);
            }

            return(lOps);
        }
示例#3
0
        //----------------------------------------------------------------------
        void TransformOp(DocOp _refOp)
        {
            for (int iOp = 0; iOp < mlOps.Count; iOp++)
            {
                DocOp op = mlOps[iOp];

                // Based on http://www3.ntu.edu.sg/home/czsun/projects/otfaq/#_Toc308616441
                switch (op.Type)
                {
                case DocOpType.Insert:

                    switch (_refOp.Type)
                    {
                    case DocOpType.Insert:
                        if (op.Position < _refOp.Position || (op.Position == _refOp.Position && op.Site > _refOp.Site))
                        {
                            continue;
                        }
                        else
                        {
                            mlOps[iOp] = DocOp.Insert(op.Site, op.Position + 1, op.Char);
                        }
                        break;

                    case DocOpType.Delete:
                        if (op.Position <= _refOp.Position)
                        {
                            continue;
                        }
                        else
                        {
                            mlOps[iOp] = DocOp.Insert(op.Site, op.Position - 1, op.Char);
                        }
                        break;
                    }

                    break;

                case DocOpType.Delete:

                    switch (_refOp.Type)
                    {
                    case DocOpType.Insert:
                        if (op.Position < _refOp.Position)
                        {
                            continue;
                        }
                        else
                        {
                            mlOps[iOp] = DocOp.Delete(op.Site, op.Position + 1);
                        }
                        break;

                    case DocOpType.Delete:
                        if (op.Position < _refOp.Position)
                        {
                            continue;
                        }
                        else
                        if (op.Position > _refOp.Position)
                        {
                            mlOps[iOp] = DocOp.Delete(op.Site, op.Position - 1);
                        }
                        else
                        {
                            mlOps.RemoveAt(iOp);
                            iOp--;
                        }
                        break;
                    }

                    break;
                }
            }
        }