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); }
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); }
//---------------------------------------------------------------------- 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; } } }