private static bool CalculateLikeOperator( string x, string y, StatElementType xType, StatElementType yType ) { if ( yType == StatElementType.Constant ) { int startIndex = 0; int endIndex; StringBuilder patten = new StringBuilder (); Regex pattenRegex = new Regex ( @"\[(\S|\s)*]" ); Match pattenMatch = pattenRegex.Match ( y ); while ( pattenMatch.Success ) { endIndex = pattenMatch.Index; patten.Append ( y.Substring ( startIndex, endIndex - startIndex ).Replace ( "%", @"\w*" ).Replace ( "_", @"\w" ) ); patten.Append ( pattenMatch.Value ); startIndex = pattenMatch.Index + pattenMatch.Length; pattenMatch = pattenMatch.NextMatch (); } endIndex = y.Length; if ( startIndex < endIndex ) { patten.Append ( y.Substring ( startIndex, endIndex - startIndex ).Replace ( "%", @"\w*" ).Replace ( "_", @"\w" ) ); } patten.Insert ( 0, '^' ); patten.Append ( '$' ); Regex regex = new Regex ( patten.ToString () ); return regex.IsMatch ( x ); } else { throw new Exception ( "Invalid Statement" ); } }
private StatElement CreateElement( StatElementType type ) { if ( _currentElement.Length > 0 ) { StatElement element = new StatElement (); if ( type == StatElementType.Variable ) { switch ( _currentElement.ToString ().ToLower () ) { case "true": element.Type = StatElementType.Constant; element.Value = true; break; case "false": element.Type = StatElementType.Constant; element.Value = false; break; case "like": element.Type = StatElementType.Operator; element.Value = Operator.Like; break; case "null": element.Type = StatElementType.Constant; element.Value = "null"; break; default: element.Type = StatElementType.Variable; element.Value = _currentElement.ToString (); break; } } else if ( type == StatElementType.Operator ) { element.Type = StatElementType.Operator; element.Value = GetOperatorByString ( _currentElement.ToString () ); } else { if ( _currentElement[0] != '\'' || _currentElement[_currentElement.Length - 1] != '\'' ) { try { double.Parse ( _currentElement.ToString () ); } catch { throw new Exception ( string.Format ( "Invalid Vairable:{0}", _currentElement.ToString () ) ); } } element.Type = StatElementType.Constant; element.Value = _currentElement.ToString (); } _currentElement.Remove ( 0, _currentElement.Length ); return element; } else { return null; } }