提交 99e512c2 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add and use StringUtils.isWhitespaceOrEmpty()

上级 96d91496
...@@ -288,7 +288,7 @@ public class Parser { ...@@ -288,7 +288,7 @@ public class Parser {
Command c = new CommandContainer(this, sql, p); Command c = new CommandContainer(this, sql, p);
if (hasMore) { if (hasMore) {
String remaining = originalSQL.substring(parseIndex); String remaining = originalSQL.substring(parseIndex);
if (remaining.trim().length() != 0) { if (!StringUtils.isWhitespaceOrEmpty(remaining)) {
c = new CommandList(this, sql, c, remaining); c = new CommandList(this, sql, c, remaining);
} }
} }
......
...@@ -29,6 +29,7 @@ import org.h2.store.fs.FileUtils; ...@@ -29,6 +29,7 @@ import org.h2.store.fs.FileUtils;
import org.h2.tools.CompressTool; import org.h2.tools.CompressTool;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.SmallLRUCache; import org.h2.util.SmallLRUCache;
import org.h2.util.StringUtils;
import org.h2.util.TempFileDeleter; import org.h2.util.TempFileDeleter;
import org.h2.value.CompareMode; import org.h2.value.CompareMode;
...@@ -88,7 +89,7 @@ abstract class ScriptBase extends Prepared implements DataHandler { ...@@ -88,7 +89,7 @@ abstract class ScriptBase extends Prepared implements DataHandler {
protected String getFileName() { protected String getFileName() {
if (fileNameExpr != null && fileName == null) { if (fileNameExpr != null && fileName == null) {
fileName = fileNameExpr.optimize(session).getValue(session).getString(); fileName = fileNameExpr.optimize(session).getValue(session).getString();
if (fileName == null || fileName.trim().length() == 0) { if (fileName == null || StringUtils.isWhitespaceOrEmpty(fileName)) {
fileName = "script.sql"; fileName = "script.sql";
} }
fileName = SysProperties.getScriptDirectory() + fileName; fileName = SysProperties.getScriptDirectory() + fileName;
......
...@@ -596,7 +596,7 @@ public class FullText { ...@@ -596,7 +596,7 @@ public class FullText {
// this is just to query the result set columns // this is just to query the result set columns
return result; return result;
} }
if (text == null || text.trim().length() == 0) { if (text == null || StringUtils.isWhitespaceOrEmpty(text)) {
return result; return result;
} }
FullTextSettings setting = FullTextSettings.getInstance(conn); FullTextSettings setting = FullTextSettings.getInstance(conn);
......
...@@ -405,7 +405,7 @@ public class FullTextLucene extends FullText { ...@@ -405,7 +405,7 @@ public class FullTextLucene extends FullText {
// this is just to query the result set columns // this is just to query the result set columns
return result; return result;
} }
if (text == null || text.trim().length() == 0) { if (text == null || StringUtils.isWhitespaceOrEmpty(text)) {
return result; return result;
} }
try { try {
......
...@@ -310,7 +310,7 @@ class WebThread extends WebApp implements Runnable { ...@@ -310,7 +310,7 @@ class WebThread extends WebApp implements Runnable {
} }
} }
} }
} else if (line.trim().length() == 0) { } else if (StringUtils.isWhitespaceOrEmpty(line)) {
break; break;
} }
} }
......
...@@ -166,7 +166,7 @@ public class RunScript extends Tool { ...@@ -166,7 +166,7 @@ public class RunScript extends Tool {
if (sql == null) { if (sql == null) {
break; break;
} }
if (sql.trim().length() == 0) { if (StringUtils.isWhitespaceOrEmpty(sql)) {
continue; continue;
} }
boolean resultSet = stat.execute(sql); boolean resultSet = stat.execute(sql);
......
...@@ -445,7 +445,7 @@ public class Shell extends Tool implements Runnable { ...@@ -445,7 +445,7 @@ public class Shell extends Tool implements Runnable {
} }
private void execute(String sql) { private void execute(String sql) {
if (sql.trim().length() == 0) { if (StringUtils.isWhitespaceOrEmpty(sql)) {
return; return;
} }
long time = System.nanoTime(); long time = System.nanoTime();
......
...@@ -980,6 +980,22 @@ public class StringUtils { ...@@ -980,6 +980,22 @@ public class StringUtils {
return true; return true;
} }
/**
* Check if the specified string is empty or contains only whitespace.
*
* @param s
* the string
* @return whether the specified string is empty or contains only whitespace
*/
public static boolean isWhitespaceOrEmpty(String s) {
for (int i = 0, l = s.length(); i < l; i++) {
if (s.charAt(i) > ' ') {
return false;
}
}
return true;
}
/** /**
* Append a zero-padded number to a string builder. * Append a zero-padded number to a string builder.
* *
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论