提交 c77c145a authored 作者: Thomas Mueller's avatar Thomas Mueller

Avoid the singleton pattern because Tomcat sets static fields to null.

上级 23b0d542
...@@ -31,8 +31,6 @@ import org.h2.util.StringUtils; ...@@ -31,8 +31,6 @@ import org.h2.util.StringUtils;
*/ */
public class Bnf { public class Bnf {
private static final String SEPARATORS = " [](){}|.,\r\n<>:-+*/=<\">!'$";
private final Random random = new Random(); private final Random random = new Random();
private final HashMap ruleMap = new HashMap(); private final HashMap ruleMap = new HashMap();
private String syntax; private String syntax;
...@@ -142,7 +140,7 @@ public class Bnf { ...@@ -142,7 +140,7 @@ public class Bnf {
* @return the HTML formatted text * @return the HTML formatted text
*/ */
public String getSyntaxHtml(String bnf) { public String getSyntaxHtml(String bnf) {
StringTokenizer tokenizer = new StringTokenizer(bnf, SEPARATORS, true); StringTokenizer tokenizer = getTokenizer(bnf);
StringBuffer buff = new StringBuffer(); StringBuffer buff = new StringBuffer();
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken(); String s = tokenizer.nextToken();
...@@ -257,7 +255,7 @@ public class Bnf { ...@@ -257,7 +255,7 @@ public class Bnf {
syntax = StringUtils.replaceAll(syntax, "a-f", "@af@"); syntax = StringUtils.replaceAll(syntax, "a-f", "@af@");
syntax = StringUtils.replaceAll(syntax, "A-F", "@af@"); syntax = StringUtils.replaceAll(syntax, "A-F", "@af@");
syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@"); syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@");
StringTokenizer tokenizer = new StringTokenizer(syntax, SEPARATORS, true); StringTokenizer tokenizer = getTokenizer(syntax);
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken(); String s = tokenizer.nextToken();
// avoid duplicate strings // avoid duplicate strings
...@@ -337,4 +335,8 @@ public class Bnf { ...@@ -337,4 +335,8 @@ public class Bnf {
return statements; return statements;
} }
private StringTokenizer getTokenizer(String syntax) {
return new StringTokenizer(syntax, " [](){}|.,\r\n<>:-+*/=<\">!'$", true);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论