private static void SplitByContains(string text, string value, StringComparison stringComparison, IList <AutoCompleteHighlightingSplitPart> parts) { int index = text.ReplaceDiacritics().IndexOf(value.ReplaceDiacritics(), stringComparison); if (index >= 0) { while (index >= 0) { if (index > 0) { var part = new AutoCompleteHighlightingSplitPart(text.Substring(0, index), false); parts.Add(part); } var matchText = text.Substring(index, value.Length); var matchPart = new AutoCompleteHighlightingSplitPart(matchText, true); parts.Add(matchPart); text = text.Substring(index + value.Length); index = text.IndexOf(value, stringComparison); } if (text.Length > 0) { var part = new AutoCompleteHighlightingSplitPart(text, false); parts.Add(part); } } else { var part = new AutoCompleteHighlightingSplitPart(text, false); parts.Add(part); } }
public static IEnumerable <AutoCompleteHighlightingSplitPart> Split(string text, string value) { List <AutoCompleteHighlightingSplitPart> parts = new List <AutoCompleteHighlightingSplitPart>(); if (string.IsNullOrEmpty(text)) { return(parts); } if (string.IsNullOrEmpty(value)) { var part = new AutoCompleteHighlightingSplitPart(text, false); parts.Add(part); return(parts); } SplitByContains(text, value, StringComparison.CurrentCultureIgnoreCase, parts); return(parts); }
private static void SplitByContains(string text, string value, StringComparison stringComparison, IList<AutoCompleteHighlightingSplitPart> parts) { int index = text.ReplaceDiacritics().IndexOf(value.ReplaceDiacritics(), stringComparison); if (index >= 0) { while (index >= 0) { if (index > 0) { var part = new AutoCompleteHighlightingSplitPart(text.Substring(0, index), false); parts.Add(part); } var matchText = text.Substring(index, value.Length); var matchPart = new AutoCompleteHighlightingSplitPart(matchText, true); parts.Add(matchPart); text = text.Substring(index + value.Length); index = text.IndexOf(value, stringComparison); } if (text.Length > 0) { var part = new AutoCompleteHighlightingSplitPart(text, false); parts.Add(part); } } else { var part = new AutoCompleteHighlightingSplitPart(text, false); parts.Add(part); } }
public static IEnumerable<AutoCompleteHighlightingSplitPart> Split(string text, string value) { List<AutoCompleteHighlightingSplitPart> parts = new List<AutoCompleteHighlightingSplitPart>(); if (string.IsNullOrEmpty(text)) { return parts; } if (string.IsNullOrEmpty(value)) { var part = new AutoCompleteHighlightingSplitPart(text, false); parts.Add(part); return parts; } SplitByContains(text, value, StringComparison.CurrentCultureIgnoreCase, parts); return parts; }