Skip to content

Commit

Permalink
don't emit empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
archi committed Jun 16, 2020
1 parent f8877cb commit bea9732
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/lib/WritePluginIni.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,27 @@ sub write {
my $first = 1;
foreach my $k (sort keys %{$result}) {
next if not defined $result->{$k};
print $OUT ",\n" if not $first;
$first = 0;

print $OUT "\"$k\":";
my $type = ref $result->{$k};
if ($type eq "") {
print $OUT $result->{$k};
print $OUT ",\n" if not $first;
$first = 0;

print $OUT "\"$k\":", $result->{$k};
} elsif ($type eq "ARRAY") {
my $cnt = scalar @{$result->{$k}};
next if $cnt == 0;

print $OUT ",\n" if not $first;
$first = 0;
print $OUT "\"$k\":[";

my $insert_line_break = 4096;
my $prefix = "";
if ($cnt > $nchn and $cnt % $nchn == 0) {
$insert_line_break = $cnt / $nchn;
$prefix = sprintf("%".(length($k)+4)."s", "");
}
print $OUT "[";

my $afirst = 1;
foreach my $a (@{$result->{$k}}) {
if ($insert_line_break == 0) {
Expand Down

0 comments on commit bea9732

Please sign in to comment.