internal static bool Parse(Parser.ParseContext context) { if (ElementBinaryOperator.ParseBinary(context)) { return(true); } else if (ElementUnitaryOperator.ParseUnitary(context)) { return(true); } else if (ElementDot.ParseDot(context)) { return(true); } else if (ElementFunction.ParseFunction(context)) { return(true); } return(false); }
internal static bool ParseFunction(Parser.ParseContext context) { char c = context.Expression[context.TokenPosition]; int offset = 0; string subStr; OperatorType operationType = OperatorType.None; TokenType lastTokenType = context.LastTokenType; switch (c) { case 'e': subStr = context.Expression.Substring(context.TokenPosition, Math.Min(6, context.Expression.Length - context.TokenPosition)); if (subStr.Equals("empty ") || subStr.Equals("empty(")) { offset = 4; operationType = OperatorType.Empty; break; } return(false); case 't': subStr = context.Expression.Substring(context.TokenPosition, Math.Min(9, context.Expression.Length - context.TokenPosition)); if (subStr == "toNumber " || subStr == "toNumber(") { offset = 7; operationType = OperatorType.ToNumber; break; } else if (subStr == "toString " || subStr == "toString(") { offset = 7; operationType = OperatorType.ToString; break; } subStr = context.Expression.Substring(context.TokenPosition, Math.Min(10, context.Expression.Length - context.TokenPosition)); if (subStr == "toBoolean " || subStr == "toBoolean(") { offset = 8; operationType = OperatorType.ToBoolean; break; } return(false); case 'm': subStr = context.Expression.Substring(context.TokenPosition, Math.Min(10, context.Expression.Length - context.TokenPosition)); if (subStr == "mathRound " || subStr == "mathRound(") { offset = 8; operationType = OperatorType.MathRound; break; } else if (subStr == "mathFloor " || subStr == "mathFloor(") { offset = 8; operationType = OperatorType.MathFloor; break; } subStr = context.Expression.Substring(context.TokenPosition, Math.Min(9, context.Expression.Length - context.TokenPosition)); if (subStr == "mathCeil " || subStr == "mathCeil(") { offset = 7; operationType = OperatorType.MathCeil; break; } return(false); case 'o': subStr = context.Expression.Substring(context.TokenPosition, Math.Min(14, context.Expression.Length - context.TokenPosition)); if (subStr == "os:htmlEncode " || subStr == "os:htmlEncode(") { offset = 12; operationType = OperatorType.HtmlEncode; break; } if (subStr == "os:htmlDecode " || subStr == "os:htmlDecode(") { offset = 12; operationType = OperatorType.HtmlDecode; break; } subStr = context.Expression.Substring(context.TokenPosition, Math.Min(13, context.Expression.Length - context.TokenPosition)); if (subStr == "os:urlEncode " || subStr == "os:urlEncode(") { offset = 11; operationType = OperatorType.UrlEncode; break; } if (subStr == "os:urlDecode " || subStr == "os:urlDecode(") { offset = 11; operationType = OperatorType.UrlDecode; break; } subStr = context.Expression.Substring(context.TokenPosition, Math.Min(18, context.Expression.Length - context.TokenPosition)); if (subStr == "os:jsStringEscape " || subStr == "os:jsStringEscape(") { offset = 16; operationType = OperatorType.JsStringEscape; break; } return(false); case 'h': subStr = context.Expression.Substring(context.TokenPosition, Math.Min(11, context.Expression.Length - context.TokenPosition)); if (subStr == "htmlEncode " || subStr == "htmlEncode(") { offset = 9; operationType = OperatorType.HtmlEncode; break; } if (subStr == "htmlDecode " || subStr == "htmlDecode(") { offset = 9; operationType = OperatorType.HtmlDecode; break; } return(false); case 'u': subStr = context.Expression.Substring(context.TokenPosition, Math.Min(10, context.Expression.Length - context.TokenPosition)); if (subStr == "urlEncode " || subStr == "urlEncode(") { offset = 8; operationType = OperatorType.UrlEncode; break; } if (subStr == "urlDecode " || subStr == "urlDecode(") { offset = 8; operationType = OperatorType.UrlDecode; break; } return(false); case 'j': subStr = context.Expression.Substring(context.TokenPosition, Math.Min(15, context.Expression.Length - context.TokenPosition)); if (subStr == "jsStringEscape " || subStr == "jsStringEscape(") { offset = 13; operationType = OperatorType.JsStringEscape; break; } return(false); default: return(false); } ValidateTokenOrder(context, TokenType.Function); context.TokenPosition += offset; IList <IList <Element> > parameters = GetParameters(context); ElementOperator element = new ElementFunction(operationType, parameters); ProcessOperator(context, element); return(true); }