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

Add and use StringUtils.isWhitespaceOrEmpty()

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