示例#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 DocOp Delete(UInt16 _uiSite, int _iPosition)
        {
            DocOp docOp = new DocOp();

            docOp.Type     = DocOpType.Delete;
            docOp.Site     = _uiSite;
            docOp.Position = _iPosition;

            return(docOp);
        }
示例#3
0
        //----------------------------------------------------------------------
        public static DocOp Insert(UInt16 _uiSite, int _iPosition, char _char)
        {
            DocOp docOp = new DocOp();

            docOp.Type     = DocOpType.Insert;
            docOp.Site     = _uiSite;
            docOp.Position = _iPosition;
            docOp.Char     = _char;

            return(docOp);
        }
示例#4
0
        public static List <DocOp> Delete(UInt16 _uiSite, int _iPosition, int _iCount)
        {
            List <DocOp> lOps = new List <DocOp>();

            for (int i = 0; i < _iCount; i++)
            {
                DocOp deleteOp = DocOp.Delete(_uiSite, _iPosition);
                lOps.Add(deleteOp);
            }

            return(lOps);
        }
示例#5
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);
        }
示例#6
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;
                }
            }
        }