/// <summary> /// Добавление дочернего контента /// </summary> /// <param name="newChild">дочерний контент</param> public void AddChild(ChildContent newChild) { newChild.StartPosition -= TextStartPosition; int index = -1; int childrenLength = 0; for (index = 0; index < Children.Count; ++index) { ChildContent child = Children[index]; if (child.IsContain(newChild)) { child.AddChild(newChild); return; } else if (newChild.IsContain(child)) { newChild.AddChild(child); Children.RemoveAt(index); --index; continue; } else if (newChild.StartPosition + newChild.Length < child.StartPosition) { break; } childrenLength += child.GetFullText().Length; } newChild.PreviousSymbol = TextValue.CharOrDefault(newChild.StartPosition - childrenLength - 1); newChild.NextSymbol = TextValue.CharOrDefault(newChild.StartPosition - childrenLength); Children.Insert(index, newChild); }
/// <summary> /// Удаление дочернего контента /// </summary> /// <param name="sentenceInfo">информация о корректируемом предложении</param> /// <param name="contentInfo">информация о корректируемом контенте</param> /// <param name="contentIndex">индекс удаляемого контента</param> private void RemoveChildContent(CorrectedSentenceInfo sentenceInfo, CorrectedContentInfo contentInfo, int contentIndex) { ChildContent content = Children[contentIndex]; string contentText = content.GetFullText(); int startPosition = GetContentCorrectedStart(contentIndex) - (sentenceInfo.SentenceItems.Sentence.GetFullStartPosition() + contentInfo.RemovedContentLength); sentenceInfo.NewSentenceText.Insert(startPosition, contentText); foreach (var entity in content.Entities) { AddEntity(entity, -(startPosition + content.TextStartPosition - content.StartPosition)); } Children.RemoveAt(contentIndex); ++contentInfo.RemovedContentCount; contentInfo.RemovedContentLength += contentText.Length; }