コード例 #1
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;
        }
コード例 #2
0
        /// <summary>
        /// Matches Int32 values that must not start with '0' ('0' is valid but '0d', where d is any digit, is not).
        /// A signed integer starts with a '-'. '-0' is valid but '-0d' (where d is any digit) is not.
        /// If the value is to big for an Int32, it fails.
        /// </summary>
        /// <param name="this">This <see cref="StringMatcher"/>.</param>
        /// <param name="i">The result integer. 0 on failure.</param>
        /// <param name="minValue">Optional minimal value.</param>
        /// <param name="maxValue">Optional maximal value.</param>
        /// <returns><c>true</c> when matched, <c>false</c> otherwise.</returns>
        public static bool MatchInt32( this StringMatcher @this, out int i, int minValue = int.MinValue, int maxValue = int.MaxValue )
        {
            i = 0;
            int savedIndex = @this.StartIndex;
            long value = 0;
            bool signed;
            if( @this.IsEnd ) return @this.SetError();
            if( (signed = @this.TryMatchChar( '-' )) && @this.IsEnd ) return @this.BackwardAddError( savedIndex );

            char c;
            if( @this.TryMatchChar( '0' ) )
            {
                if( [email protected] && (c = @this.Head) >= '0' && c <= '9' ) return @this.BackwardAddError( savedIndex, "0...9" );
                return @this.SetSuccess();
            }
            unchecked
            {
                long iMax = Int32.MaxValue;
                if( signed ) iMax = iMax + 1;
                while( [email protected] && (c = @this.Head) >= '0' && c <= '9' )
                {
                    value = value * 10 + (c - '0');
                    if( value > iMax ) break;
                    @this.UncheckedMove( 1 );
                }
            }
            if( @this.StartIndex > savedIndex )
            {
                if( signed ) value = -value;
                if( value < (long)minValue || value > (long)maxValue )
                {
                    return @this.BackwardAddError( savedIndex, String.Format( CultureInfo.InvariantCulture, "value between {0} and {1}", minValue, maxValue ) );
                }
                i = (int)value;
                return @this.SetSuccess();
            }
            return @this.SetError();
        }
コード例 #3
0
 /// <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 );
 }