public FCLRegex(IRegexFactory factory, string pattern, ReOptions options) { this.factory = factory; this.options = options; this.pattern = pattern; var opts = RENS.RegexOptions.Compiled | RENS.RegexOptions.ExplicitCapture; if ((options & ReOptions.AllowPatternWhitespaces) == 0) { opts |= RENS.RegexOptions.IgnorePatternWhitespace; } if ((options & RegularExpressions.ReOptions.Multiline) != 0) { opts |= RENS.RegexOptions.Multiline; } if ((options & RegularExpressions.ReOptions.Singleline) != 0) { opts |= RENS.RegexOptions.Singleline; } if ((options & RegularExpressions.ReOptions.RightToLeft) != 0) { opts |= RENS.RegexOptions.RightToLeft; } if ((options & RegularExpressions.ReOptions.IgnoreCase) != 0) { opts |= RENS.RegexOptions.IgnoreCase; } this.impl = new RENS.Regex(pattern, opts); this.groupNames = impl.GetGroupNames().ToArray(); }
public LoadedRegex Clone(ReOptions optionsToAdd = ReOptions.None) { LoadedRegex ret; ret.Regex = RegularExpressions.RegexUtils.CloneRegex(this.Regex, optionsToAdd); ret.SuffersFromPartialMatchProblem = this.SuffersFromPartialMatchProblem; return(ret); }
public static IRegex CloneRegex(IRegex re, ReOptions optionsToAdd = ReOptions.None) { if (re != null) { return(re.Factory.Create(re.Pattern, re.Options | optionsToAdd)); } else { return(null); } }
/// <summary> /// Preprocesses the search options and returns an opaque object /// that holds the state needed to efficiently search many times using the search options. /// Different threads can not share the returned state object. Each thread has to call this method. /// </summary> public static SearchState BeginSearch(this Options options, IRegexFactory regexFactory, bool timeboxedMatching = false) { SearchState ret = new SearchState() { options = options, contentTypeMask = MessageFlag.ContentTypeMask & options.ContentTypes, }; if (!string.IsNullOrEmpty(options.Template)) { if (options.Regexp || useRegexsForSimpleTemplates) { ReOptions reOpts = ReOptions.AllowPatternWhitespaces; if (!options.MatchCase) { reOpts |= ReOptions.IgnoreCase; } if (options.ReverseSearch) { reOpts |= ReOptions.RightToLeft; } if (timeboxedMatching) { reOpts |= ReOptions.Timeboxed; } try { ret.re = regexFactory.Create( options.Regexp ? options.Template : System.Text.RegularExpressions.Regex.Escape(options.Template), reOpts); } catch (Exception) { throw new TemplateException(); } } else { if (!options.MatchCase) { ret.options.Template = ret.options.Template.ToLower(); } } } return(ret); }
/// <summary> /// Preprocesses the search options and returns an opaque object /// that holds the state needed to efficiently search many times using the search options. /// Different threads can not share the returned state object. Each thread has to call this method. /// </summary> public SearchState BeginSearch() { SearchState ret = new SearchState() { options = this, contentTypeMask = MessageFlag.ContentTypeMask & ContentTypes, }; if (!string.IsNullOrEmpty(Template)) { if (Regexp || useRegexsForSimpleTemplates) { ReOptions reOpts = ReOptions.AllowPatternWhitespaces; if (!MatchCase) { reOpts |= ReOptions.IgnoreCase; } if (ReverseSearch) { reOpts |= ReOptions.RightToLeft; } try { ret.re = RegexFactory.Instance.Create( Regexp ? Template : System.Text.RegularExpressions.Regex.Escape(Template), reOpts); } catch (Exception) { throw new TemplateException(); } } else { if (!MatchCase) { ret.options.Template = ret.options.Template.ToLower(); } } } return(ret); }
protected static LoadedRegex ReadRe(XElement root, string name, ReOptions opts) { LoadedRegex ret = new LoadedRegex(); var n = root.Element(name); if (n == null) { return(ret); } string pattern = n.Value; if (string.IsNullOrEmpty(pattern)) { return(ret); } ret.Regex = RegexFactory.Instance.Create(pattern, opts); XAttribute attr; ret.SuffersFromPartialMatchProblem = (attr = n.Attribute("suffers-from-partial-match-problem")) != null && attr.Value == "yes"; return(ret); }
public IRegex Create(string pattern, ReOptions options) { return(new FCLRegex(this, pattern, options)); }
protected static LoadedRegex CloneRegex(LoadedRegex re, ReOptions optionsToAdd = ReOptions.None) { return(re.Clone(optionsToAdd)); }