Skip to content

Commit

Permalink
Fix indentation (header & list)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carleslc committed Aug 8, 2020
1 parent 81c995b commit d48be3c
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 176 deletions.
Binary file modified Simple-Yaml-1.7.1-javadoc.jar
Binary file not shown.
Binary file modified Simple-Yaml-1.7.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,23 @@ public static YamlConfiguration loadConfiguration(final Reader reader) {

@Override
public String saveToString() throws IOException {
return this.buildHeader() + this.dump();
}

protected String dump() {
this.yamlOptions.setIndent(this.options().indent());
this.yamlOptions.setIndicatorIndent(this.options().indent());
this.yamlOptions.setAllowUnicode(this.options().isUnicode());
this.yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
this.yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

final String header = this.buildHeader();
String dump = this.yaml.dump(this.getValues(false));

if (dump.equals(YamlConfiguration.BLANK_CONFIG)) {
dump = "";
}

return header + dump;
return dump;
}

@Override
Expand Down Expand Up @@ -144,22 +148,21 @@ public void loadFromString(final String contents) throws InvalidConfigurationExc
@Override
protected String buildHeader() {
final String header = this.options().header();
final boolean copyHeader = this.options().copyHeader();

if (this.options().copyHeader()) {
final Configuration def = this.getDefaults();
if (!copyHeader || header == null) {
return "";
}

if (def instanceof FileConfiguration) {
final FileConfiguration filedefaults = (FileConfiguration) def;
final String defaultsHeader = filedefaults.buildHeader();
final Configuration def = this.getDefaults();

if (defaultsHeader != null && defaultsHeader.length() > 0) {
return defaultsHeader;
}
}
}
if (def instanceof FileConfiguration) {
final FileConfiguration filedefaults = (FileConfiguration) def;
final String defaultsHeader = filedefaults.buildHeader();

if (header == null) {
return "";
if (defaultsHeader != null && defaultsHeader.length() > 0) {
return defaultsHeader;
}
}

final StringBuilder builder = new StringBuilder();
Expand All @@ -171,7 +174,6 @@ protected String buildHeader() {

if (startedHeader || lines[i].length() != 0) {
builder.insert(0, lines[i]);
builder.insert(0, Commentable.COMMENT_PREFIX);
startedHeader = true;
}
}
Expand Down Expand Up @@ -217,7 +219,7 @@ protected static String parseHeader(final String input) {
}

if (line.length() > commentPrefixTrimmed.length()) {
result.append(line.substring(commentPrefixTrimmed.length()).trim());
result.append(line.trim());
}

foundHeader = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ public void save() throws IOException {
* @throws IOException if it hasn't been possible to save configuration file
*/
public String saveToString() throws IOException {
String contents = super.saveToString();
if (this.useComments) {
contents = new CommentDumper(this.options(), this.parseComments(), new StringReader(contents)).dump();
return new CommentDumper(this.options(), this.parseComments(), new StringReader(super.dump())).dump();
}
return contents;
return super.saveToString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ void saveToString() throws IOException {
" string: Hello world\n" +
" boolean: true\n" +
" list:\n" +
" - Each\n" +
" - word\n" +
" - will\n" +
" - be\n" +
" - in\n" +
" - a\n" +
" - separated\n" +
" - entry\n" +
" - Each\n" +
" - word\n" +
" - will\n" +
" - be\n" +
" - in\n" +
" - a\n" +
" - separated\n" +
" - entry\n" +
"math:\n" +
" pi: 3.141592653589793\n" +
"timestamp:\n" +
Expand Down Expand Up @@ -220,14 +220,14 @@ void parseHeader() {
" string: Hello world\n" +
" boolean: true\n" +
" list:\n" +
" - Each\n" +
" - word\n" +
" - will\n" +
" - be\n" +
" - in\n" +
" - a\n" +
" - separated\n" +
" - entry\n" +
" - Each\n" +
" - word\n" +
" - will\n" +
" - be\n" +
" - in\n" +
" - a\n" +
" - separated\n" +
" - entry\n" +
"math:\n" +
" pi: 3.141592653589793\n" +
"timestamp:\n" +
Expand All @@ -237,7 +237,7 @@ void parseHeader() {
MatcherAssert.assertThat(
"Couldn't parse the header of the content!",
YamlConfiguration.parseHeader(content),
new IsEqual<>("test123")
new IsEqual<>("# test123")
);
}

Expand Down
Loading

0 comments on commit d48be3c

Please sign in to comment.