package org.cobbzilla.util.javascript;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

import static org.cobbzilla.util.io.StreamUtil.stream2string;
import static org.cobbzilla.util.string.StringUtil.getPackagePath;

@Slf4j
public class StandardJsEngine extends JsEngine {

    public StandardJsEngine() { this(1, 1); }

    public StandardJsEngine(int minEngines, int maxEngines) { super(new JsEngineConfig(minEngines, maxEngines, STANDARD_FUNCTIONS)); }

    public static final String STANDARD_FUNCTIONS = stream2string(getPackagePath(StandardJsEngine.class)+"/standard_js_lib.js");

    private static final String ESC_DOLLAR = "__ESCAPED_DOLLAR_SIGN__";
    public static String replaceDollarSigns(String val) {
        return val.replace("'$", ESC_DOLLAR)
                .replaceAll("(\\$(\\d+(\\.\\d{2})?))", "($2 * 100)")
                .replace(ESC_DOLLAR, "'$");
    }

    public String round(String value, String script) {
        final Map<String, Object> ctx = new HashMap<>();
        ctx.put("x", value);
        try {
            return String.valueOf(evaluateInt(script, ctx));
        } catch (Exception e) {
            log.warn("round('"+value+"', '"+script+"', NOT rounding due to exception: "+e);
            return value;
        }
    }
}

@@ -72,57 +72,8 @@
 j;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 impo
@@ -572,683 +572,6 @@
 );%0A%0A
-    private static final String ESC_DOLLAR = %22__ESCAPED_DOLLAR_SIGN__%22;%0A    public static String replaceDollarSigns(String val) %7B%0A        return val.replace(%22'$%22, ESC_DOLLAR)%0A                .replaceAll(%22(%5C%5C$(%5C%5Cd+(%5C%5C.%5C%5Cd%7B2%7D)?))%22, %22($2 * 100)%22)%0A                .replace(ESC_DOLLAR, %22'$%22);%0A    %7D%0A%0A    public String round(String value, String script) %7B%0A        final Map%3CString, Object%3E ctx = new HashMap%3C%3E();%0A        ctx.put(%22x%22, value);%0A        try %7B%0A            return String.valueOf(evaluateInt(script, ctx));%0A        %7D catch (Exception e) %7B%0A            log.warn(%22round('%22+value+%22', '%22+script+%22', NOT rounding due to exception: %22+e);%0A            return value;%0A        %7D%0A    %7D%0A
 %7D%0A

remove obsolete code