public MessagesReader( MediaBasedReaderParams readerParams, FormatInfo fmt, FieldsProcessor.IFactory fieldsProcessorFactory, IRegexFactory regexFactory, ITraceSourceFactory traceSourceFactory ) : base(readerParams.Media, fmt.BeginFinder, fmt.EndFinder, fmt.ExtensionsInitData, fmt.TextStreamPositioningParams, readerParams.Flags, readerParams.SettingsAccessor) { if (readerParams.Threads == null) { throw new ArgumentNullException(nameof(readerParams) + ".Threads"); } this.threads = readerParams.Threads; this.traceSourceFactory = traceSourceFactory; this.regexFactory = regexFactory; this.fmtInfo = fmt; this.fieldsProcessorFactory = fieldsProcessorFactory; this.trace = traceSourceFactory.CreateTraceSource("LogSource", string.Format("{0}.r{1:x4}", readerParams.ParentLoggingPrefix, Hashing.GetShortHashCode(this.GetHashCode()))); base.Extensions.AttachExtensions(); this.isBodySingleFieldExpression = new Lazy <bool>(() => { return(CreateNewFieldsProcessor().IsBodySingleFieldExpression()); }); }
public NativeXMLFormatFactory(ITempFilesManager tempFiles, IRegexFactory regexFactory, ITraceSourceFactory traceSourceFactory) { this.tempFiles = tempFiles; this.regexFactory = regexFactory; this.traceSourceFactory = traceSourceFactory; this.nativeFormatInfo = XmlFormatInfo.MakeNativeFormatInfo("utf-8", null, new FormatViewOptions(), regexFactory); }
void ReverseStringSliceMatchingTest(IRegexFactory factory) { var re = factory.Create(@"f\wo", ReOptions.RightToLeft); IMatch m = null; var testString = "bar foo boo"; TestOnAllSliceVariations(testString, slice => { Action testMatch = () => { Assert.AreEqual(4, m.Index); Assert.AreEqual(3, m.Length); }; Assert.IsFalse(re.Match(slice, 0, ref m)); Assert.IsFalse(re.Match(slice, 1, ref m)); Assert.IsFalse(re.Match(slice, 4, ref m)); Assert.IsFalse(re.Match(slice, 6, ref m)); Assert.IsTrue(re.Match(slice, 7, ref m)); testMatch(); Assert.IsTrue(re.Match(slice, testString.Length, ref m)); testMatch(); }); Assert.IsFalse(re.Match(new StringSlice("foo 222", 1, 5), 5, ref m)); Assert.IsFalse(re.Match(new StringSlice("111 foo 333", 0, 6), 6, ref m)); }
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(); }
/// <summary> /// Конструктор FTP-клиента. /// </summary> /// <param name="configurationManager">Менеджер конфигурации</param> /// <param name="regexFactory">Фабрика регулярных выражений</param> public FtpClient(IApplicationConfigurationManager configurationManager, IRegexFactory regexFactory, IFileWrapper file) { UserName = configurationManager.GetSetting("ftpUserName"); Password = configurationManager.GetSetting("ftpUserPassword"); Host = configurationManager.GetSetting("ftpHost"); _regexFactory = regexFactory; _file = file; }
public WordSelection(IRegexFactory regexFactory) { isPartOfGuidRegex = regexFactory.Create( @"^[\da-f\-]{1,36}$", ReOptions.IgnoreCase); isGuidRegex = regexFactory.Create( @"^[\da-f]{8}\-[\da-f]{4}\-[\da-f]{4}\-[\da-f]{4}\-[\da-f]{12}$", ReOptions.IgnoreCase); isPartOfIPRegex = regexFactory.Create( @"^[\d\.\:]{1,21}$", ReOptions.IgnoreCase); ipRegex = regexFactory.Create( @"(?<p1>\d{1,3})\.(?<p2>\d{1,3})\.(?<p3>\d{1,3})\.(?<p4>\d{1,3})(\:(?<port>\d+))?", ReOptions.IgnoreCase); }
void CaseMatchingTest(IRegexFactory factory) { var re = factory.Create(@"B(o+)m", ReOptions.None); IMatch m = null; Assert.IsTrue(re.Match("Boooom", 0, ref m)); Assert.IsFalse(re.Match("boooom", 0, ref m)); re = factory.Create(@"B(o+)m", ReOptions.IgnoreCase); m = null; Assert.IsTrue(re.Match("Boooom", 0, ref m)); Assert.IsTrue(re.Match("boooom", 0, ref m)); }
public MessagesReader( MediaBasedReaderParams readerParams, JsonFormatInfo fmt, IRegexFactory regexFactory, ITraceSourceFactory traceSourceFactory ) : base(readerParams.Media, fmt.BeginFinder, fmt.EndFinder, fmt.ExtensionsInitData, fmt.TextStreamPositioningParams, readerParams.Flags, readerParams.SettingsAccessor) { this.formatInfo = fmt; this.threads = readerParams.Threads; this.traceSourceFactory = traceSourceFactory; this.regexFactory = regexFactory; }
public UserDefinedFormatFactory(UserDefinedFactoryParams createParams) : base(createParams) { var formatSpecificNode = createParams.FormatSpecificNode; ReadPatterns(formatSpecificNode, patterns); var boundsNodes = formatSpecificNode.Elements("bounds").Take(1); var beginFinder = BoundFinder.CreateBoundFinder(boundsNodes.Select(n => n.Element("begin")).FirstOrDefault()); var endFinder = BoundFinder.CreateBoundFinder(boundsNodes.Select(n => n.Element("end")).FirstOrDefault()); tempFilesManager = createParams.TempFilesManager; fieldsProcessorFactory = createParams.FieldsProcessorFactory; regexFactory = createParams.RegexFactory; traceSourceFactory = createParams.TraceSourceFactory; fmtInfo = new Lazy <FormatInfo>(() => { FieldsProcessor.IInitializationParams fieldsInitParams = fieldsProcessorFactory.CreateInitializationParams( formatSpecificNode.Element("fields-config"), performChecks: true); MessagesReaderExtensions.XmlInitializationParams extensionsInitData = new MessagesReaderExtensions.XmlInitializationParams( formatSpecificNode.Element("extensions")); DejitteringParams?dejitteringParams = DejitteringParams.FromConfigNode( formatSpecificNode.Element("dejitter")); TextStreamPositioningParams textStreamPositioningParams = TextStreamPositioningParams.FromConfigNode( formatSpecificNode); RotationParams rotationParams = RotationParams.FromConfigNode( formatSpecificNode.Element("rotation")); FormatInfo.FormatFlags flags = FormatInfo.FormatFlags.None; if (formatSpecificNode.Element("plain-text-search-optimization").AttributeValue("allowed") == "yes") { flags |= FormatInfo.FormatFlags.AllowPlainTextSearchOptimization; } return(new FormatInfo( ReadRe(formatSpecificNode, "head-re", ReOptions.Multiline), ReadRe(formatSpecificNode, "body-re", ReOptions.Singleline), ReadParameter(formatSpecificNode, "encoding"), fieldsInitParams, extensionsInitData, dejitteringParams, textStreamPositioningParams, flags, rotationParams, beginFinder, endFinder )); }); uiKey = ReadParameter(formatSpecificNode, "ui-key"); }
/// <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); }
public UserDefinedFormatFactory(UserDefinedFactoryParams createParams) : base(createParams) { var formatSpecificNode = createParams.FormatSpecificNode; ReadPatterns(formatSpecificNode, patterns); var boundsNodes = formatSpecificNode.Elements("bounds").Take(1); var beginFinder = BoundFinder.CreateBoundFinder(boundsNodes.Select(n => n.Element("begin")).FirstOrDefault()); var endFinder = BoundFinder.CreateBoundFinder(boundsNodes.Select(n => n.Element("end")).FirstOrDefault()); this.tempFilesManager = createParams.TempFilesManager; this.regexFactory = createParams.RegexFactory; this.traceSourceFactory = createParams.TraceSourceFactory; formatInfo = new Lazy <XmlFormatInfo>(() => { XmlDocument tmpDoc = new XmlDocument(); tmpDoc.LoadXml(formatSpecificNode.ToString()); XmlElement xsl = tmpDoc.DocumentElement.SelectSingleNode("xsl:stylesheet", nsMgr) as XmlElement; if (xsl == null) { throw new Exception("Wrong XML-based format definition: xsl:stylesheet is not defined"); } LoadedRegex head = ReadRe(formatSpecificNode, "head-re", ReOptions.Multiline); LoadedRegex body = ReadRe(formatSpecificNode, "body-re", ReOptions.Singleline); string encoding = ReadParameter(formatSpecificNode, "encoding"); MessagesReaderExtensions.XmlInitializationParams extensionsInitData = new MessagesReaderExtensions.XmlInitializationParams(formatSpecificNode.Element("extensions")); DejitteringParams?dejitteringParams = DejitteringParams.FromConfigNode( formatSpecificNode.Element("dejitter")); TextStreamPositioningParams textStreamPositioningParams = TextStreamPositioningParams.FromConfigNode( formatSpecificNode); return(new XmlFormatInfo(xsl, head, body, beginFinder, endFinder, encoding, extensionsInitData, textStreamPositioningParams, dejitteringParams, viewOptions)); }); uiKey = ReadParameter(formatSpecificNode, "ui-key"); }
void BasicReTest(IRegexFactory factory) { var re = factory.Create(@"^\s+(?<test>\d{2})", ReOptions.None); IMatch m = null; string buf = " 34 56"; Assert.IsTrue(re.Match(buf, 0, 10, ref m)); Assert.AreEqual(0, m.Index); Assert.AreEqual(5, m.Length); Assert.AreEqual(2, m.Groups.Length); Assert.AreEqual(3, m.Groups[1].Index); Assert.AreEqual(2, m.Groups[1].Length); Assert.IsTrue(re.Match(buf, 5, 5, ref m)); Assert.AreEqual(8, m.Groups[1].Index); Assert.AreEqual(2, m.Groups[1].Length); Assert.IsFalse(re.Match(buf, 9, 1, ref m)); }
public MessagesReader( MediaBasedReaderParams readerParams, XmlFormatInfo fmt, IRegexFactory regexFactory, ITraceSourceFactory traceSourceFactory ) : base(readerParams.Media, fmt.BeginFinder, fmt.EndFinder, fmt.ExtensionsInitData, fmt.TextStreamPositioningParams, readerParams.Flags, readerParams.SettingsAccessor) { this.formatInfo = fmt; this.threads = readerParams.Threads; this.traceSourceFactory = traceSourceFactory; this.regexFactory = regexFactory; this.transformArgs = new XsltArgumentList(); this.xslExt = new LogJointXSLExtension(); transformArgs.AddExtensionObject(Properties.LogJointNS, this.xslExt); foreach (MessagesReaderExtensions.ExtensionData extInfo in this.Extensions.Items) { transformArgs.AddExtensionObject(Properties.LogJointNS + extInfo.Name, extInfo.Instance()); } }
public UserDefinedFormatFactory(UserDefinedFactoryParams createParams) : base(createParams) { var formatSpecificNode = createParams.FormatSpecificNode; ReadPatterns(formatSpecificNode, patterns); var boundsNodes = formatSpecificNode.Elements("bounds").Take(1); var beginFinder = BoundFinder.CreateBoundFinder(boundsNodes.Select(n => n.Element("begin")).FirstOrDefault()); var endFinder = BoundFinder.CreateBoundFinder(boundsNodes.Select(n => n.Element("end")).FirstOrDefault()); this.tempFilesManager = createParams.TempFilesManager; this.regexFactory = createParams.RegexFactory; this.traceSourceFactory = createParams.TraceSourceFactory; formatInfo = new Lazy <JsonFormatInfo>(() => { string transform = ReadParameter(formatSpecificNode, "transform"); if (transform == null) { throw new Exception("Wrong JSON format definition: transform is not defined"); } LoadedRegex head = ReadRe(formatSpecificNode, "head-re", ReOptions.Multiline); LoadedRegex body = ReadRe(formatSpecificNode, "body-re", ReOptions.Singleline); string encoding = ReadParameter(formatSpecificNode, "encoding"); DejitteringParams?dejitteringParams = DejitteringParams.FromConfigNode( formatSpecificNode.Element("dejitter")); TextStreamPositioningParams textStreamPositioningParams = TextStreamPositioningParams.FromConfigNode( formatSpecificNode); return(new JsonFormatInfo(transform, head, body, beginFinder, endFinder, encoding, textStreamPositioningParams, dejitteringParams, viewOptions)); }); }
public static XmlFormatInfo MakeNativeFormatInfo(string encoding, DejitteringParams?dejitteringParams, FormatViewOptions viewOptions, IRegexFactory regexFactory) { LoadedRegex headRe; headRe.Regex = regexFactory.Create(@"\<\s*(m|f|ef)\s", ReOptions.None); headRe.SuffersFromPartialMatchProblem = false; return(new XmlFormatInfo( null, headRe, new LoadedRegex(), null, null, encoding, null, TextStreamPositioningParams.Default, dejitteringParams, viewOptions)); }
public UnixFtpProcessor(IRegexFactory regexFactory) { _regexFactory = regexFactory; }