提交 e619227f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Pass StringBuilder to StringUtils.indent()

上级 140e8a8d
......@@ -1336,7 +1336,7 @@ public class Select extends Query {
for (int i = 0; i < visibleColumnCount; i++) {
buff.appendExceptFirst(",");
buff.append('\n');
buff.append(StringUtils.indent(exprList[i].getSQL(), 4, false));
StringUtils.indent(buff.builder(), exprList[i].getSQL(), 4, false);
}
buff.append("\nFROM ");
TableFilter filter = topTableFilter;
......
......@@ -43,8 +43,7 @@ public class ConditionExists extends Condition {
@Override
public StringBuilder getSQL(StringBuilder builder) {
builder.append("EXISTS(\n");
builder.append(StringUtils.indent(query.getPlanSQL(), 4, false));
return builder.append(')');
return StringUtils.indent(builder, query.getPlanSQL(), 4, false).append(')');
}
@Override
......
......@@ -143,7 +143,8 @@ public class ConditionInSelect extends Condition {
append(" ANY");
}
}
return builder.append("(\n").append(StringUtils.indent(query.getPlanSQL(), 4, false)).append("))");
builder.append("(\n");
return StringUtils.indent(builder, query.getPlanSQL(), 4, false).append("))");
}
@Override
......
......@@ -774,7 +774,7 @@ public class TableFilter implements ColumnResolver {
if (enclose) {
buff.append("(\n");
}
buff.append(StringUtils.indent(nested, 4, false));
StringUtils.indent(buff, nested, 4, false);
if (enclose) {
buff.append(')');
}
......@@ -842,7 +842,7 @@ public class TableFilter implements ColumnResolver {
if (plan.indexOf('\n') >= 0) {
plan += "\n";
}
buff.append(StringUtils.indent("/* " + plan + " */", 4, false));
StringUtils.indent(buff, "/* " + plan + " */", 4, false);
}
if (isJoin) {
buff.append("\n ON ");
......@@ -858,7 +858,7 @@ public class TableFilter implements ColumnResolver {
buff.append('\n');
String condition = StringUtils.unEnclose(filterCondition.getSQL());
condition = "/* WHERE " + StringUtils.quoteRemarkSQL(condition) + "\n*/";
buff.append(StringUtils.indent(condition, 4, false));
StringUtils.indent(buff, condition, 4, false);
}
if (scanCount > 0) {
buff.append("\n /* scanCount: ").append(scanCount).append(" */");
......
......@@ -468,7 +468,8 @@ public class TableView extends Table {
@Override
public String getSQL() {
if (isTemporary() && querySQL != null) {
return "(\n" + StringUtils.indent(querySQL) + ")";
StringBuilder builder = new StringBuilder(querySQL.length() + 16).append("(\n");
return StringUtils.indent(builder, querySQL, 4, true).append(')').toString();
}
return super.getSQL();
}
......
......@@ -560,49 +560,49 @@ public class StringUtils {
*/
public static String xmlNode(String name, String attributes,
String content, boolean indent) {
String start = attributes == null ? name : name + attributes;
StringBuilder builder = new StringBuilder();
builder.append('<').append(name);
if (attributes != null) {
builder.append(attributes);
}
if (content == null) {
return "<" + start + "/>\n";
builder.append("/>\n");
return builder.toString();
}
builder.append('>');
if (indent && content.indexOf('\n') >= 0) {
content = "\n" + indent(content);
builder.append('\n');
indent(builder, content, 4, true);
} else {
builder.append(content);
}
return "<" + start + ">" + content + "</" + name + ">\n";
}
/**
* Indents a string with 4 spaces.
*
* @param s the string
* @return the indented string
*/
public static String indent(String s) {
return indent(s, 4, true);
builder.append("</").append(name).append(">\n");
return builder.toString();
}
/**
* Indents a string with spaces.
* Indents a string with spaces and appends it to a specified builder.
*
* @param builder string builder to append to
* @param s the string
* @param spaces the number of spaces
* @param newline append a newline if there is none
* @return the indented string
* @return the specified string builder
*/
public static String indent(String s, int spaces, boolean newline) {
StringBuilder buff = new StringBuilder(s.length() + spaces);
for (int i = 0; i < s.length();) {
public static StringBuilder indent(StringBuilder builder, String s, int spaces, boolean newline) {
for (int i = 0, length = s.length(); i < length;) {
for (int j = 0; j < spaces; j++) {
buff.append(' ');
builder.append(' ');
}
int n = s.indexOf('\n', i);
n = n < 0 ? s.length() : n + 1;
buff.append(s, i, n);
n = n < 0 ? length : n + 1;
builder.append(s, i, n);
i = n;
}
if (newline && !s.endsWith("\n")) {
buff.append('\n');
builder.append('\n');
}
return buff.toString();
return builder;
}
/**
......@@ -625,7 +625,8 @@ public class StringUtils {
// must have a space at the beginning and at the end,
// otherwise the data must not contain '-' as the first/last character
if (data.indexOf('\n') >= 0) {
return "<!--\n" + indent(data) + "-->\n";
StringBuilder builder = new StringBuilder(data.length() + 18).append("<!--\n");
return indent(builder, data, 4, true).append("-->\n").toString();
}
return "<!-- " + data + " -->\n";
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论