@Test public void testVariable () throws IOException { final HashMap<String,String> fieldMap = new HashMap<String, String> (); fieldMap.put ("abc", "cooler than ice"); fieldMap.put ("def", "ice cold"); ExpressionHandler fieldHandler = new ExpressionHandler () { @Override public String eval (String name) throws IOException { return fieldMap.get (name); } }; String str = "abcd ${1} ${2} ${PATH} ${SHELL} {{abc}} {{}} {{d}} {{def}}"; String value; value = FieldParser.getString (str, fieldHandler); Assert.assertEquals ("abcd ${1} ${2} ${PATH} ${SHELL} cooler than ice ice cold", value); }
public static String getString (String str, ExpressionHandler expHandler) throws IOException { FieldParser parser = new FieldParser (expHandler); parser.setInput (new StringReader (str)); if (parser.yyLex () != 0) throw new IOException ("parsing error."); return parser.toString (); }
FieldParser extends GeneratedFieldParser { public static String getString (String str, ExpressionHandler expHandler) throws IOException { FieldParser parser = new FieldParser (expHandler); parser.setInput (new StringReader (str)); if (parser.yyLex () != 0) throw new IOException ("parsing error."); return parser.toString (); } }
FieldParser extends GeneratedFieldParser { public static String getString (String str, ExpressionHandler expHandler) throws IOException { FieldParser parser = new FieldParser (expHandler); parser.setInput (new StringReader (str)); if (parser.yyLex () != 0) throw new IOException ("parsing error."); return parser.toString (); } private  FieldParser(ExpressionHandler fieldHandler); }
FieldParser extends GeneratedFieldParser { public static String getString (String str, ExpressionHandler expHandler) throws IOException { FieldParser parser = new FieldParser (expHandler); parser.setInput (new StringReader (str)); if (parser.yyLex () != 0) throw new IOException ("parsing error."); return parser.toString (); } private  FieldParser(ExpressionHandler fieldHandler); @Override String toString(); static String getString(String str, ExpressionHandler expHandler); }
FieldParser extends GeneratedFieldParser { public static String getString (String str, ExpressionHandler expHandler) throws IOException { FieldParser parser = new FieldParser (expHandler); parser.setInput (new StringReader (str)); if (parser.yyLex () != 0) throw new IOException ("parsing error."); return parser.toString (); } private  FieldParser(ExpressionHandler fieldHandler); @Override String toString(); static String getString(String str, ExpressionHandler expHandler);  }