src/main/java/tinyrtpl/Rtpl.java
private static Data _get(Data odata, String oref, boolean wrap) {
        String ref = oref.trim();

        // const boolean
        if ("true".equals(ref) || "false".equals(ref))
            return new Data("true".equals(ref), 1);

        char ch = ref.charAt(0);
        if (ch >= '0' && ch <= '9') { // const number
            try {
                int vi = Integer.parseInt(ref);
                return new Data(vi, 2);
            } catch (NumberFormatException ex) {
                try {
                    double vd = Double.parseDouble(ref);
                    return new Data(vd, 3);
                } catch (NumberFormatException ex1) {
                    try {
                        float vf = Float.parseFloat(ref);
                        return new Data(new BigDecimal(String.valueOf(vf)).doubleValue(), 3);
                    } catch (NumberFormatException ex2) {
                        return null;
                    }
                }
            }
        } else if (ch == '"') { // const string
            int lastQuotationPos = ref.lastIndexOf('"');
            if (lastQuotationPos <= 0) return null;
            return new Data(ref.substring(1, lastQuotationPos), 4);
        }

        Data data;
        if (wrap) {
            data = new Data();
            data.put("this", (ref == null || "".equals(ref)) ? odata : odata.get(ref));

            // 支持自定义变量渗透进子作用域传递
            Map m = (HashMap) odata.val();
            Iterator it = m.entrySet().iterator();
            String kStr;
            while (it.hasNext()) {
                Map.Entry e = (Map.Entry) it.next();
                kStr = (String) e.getKey();
                if ("this".equals(kStr)) continue;
                data.put(kStr, e.getValue());
            }
        } else {
            data = (ref == null || "".equals(ref)) ? null : odata.get(ref);
        }
        return data;
    }
/**
     * Return the referred data.
     * @param odata: the data scope
     * @param oref: the reference
     * @param wrap: if need to wrap the referred data with "this"
     * @return a Data instance
     */
Return the referred data.
@param odata: the data scope
@param oref: the reference
@param wrap: if need to wrap the referred data with "this"
@return a Data instance
Return the referred data . @param odata : the data scope @param oref : the reference @param wrap : if need to wrap the referred data with " this " @return a Data instance
private static Data _get(Data odata, String oref, boolean wrap) {
        String ref = oref.trim();
        if ("true".equals(ref) || "false".equals(ref))
            return new Data("true".equals(ref), 1);
        char ch = ref.charAt(0);
        if (ch >= '0' && ch <= '9') { 
            try {
                int vi = Integer.parseInt(ref);
                return new Data(vi, 2);
            } catch (NumberFormatException ex) {
                try {
                    double vd = Double.parseDouble(ref);
                    return new Data(vd, 3);
                } catch (NumberFormatException ex1) {
                    try {
                        float vf = Float.parseFloat(ref);
                        return new Data(new BigDecimal(String.valueOf(vf)).doubleValue(), 3);
                    } catch (NumberFormatException ex2) {
                        return null;
                    }
                }
            }
        } else if (ch == '"') { 
            int lastQuotationPos = ref.lastIndexOf('"');
            if (lastQuotationPos <= 0) return null;
            return new Data(ref.substring(1, lastQuotationPos), 4);
        }
        Data data;
        if (wrap) {
            data = new Data();
            data.put("this", (ref == null || "".equals(ref)) ? odata : odata.get(ref));
            Map m = (HashMap) odata.val();
            Iterator it = m.entrySet().iterator();
            String kStr;
            while (it.hasNext()) {
                Map.Entry e = (Map.Entry) it.next();
                kStr = (String) e.getKey();
                if ("this".equals(kStr)) continue;
                data.put(kStr, e.getValue());
            }
        } else {
            data = (ref == null || "".equals(ref)) ? null : odata.get(ref);
        }
        return data;
    }
private static Data _get ( Data odata , String oref , boolean wrap ) { String ref = oref . trim ( ) ; if ( "true" . equals ( ref ) || "false" . equals ( ref ) ) return new Data ( "true" . equals ( ref ) , 1 ) ; char ch = ref . charAt ( 0 ) ; if ( ch >= '0' && ch <= '9' ) { try { int vi = Integer . parseInt ( ref ) ; return new Data ( vi , 2 ) ; } catch ( NumberFormatException ex ) { try { double vd = Double . parseDouble ( ref ) ; return new Data ( vd , 3 ) ; } catch ( NumberFormatException ex1 ) { try { float vf = Float . parseFloat ( ref ) ; return new Data ( new BigDecimal ( String . valueOf ( vf ) ) . doubleValue ( ) , 3 ) ; } catch ( NumberFormatException ex2 ) { return null ; } } } } else if ( ch == '"' ) { int lastQuotationPos = ref . lastIndexOf ( '"' ) ; if ( lastQuotationPos <= 0 ) return null ; return new Data ( ref . substring ( 1 , lastQuotationPos ) , 4 ) ; } Data data ; if ( wrap ) { data = new Data ( ) ; data . put ( "this" , ( ref == null || "" . equals ( ref ) ) ? odata : odata . get ( ref ) ) ; Map m = ( HashMap ) odata . val ( ) ; Iterator it = m . entrySet ( ) . iterator ( ) ; String kStr ; while ( it . hasNext ( ) ) { Map . Entry e = ( Map . Entry ) it . next ( ) ; kStr = ( String ) e . getKey ( ) ; if ( "this" . equals ( kStr ) ) continue ; data . put ( kStr , e . getValue ( ) ) ; } } else { data = ( ref == null || "" . equals ( ref ) ) ? null : odata . get ( ref ) ; } return data ; }
Return the referred data.
Return the referred data .
// const boolean // const number // const string // 支持自定义变量渗透进子作用域传递