public GroupsFormat AddGroup(string groupName, string regexString, Color color, FontStyle style, bool caseSensitive = true) { if (groupName == UNGROUPED || UNGROUPED_OTHER == "") { throw new Exception("Reserved group name."); } if (GroupsFormats.Exists(g => g.GroupName == groupName)) { throw new Exception("Group name repeated."); } var group = new GroupsFormat(groupName, regexString, color, style, caseSensitive); GroupsFormats.Add(group); return(group); }
private void AppendText(Text formattedText, string text, GroupsFormat format) { if (format.KeywordsFormats.Any()) { var mtokens = grupedRegex.Matches(text); foreach (Match match in mtokens) { if (match.Groups[NEW_LINE].Success) { //AppendString(formattedText, format, match.Value); formattedText.Lines.Add(new TextLine()); } else if (format.CaseSensitive && match.Groups[TOKENS_GROUP].Success && format.KeywordsFormats.Any(gk => gk.Keywords.Contains(match.Value))) { var keyword = format.KeywordsFormats.First(gk => gk.Keywords.Contains(match.Value)); AppendString(formattedText, keyword, match.Value); } else if (!format.CaseSensitive && match.Groups[TOKENS_GROUP].Success && format.KeywordsFormats.Any(gk => gk.Keywords.Any(kw => kw.ToLower() == match.Value.ToLower()))) { var keyword = format.KeywordsFormats.First(gk => gk.Keywords.Any(kw => kw.ToLower() == match.Value.ToLower())); AppendString(formattedText, keyword, match.Value); } else { AppendString(formattedText, format, match.Value); } } } else { var mtokens = ungrupedRegex.Matches(text); foreach (Match match in mtokens) { if (match.Groups[NEW_LINE].Success) { //AppendString(formattedText, format, match.Value); formattedText.Lines.Add(new TextLine()); } else { AppendString(formattedText, format, match.Value); } } } }