CK.Text.StringMatcher.TryMatchText C# (CSharp) Method

TryMatchText() public method

Matches a text without setting an error if match fails.
public TryMatchText ( string text, System.StringComparison comparisonType = StringComparison.OrdinalIgnoreCase ) : bool
text string The string that must match. Can not be null nor empty.
comparisonType System.StringComparison Specifies the culture, case, and sort rules.
return bool
        public bool TryMatchText( string text, StringComparison comparisonType = StringComparison.OrdinalIgnoreCase )
        {
            if( string.IsNullOrEmpty( text ) ) throw new ArgumentException( nameof( text ) );
            int len = text.Length;
            return !IsEnd
                    && len <= _length
                    && string.Compare( _text, _startIndex, text, 0, len, comparisonType ) == 0
                ? UncheckedMove( len )
                : false;
        }

Usage Example

        /// <summary>
        /// Matches a JSON value: a "string", null, a number (double value), true or false.
        /// Not error is set if match fails.
        /// </summary>
        /// <param name="this">This <see cref="StringMatcher"/>.</param>
        /// <param name="value">The parsed value. Can be null.</param>
        /// <returns>True if a JSON value has been matched, false otherwise.</returns>
        public static bool TryMatchJSONValue(this StringMatcher @this, out object value)
        {
            string s;

            if (@this.TryMatchJSONQuotedString(out s, true))
            {
                value = s;
                return(true);
            }
            double d;

            if (@this.TryMatchDoubleValue(out d))
            {
                value = d;
                return(true);
            }
            if (@this.TryMatchText("true"))
            {
                value = true;
                return(true);
            }
            if (@this.TryMatchText("false"))
            {
                value = false;
                return(true);
            }
            value = null;
            return(false);
        }
All Usage Examples Of CK.Text.StringMatcher::TryMatchText