/// <summary> /// Matches a <see cref="DateTimeStamp"/>. /// </summary> /// <param name="this">This <see cref="StringMatcher"/>.</param> /// <param name="time">Resulting time stamp on successful match; <see cref="DateTimeStamp.Unknown"/> otherwise.</param> /// <returns>True if the time stamp has been matched.</returns> static public bool MatchDateTimeStamp(this StringMatcher @this, out DateTimeStamp time) { time = DateTimeStamp.Unknown; int savedIndex = @this.StartIndex; DateTime t; if ([email protected](out t)) { return(@this.SetError()); } byte uniquifier = 0; if (@this.MatchChar('(')) { int unique; if ([email protected](out unique, 0, 255) || [email protected](')')) { return(@this.BackwardAddError(savedIndex)); } uniquifier = (byte)unique; } time = new DateTimeStamp(t, uniquifier); return(@this.Forward(0)); }
/// <summary> /// Matches a <see cref="LogFilter"/>: it can be a predefined filter as ("Undefined", "Debug", "Verbose", etc.) /// or as {GroupLogLevelFilter,LineLogLevelFilter} pairs like "{None,None}", "{Error,Trace}". /// </summary> /// <param name="m">This <see cref="StringMatcher"/>.</param> /// <param name="f">Resulting filter.</param> /// <returns>True on success, false on error.</returns> public static bool MatchLogFilter(this StringMatcher m, out LogFilter f) { f = LogFilter.Undefined; if (!m.MatchText("Undefined")) { if (m.MatchText("Debug")) { f = LogFilter.Debug; } else if (m.MatchText("Verbose")) { f = LogFilter.Verbose; } else if (m.MatchText("Monitor")) { f = LogFilter.Monitor; } else if (m.MatchText("Terse")) { f = LogFilter.Terse; } else if (m.MatchText("Release")) { f = LogFilter.Release; } else if (m.MatchText("Off")) { f = LogFilter.Off; } else if (m.MatchText("Invalid")) { f = LogFilter.Invalid; } else { int savedIndex = m.StartIndex; if (!m.MatchChar('{')) { return(m.BackwardAddError(savedIndex)); } LogLevelFilter group, line; m.MatchWhiteSpaces(); if (!m.MatchLogLevelFilter(out group)) { return(m.BackwardAddError(savedIndex)); } m.MatchWhiteSpaces(); if (!m.MatchChar(',')) { return(m.BackwardAddError(savedIndex)); } m.MatchWhiteSpaces(); if (!m.MatchLogLevelFilter(out line)) { return(m.BackwardAddError(savedIndex)); } m.MatchWhiteSpaces(); if (!m.MatchChar('}')) { return(m.BackwardAddError(savedIndex)); } f = new LogFilter(group, line); } } return(true); }