private TextSplitted getTextSplitted(FoundAcronym acronym, string text) { TextSplitted ret = new TextSplitted(); string leftText = StringTreatment.NormalizeText(text.Substring(0, acronym.Index)); MatchCollection newLines = Regex.Matches(leftText, Environment.NewLine, RegexOptions.RightToLeft); if (newLines.Count == 0) { ret.MainParagraph = leftText.Trim(); } else { ret.MainParagraph = leftText.Substring(newLines[0].Index).Trim(); leftText = leftText.Substring(0, newLines[0].Index); for (int i = 1; i <= _paragraphsAround && i <= newLines.Count; i++) { string nextParagraph = leftText.Substring(i < newLines.Count ? newLines[i].Index : 0); if (!string.IsNullOrWhiteSpace(nextParagraph)) { ret.LeftParagraphs.Add(nextParagraph.Trim()); } if (i < newLines.Count) { leftText = leftText.Substring(0, newLines[i].Index); } } } ret.MainParagraph += " "; // +acronym.Caption + " "; string rightText = StringTreatment.NormalizeText(text.Substring(acronym.Index + acronym.Caption.Length)); newLines = Regex.Matches(rightText, Environment.NewLine); if (newLines.Count == 0) { ret.MainParagraph += rightText.Trim(); } else { ret.MainParagraph += rightText.Substring(0, newLines[0].Index).Trim(); int indexOfLastLineBreak = newLines[0].Index; for (int i = 1; i <= _paragraphsAround && i <= newLines.Count; i++) { string nextParagraph = rightText.Substring(indexOfLastLineBreak, i < newLines.Count ? (newLines[i].Index - indexOfLastLineBreak) : rightText.Length - indexOfLastLineBreak); if (!string.IsNullOrWhiteSpace(nextParagraph)) { ret.RightParagraphs.Add(nextParagraph.Trim()); } if (i < newLines.Count) { indexOfLastLineBreak = newLines[i].Index; } } } return(ret); }
public override IEnumerable <FoundMatchBase> FindMatches(ResourceInformation information) { information.Content = StringTreatment.NormalizeText(information.Content); return(FindMatches(information.Content)); }