src/main/java/tinyrtpl/Rtpl.java
private static Data _ex(Data data, String exp) {
        if (exp == null || "".equals(exp)) return null;
        int offset = 0;

        // [...]
        int squareBracketBegin = exp.indexOf('[');
        int squareBracketEnd = exp.indexOf(']');
        if (squareBracketBegin < 0) {
            if (squareBracketEnd >= 0) return null;
        } else if (squareBracketBegin == 0) {
            return null;
        } else {
            if (squareBracketEnd <= squareBracketBegin + 1) return null;
        }
        if (squareBracketBegin > 0) {
            return Rtpl._ex(data, exp.substring(0, squareBracketBegin) + "." + Rtpl._ex(data, exp.substring(squareBracketBegin + 1, squareBracketEnd)).toString() + exp.substring(squareBracketEnd + 1));
        }

        // ... ? ... : ...
        int questionPos = exp.indexOf('?');
        if (questionPos == 0) return null;
        if (questionPos > 0) {
            int colonPos = exp.indexOf(':');
            if (colonPos <= questionPos + 1) return null;
            return Data.op(Rtpl._ex(data, exp.substring(0, questionPos)),
                    Rtpl._ex(data, exp.substring(questionPos + 1, colonPos)),
                    Rtpl._ex(data, exp.substring(colonPos + 1)));
        }

        return Rtpl.evalTokenList(Rtpl.getTokensOfExp(data, exp));
    }
/**
     * Return a data evaluated from an expression.
     * @param data: the data scope
     * @param exp: the expression
     * @return a Data instance
     */
Return a data evaluated from an expression.
@param data: the data scope
@param exp: the expression
@return a Data instance
Return a data evaluated from an expression . @param data : the data scope @param exp : the expression @return a Data instance
private static Data _ex(Data data, String exp) {
        if (exp == null || "".equals(exp)) return null;
        int offset = 0;
        int squareBracketBegin = exp.indexOf('[');
        int squareBracketEnd = exp.indexOf(']');
        if (squareBracketBegin < 0) {
            if (squareBracketEnd >= 0) return null;
        } else if (squareBracketBegin == 0) {
            return null;
        } else {
            if (squareBracketEnd <= squareBracketBegin + 1) return null;
        }
        if (squareBracketBegin > 0) {
            return Rtpl._ex(data, exp.substring(0, squareBracketBegin) + "." + Rtpl._ex(data, exp.substring(squareBracketBegin + 1, squareBracketEnd)).toString() + exp.substring(squareBracketEnd + 1));
        }
        int questionPos = exp.indexOf('?');
        if (questionPos == 0) return null;
        if (questionPos > 0) {
            int colonPos = exp.indexOf(':');
            if (colonPos <= questionPos + 1) return null;
            return Data.op(Rtpl._ex(data, exp.substring(0, questionPos)),
                    Rtpl._ex(data, exp.substring(questionPos + 1, colonPos)),
                    Rtpl._ex(data, exp.substring(colonPos + 1)));
        }
        return Rtpl.evalTokenList(Rtpl.getTokensOfExp(data, exp));
    }
private static Data _ex ( Data data , String exp ) { if ( exp == null || "" . equals ( exp ) ) return null ; int offset = 0 ; int squareBracketBegin = exp . indexOf ( '[' ) ; int squareBracketEnd = exp . indexOf ( ']' ) ; if ( squareBracketBegin < 0 ) { if ( squareBracketEnd >= 0 ) return null ; } else if ( squareBracketBegin == 0 ) { return null ; } else { if ( squareBracketEnd <= squareBracketBegin + 1 ) return null ; } if ( squareBracketBegin > 0 ) { return Rtpl . _ex ( data , exp . substring ( 0 , squareBracketBegin ) + "." + Rtpl . _ex ( data , exp . substring ( squareBracketBegin + 1 , squareBracketEnd ) ) . toString ( ) + exp . substring ( squareBracketEnd + 1 ) ) ; } int questionPos = exp . indexOf ( '?' ) ; if ( questionPos == 0 ) return null ; if ( questionPos > 0 ) { int colonPos = exp . indexOf ( ':' ) ; if ( colonPos <= questionPos + 1 ) return null ; return Data . op ( Rtpl . _ex ( data , exp . substring ( 0 , questionPos ) ) , Rtpl . _ex ( data , exp . substring ( questionPos + 1 , colonPos ) ) , Rtpl . _ex ( data , exp . substring ( colonPos + 1 ) ) ) ; } return Rtpl . evalTokenList ( Rtpl . getTokensOfExp ( data , exp ) ) ; }
Return a data evaluated from an expression.
Return a data evaluated from an expression .
// [...] // ... ? ... : ...