|
@@ -53,6 +53,8 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
|
|
|
|
|
private int size;
|
|
private int size;
|
|
|
|
|
|
|
|
|
|
+ private int indent;
|
|
|
|
|
+
|
|
|
private final Supplier<Formatter> formatter = LazyReference.unique(() -> new Formatter(this));
|
|
private final Supplier<Formatter> formatter = LazyReference.unique(() -> new Formatter(this));
|
|
|
|
|
|
|
|
final Deque<BuilderState> options = new ArrayDeque<>();
|
|
final Deque<BuilderState> options = new ArrayDeque<>();
|
|
@@ -413,7 +415,10 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
public StrBuilder append(CharSequence value, int begin, int end) {
|
|
public StrBuilder append(CharSequence value, int begin, int end) {
|
|
|
if (value == null) {
|
|
if (value == null) {
|
|
|
return append();
|
|
return append();
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if(indent > 0) {
|
|
|
|
|
+ append(value.subSequence(begin, end).toString(), 0, end-begin);
|
|
|
|
|
+ }
|
|
|
reserve(length() + (end - begin));
|
|
reserve(length() + (end - begin));
|
|
|
for(int i=begin; i<end; i++) {
|
|
for(int i=begin; i<end; i++) {
|
|
|
buffer[size++] = value.charAt(i);
|
|
buffer[size++] = value.charAt(i);
|
|
@@ -443,6 +448,12 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
if (value == null) {
|
|
if (value == null) {
|
|
|
return append();
|
|
return append();
|
|
|
}
|
|
}
|
|
|
|
|
+ if(indent > 0) {
|
|
|
|
|
+ String prefix = StringUtils.repeat(indent, options().indent()) + options().endl();
|
|
|
|
|
+ value = value.substring(begin, end).replaceAll("(\r\n|\n|\r)", prefix);
|
|
|
|
|
+ begin = 0;
|
|
|
|
|
+ end = value.length();
|
|
|
|
|
+ }
|
|
|
NativeArrayAllocator.ensureFromTo(value.length(), begin, end);
|
|
NativeArrayAllocator.ensureFromTo(value.length(), begin, end);
|
|
|
int n = end - begin;
|
|
int n = end - begin;
|
|
|
if (n > 0) {
|
|
if (n > 0) {
|
|
@@ -475,6 +486,11 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
if (value == null) {
|
|
if (value == null) {
|
|
|
return append();
|
|
return append();
|
|
|
}
|
|
}
|
|
|
|
|
+ if(indent > 0) {
|
|
|
|
|
+ char[] out = new char[end - begin];
|
|
|
|
|
+ value.getChars(begin, end, out, 0);
|
|
|
|
|
+ return append(StringUtils.wrap(out));
|
|
|
|
|
+ }
|
|
|
NativeArrayAllocator.ensureFromTo(value.length(), begin, end);
|
|
NativeArrayAllocator.ensureFromTo(value.length(), begin, end);
|
|
|
int n = end - begin;
|
|
int n = end - begin;
|
|
|
if (n > 0) {
|
|
if (n > 0) {
|
|
@@ -507,6 +523,11 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
if (value == null) {
|
|
if (value == null) {
|
|
|
return append();
|
|
return append();
|
|
|
}
|
|
}
|
|
|
|
|
+ if(indent > 0) {
|
|
|
|
|
+ char[] out = new char[end - begin];
|
|
|
|
|
+ value.getChars(begin, end, out, 0);
|
|
|
|
|
+ return append(StringUtils.wrap(out));
|
|
|
|
|
+ }
|
|
|
NativeArrayAllocator.ensureFromTo(value.length(), begin, end);
|
|
NativeArrayAllocator.ensureFromTo(value.length(), begin, end);
|
|
|
int n = end - begin;
|
|
int n = end - begin;
|
|
|
if (n > 0) {
|
|
if (n > 0) {
|
|
@@ -539,6 +560,9 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
if (value == null) {
|
|
if (value == null) {
|
|
|
return append();
|
|
return append();
|
|
|
}
|
|
}
|
|
|
|
|
+ if(indent > 0) {
|
|
|
|
|
+ return append(StringUtils.wrap(value).subSequence(begin, end));
|
|
|
|
|
+ }
|
|
|
NativeArrayAllocator.ensureFromTo(value.length, begin, end);
|
|
NativeArrayAllocator.ensureFromTo(value.length, begin, end);
|
|
|
int n = end - begin;
|
|
int n = end - begin;
|
|
|
if (n > 0) {
|
|
if (n > 0) {
|
|
@@ -1067,7 +1091,9 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
private String open;
|
|
private String open;
|
|
|
|
|
|
|
|
private String close;
|
|
private String close;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private String indent;
|
|
|
|
|
+
|
|
|
public BuilderState(StrBuilderOptions parent) {
|
|
public BuilderState(StrBuilderOptions parent) {
|
|
|
this.parent = parent;
|
|
this.parent = parent;
|
|
|
}
|
|
}
|
|
@@ -1084,6 +1110,7 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
state.separator(this.separator());
|
|
state.separator(this.separator());
|
|
|
state.open(this.open());
|
|
state.open(this.open());
|
|
|
state.close(this.close());
|
|
state.close(this.close());
|
|
|
|
|
+ state.indent(this.indent());
|
|
|
|
|
|
|
|
return state;
|
|
return state;
|
|
|
}
|
|
}
|
|
@@ -1142,6 +1169,17 @@ public final class StrBuilder implements CharSequence, Appendable, Serializable
|
|
|
this.close = value;
|
|
this.close = value;
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String indent() {
|
|
|
|
|
+ return indent;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public StrBuilderOptions indent(String value) {
|
|
|
|
|
+ this.indent = value;
|
|
|
|
|
+ return this;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|