//--------------------------------------------------------------------------- private List <TextSegment> ParseToSegments() { List <TextSegment> segments = new List <TextSegment>(); MatchCollection matches = Regex.Matches(Text, "<[A-Za-z/]+>"); Stack <Match> open = new Stack <Match>(); int index = 0; foreach (Match match in matches) { if (match.Value.Contains('/')) { if (AssertManager.Get().Show(open.Count > 0 && IsClosingTag(open.Peek().Value, match.Value), "Tags in TextComponent don't match.")) { return(new List <TextSegment>() { new TextSegment(Text) }); } Match tag = open.Pop(); if (match.Index > index) { segments.Add(TextSegment.Parse(Text.Substring(index, match.Index - index), tag.Value)); } index = match.Index + match.Length; } else { if (match.Index > index) { if (open.Count > 0) { segments.Add(TextSegment.Parse(Text.Substring(index, match.Index - index), open.Peek().Value)); } else { segments.Add(new TextSegment(Text.Substring(index, match.Index - index))); } } open.Push(match); index = match.Index + match.Length; } } if (index < Text.Length) { segments.Add(new TextSegment(Text.Substring(index))); } return(segments); }