add copy() for raw string injection to Builder

This commit is contained in:
Jörg Prante 2021-12-02 18:07:21 +01:00
parent 31aa9c4de5
commit 07673324ca
4 changed files with 23 additions and 0 deletions

View file

@ -58,5 +58,7 @@ public interface Builder {
Builder copy(Builder builder) throws IOException;
Builder copy(String string) throws IOException;
String build();
}

View file

@ -182,6 +182,15 @@ public class JsonBuilder implements Builder {
return this;
}
@Override
public Builder copy(String string) throws IOException {
if (state.structure == Structure.COLLECTION) {
beginArrayValue();
}
appendable.append(string);
return this;
}
@Override
public String build() {
return appendable.toString();

View file

@ -305,6 +305,12 @@ public class XMLBuilder implements Builder {
return this;
}
@Override
public Builder copy(String string) throws IOException {
appendable.append(string);
return this;
}
@Override
public String build() {
return appendable.toString();

View file

@ -175,6 +175,12 @@ public class YamlBuilder implements Builder {
return this;
}
@Override
public Builder copy(String string) throws IOException {
buildValue(string);
return this;
}
@Override
public String build() {
return appendable.toString();