Hi guys,
I have an application that allow the user to create some regex to compare values by using scripting, basically I am using the test code
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("rhino");
String[] scripts = {"/[abc]+/.test(\"giscaaard\")",
"/[abc]+/.test(\"giscaaard\r\")"};
for(String script : scripts){
Object result = engine.eval(script);
System.out.println(script + ":" + result);
}//end for
So I run a simple test
The output is
/[abc]+/.test("giscaaard"):true
Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: unterminated string literal (<Unknown source>#1) in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
at threads.Threads.main(Threads.java:34)
Java Result: 1
Any idea why rhino doesn't accept \r\n? If there is a standard for this where I can get how it handles other characters?
PS: In fact my first idea was to use only java classes for perform such things, however when I try to importClass(java.lang.String) I get an exception saying rhino already has one. Is there anyway on how I can give up rhino default classes and use the java one?
Thanks and Regards