Scan the right-side string value, return a STARTS WITH Expression for generating XML

@param a ExpressionColumn
511735
private ExpressionLogical XStartsWithPredicateRightPart(Expression left) {

        readThis(Tokens.WITH);

        if (token.tokenType == Tokens.QUESTION) {    // handle user parameter case
            Expression right = XreadRowValuePredicand();
            if (left.isParam() && right.isParam()) {  // again make sure the left side is valid
                throw Error.error(ErrorCode.X_42567);
            }
            /** In this case, we make the right parameter as the lower bound,
             *  and the right parameter concatenating a special char (greater than any other chars) as the upper bound.
             *  It now becomes a range scan for all the strings with right parameter as its prefix.
             */
            Expression l = new ExpressionLogical(OpTypes.GREATER_EQUAL, left, right);
            Expression r = new ExpressionLogical(OpTypes.SMALLER_EQUAL, left,
                    new ExpressionArithmetic(OpTypes.CONCAT, right, new ExpressionValue("\uffff", Type.SQL_CHAR)));
            return new ExpressionLogical(OpTypes.AND, l, r);
        } else {          // handle plain string value and the column
            Expression right      = XreadStringValueExpression();
            return new ExpressionStartsWith(left, right, this.isCheckOrTriggerCondition);
        }
    }
66593
private JCExpression scanForAssign(final MethodSymbol sym,
                                       final JCTree tree) {
        class TS extends TreeScanner {
            JCExpression result = null;
            public void scan(JCTree t) {
                if (t != null && result == null)
                    t.accept(this);
            }
            public void visitAnnotation(JCAnnotation t) {
                if (t == tree)
                    scan(t.args);
            }
            public void visitAssign(JCAssign t) {
                if (t.lhs.hasTag(IDENT)) {
                    JCIdent ident = (JCIdent) t.lhs;
                    if (ident.sym == sym)
                        result = t.rhs;
                }
            }
        }
        TS scanner = new TS();
        tree.accept(scanner);
        return scanner.result;
    }
659962
@Override
    public Object getValueAt(Object nodeObj, int column) {
        if (debugger == null) { return null; }
        VariableNode node = (VariableNode)nodeObj;
        switch (column) {
        case 0: // Name
            return node.toString();
        case 1: // Value
            String result;
            try {
                result = debugger.objectToString(getValue(node));
            } catch (RuntimeException exc) {
                result = exc.getMessage();
            }
            StringBuilder buf = new StringBuilder();
            int len = result.length();
            for (int i = 0; i < len; i++) {
                char ch = result.charAt(i);
                if (Character.isISOControl(ch)) {
                    ch = ' ';
                }
                buf.append(ch);
            }
            return buf.toString();
        }
        return null;
    }
866377
protected String attributeAsString(XMLStreamReader reader, String attributeName, Map<String, String> expressions)
      throws XMLStreamException
   {
      String attributeString = rawAttributeText(reader, attributeName);

      if (attributeName != null && expressions != null && attributeString != null &&
          attributeString.indexOf("${") != -1)
         expressions.put(attributeName, attributeString);

      return getSubstitutionValue(attributeString);
   }
1280312
Content scanFormulaNode(Element formulaNode) throws Exception {
        // first off, try scanning for a semantic split, this indicates multiple semantics
        Boolean containsSemantic = XMLHelper.getElementB(formulaNode, xPath.compile("//m:semantics")) != null;

        // check if there is an annotationNode and if so check which semantics are present
        Element annotationNode = (Element) XMLHelper.getElementB(formulaNode, xPath.compile("//m:annotation-xml"));
        Boolean containsCMML = annotationNode != null && annotationNode.getAttribute("encoding").equals("MathML-Content");
        Boolean containsPMML = annotationNode != null && annotationNode.getAttribute("encoding").equals("MathML-Presentation");

        // if apply are present, the content semantics is used somewhere
        NonWhitespaceNodeList applyNodes = new NonWhitespaceNodeList(XMLHelper.getElementsB(formulaNode, xPath.compile("//m:apply")));
        containsCMML |= applyNodes.getLength() > 0;

        // if mrow nodes are present, the presentation semantic is used somewhere
        NonWhitespaceNodeList mrowNodes = new NonWhitespaceNodeList(XMLHelper.getElementsB(formulaNode, xPath.compile("//m:mrow")));
        containsPMML |= mrowNodes.getLength() > 0;

        // TODO the containCMML and -PMML can be more specific, e.g. check if identifiers of each semantics is present
        if (containsSemantic) {
            // if semantic separator is present plus one opposite semantic, we assume a LaTeXML produced content
            return containsCMML || containsPMML ? Content.mathml : Content.unknown;
        } else {
            if (containsCMML && containsPMML) {
                // both semantics without semantic separator suggests broken syntax
                return Content.unknown;
            } else if (containsCMML) {
                return Content.cmml;
            } else if (containsPMML) {
                return Content.pmml;
            }
        }

        // next, try to identify latex
        Element child = (Element) XMLHelper.getElementB(formulaNode, "./*[1]");
        // if there is no child node, we currently anticipate some form of latex formula
        if (child == null && StringUtils.isNotEmpty(formulaNode.getTextContent())) {
            return Content.latex;
        }

        // found nothing comprehensible
        return Content.unknown;
    }
267805
private Expression getExpression(String expressionString) throws ParseException {
		if (!expressionCache.containsKey(expressionString)) {
			Expression expression;
			expression = parser.parseExpression(expressionString);
			expressionCache.put(expressionString, expression);
		}
		return expressionCache.get(expressionString);

	}
951692
public static boolean evaluate(final String expression) {
        final Deque<String> operators = new ArrayDeque<>();
        final Deque<String> values = new ArrayDeque<>();
        final boolean result;

        char currentCharacter;
        int currentCharacterIndex = 0;

        try {
            while (currentCharacterIndex < expression.length()) {
                currentCharacter = expression.charAt(currentCharacterIndex);

                if (SeparatorToken.OPEN_PARENTHESIS.value == currentCharacter) {
                    operators.push(SeparatorToken.OPEN_PARENTHESIS.toString());
                    currentCharacterIndex += moveCursor(SeparatorToken.OPEN_PARENTHESIS.toString());
                } else if (SeparatorToken.SPACE.value == currentCharacter) {
                    currentCharacterIndex += moveCursor(SeparatorToken.SPACE.toString());
                } else if (SeparatorToken.CLOSE_PARENTHESIS.value == currentCharacter) {
                    evaluateSubexpression(operators, values);
                    currentCharacterIndex += moveCursor(SeparatorToken.CLOSE_PARENTHESIS.toString());
                } else if (!Character.isDigit(currentCharacter)) {
                    final String parsedNonDigit = parseNonDigits(expression, currentCharacterIndex);
                    if (isBoolean(parsedNonDigit)) {
                        values.push(replaceBooleanStringByIntegerRepresentation(parsedNonDigit));
                    } else {
                        operators.push(validateOperator(parsedNonDigit));
                    }
                    currentCharacterIndex += moveCursor(parsedNonDigit);
                } else if (Character.isDigit(currentCharacter)) {
                    final String parsedDigits = parseDigits(expression, currentCharacterIndex);
                    values.push(parsedDigits);
                    currentCharacterIndex += moveCursor(parsedDigits);
                }
            }

            result = Boolean.valueOf(evaluateExpressionStack(operators, values));

            if (log.isDebugEnabled()) {
                log.debug("Boolean expression {} evaluates to {}", expression, result);
            }
        } catch (final NoSuchElementException e) {
            throw new CitrusRuntimeException("Unable to parse boolean expression '" + expression + "'. Maybe expression is incomplete!", e);
        }

        return result;
    }
688407
private boolean checkSimpleExpression(String tagExpression, List<String> scenarioTags) {
        Set<String> expressionTags = extractTagsFromSimpleExpression(tagExpression);

        for (String expressionTag : expressionTags) {
            if (expressionTag.startsWith("@")) {
                if (!scenarioTags.contains(expressionTag)) {
                    //this tag is not listed on the scenario so don't execute
                    return false;
                }
            } else if (expressionTag.startsWith("!")) {
                String expressionTagWithoutNot = expressionTag.substring(1, expressionTag.length());
                if (scenarioTags.contains(expressionTagWithoutNot)) {
                    //this is a negated tag and it exists on the scenario so don't execute
                    return false;
                }
            } else {
                throw new IllegalStateException(String.format("'%s' is not a valid tag, no @ or !@ prefix", expressionTag));
            }
        }

        //there are no reasons left for not executing
        return true;
    }
527213
private int _readXMLComment (final Line firstLine, final int start)
  {
    Line line = firstLine;
    if (start + 3 < line.m_sValue.length ())
    {
      if (line.m_sValue.charAt (2) == '-' && line.m_sValue.charAt (3) == '-')
      {
        int pos = start + 4;
        while (line != null)
        {
          while (pos < line.m_sValue.length () && line.m_sValue.charAt (pos) != '-')
          {
            pos++;
          }
          if (pos == line.m_sValue.length ())
          {
            line = line.m_aNext;
            pos = 0;
          }
          else
          {
            if (pos + 2 < line.m_sValue.length ())
            {
              if (line.m_sValue.charAt (pos + 1) == '-' && line.m_sValue.charAt (pos + 2) == '>')
              {
                m_aXmlEndLine = line;
                return pos + 3;
              }
            }
            pos++;
          }
        }
      }
    }
    return -1;
  }
732320
public static Expression arrayPosition(String expression, Expression value) {
        return arrayPosition(x(expression), value);
    }
433480
@CheckForSigned
  public static int readXMLElement (final StringBuilder aSB,
                                    final String sIn,
                                    final int nStart,
                                    final boolean bSafeMode)
  {
    try
    {
      if (sIn.charAt (nStart + 1) == '!')
      {
        aSB.append ("<!");
        return nStart + 1;
      }

      int pos;
      boolean bIsCloseTag;
      if (sIn.charAt (nStart + 1) == '/')
      {
        bIsCloseTag = true;
        pos = nStart + 2;
      }
      else
      {
        bIsCloseTag = false;
        pos = nStart + 1;
      }

      if (bSafeMode)
      {
        final StringBuilder temp = new StringBuilder ();
        pos = _readRawUntil (temp, sIn, pos, ' ', '/', '>');
        if (pos == -1)
          return -1;
        final String tag = temp.toString ().trim ().toLowerCase (Locale.US);
        if (MarkdownHTML.isUnsafeHtmlElement (tag))
        {
          aSB.append ("&lt;");
          if (bIsCloseTag)
            aSB.append ('/');
          aSB.append (temp);
        }
        else
        {
          aSB.append ('<');
          if (bIsCloseTag)
            aSB.append ('/');
          aSB.append (temp);
        }
      }
      else
      {
        aSB.append ('<');
        if (bIsCloseTag)
          aSB.append ('/');
        pos = _readRawUntil (aSB, sIn, pos, ' ', '/', '>');
      }
      if (pos == -1)
        return -1;
      pos = _readRawUntil (aSB, sIn, pos, '/', '>');
      if (sIn.charAt (pos) == '/')
      {
        aSB.append (" /");
        pos = readRawUntil (aSB, sIn, pos + 1, '>');
        if (pos == -1)
          return -1;
      }
      if (sIn.charAt (pos) == '>')
      {
        aSB.append ('>');
        return pos + 1;
      }
    }
    catch (final StringIndexOutOfBoundsException e)
    {
      return -1;
    }
    return -1;
  }
600109
private String appendXmlStartTag(String value)  {
        StringBuilder sb = new StringBuilder();
        sb.append("<").append(value).append(">");

        return sb.toString();
    }
549807
String expand(String expression, boolean horizontal) {
        int cursor = 0;
        int start = expression.indexOf(LayoutMap.VARIABLE_PREFIX_CHAR, cursor);
        if (start == -1) { // No variables
            return expression;
        }
        StringBuffer buffer = new StringBuffer();
        do {
            buffer.append(expression.substring(cursor, start));
            String variableName = nextVariableName(expression, start);
            buffer.append(expansion(variableName, horizontal));
            cursor = start + variableName.length() + 1;
            start = expression.indexOf(LayoutMap.VARIABLE_PREFIX_CHAR, cursor);
        } while (start != -1);
        buffer.append(expression.substring(cursor));
        return buffer.toString();
    }
169370
public static String print(Expression expression) {
        return expression.match(new Expression.MatchBlock<String>() {

            @Override
            public String _case(LiteralExpression x) {
                return print(x.literal);
            }

            @Override
            public String _case(VariableExpression x) {
                return x.selector.match(new Optional.MatchBlock<Expression, String>() {
                    @Override
                    public String _case(Some<Expression> x) {
                        return print(x.value) + ".";
                    }

                    @Override
                    public String _case(None<Expression> x) {
                        return "";
                    }
                }) + x.identifier;
            }

            @Override
            public String _case(NestedExpression x) {
                return "( " + print(x.expression) + " )";
            }

            @Override
            public String _case(ClassReference x) {
                return print(x.type) + ".class";
            }

            @Override
            public String _case(TernaryExpression x) {
                return print(x.cond) + " ? " + print(x.trueExpression) + " : " + print (x.falseExpression);
            }

            @Override
            public String _case(BinaryExpression x) {
                return print(x.left) + " " + print(x.op) + " " +  print(x.right);
            }
        });
    }
914233
static BaseLongColumnValueSelector makeColumnValueSelectorWithLongDefault(
      final ColumnSelectorFactory metricFactory,
      final ExprMacroTable macroTable,
      @Nullable final String fieldName,
      @Nullable final String fieldExpression,
      final long nullValue
  )
  {
    if ((fieldName == null) == (fieldExpression == null)) {
      throw new IllegalArgumentException("");
    }
    if (fieldName != null) {
      return metricFactory.makeColumnValueSelector(fieldName);
    } else {
      final Expr expr = Parser.parse(fieldExpression, macroTable);
      final ColumnValueSelector<ExprEval> baseSelector = ExpressionSelectors.makeExprEvalSelector(metricFactory, expr);
      class ExpressionLongColumnSelector implements LongColumnSelector
      {
        @Override
        public long getLong()
        {
          final ExprEval exprEval = baseSelector.getObject();
          return exprEval.isNumericNull() ? nullValue : exprEval.asLong();
        }

        @Override
        public void inspectRuntimeShape(RuntimeShapeInspector inspector)
        {
          inspector.visit("baseSelector", baseSelector);
        }

        @Override
        public boolean isNull()
        {
          final ExprEval exprEval = baseSelector.getObject();
          return exprEval == null || exprEval.isNumericNull();
        }
      }
      return new ExpressionLongColumnSelector();
    }
  }
825066
private Expression readCaseWhen(final Expression l) {

        readThis(Tokens.WHEN);

        Expression condition = null;

        if (l == null) {
            condition = XreadBooleanValueExpression();
        } else {
            while (true) {
                Expression newCondition = XreadPredicateRightPart(l);

                if (l == newCondition) {
                    newCondition =
                        new ExpressionLogical(l, XreadRowValuePredicand());
                }

                if (condition == null) {
                    condition = newCondition;
                } else {
                    condition = new ExpressionLogical(OpTypes.OR, condition,
                                                      newCondition);
                }

                if (token.tokenType == Tokens.COMMA) {
                    read();
                } else {
                    break;
                }
            }
        }

        readThis(Tokens.THEN);

        Expression current  = XreadValueExpression();
        Expression elseExpr = null;

        if (token.tokenType == Tokens.WHEN) {
            elseExpr = readCaseWhen(l);
        } else if (token.tokenType == Tokens.ELSE) {
            read();

            elseExpr = XreadValueExpression();

            readThis(Tokens.END);
            readIfThis(Tokens.CASE);
        } else {
            elseExpr = new ExpressionValue((Object) null, Type.SQL_ALL_TYPES);

            readThis(Tokens.END);
            readIfThis(Tokens.CASE);
        }

        Expression alternatives = new ExpressionOp(OpTypes.ALTERNATIVE,
            current, elseExpr);
        Expression casewhen = new ExpressionOp(OpTypes.CASEWHEN, condition,
                                               alternatives);

        return casewhen;
    }
405131
public static String evaluateAsString(Node node, String xPathExpression, NamespaceContext nsContext) {
        String result = (String) evaluateExpression(node, xPathExpression, nsContext, XPathConstants.STRING);

        if (!StringUtils.hasText(result)) {
            //result is empty so check if the expression node really exists
            //if node does not exist an exception is thrown
            evaluateAsNode(node, xPathExpression, nsContext);
        }

        return result;
    }