Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uneven spacing between tables #152

Closed
nulaft opened this issue Mar 27, 2021 · 3 comments
Closed

Uneven spacing between tables #152

nulaft opened this issue Mar 27, 2021 · 3 comments

Comments

@nulaft
Copy link

nulaft commented Mar 27, 2021

I'm using the latest release, toml11-3.6.1. This code:

#define TOML11_DISABLE_STD_FILESYSTEM
#include <toml.hpp>
#include <iostream>

int main()
{
    toml::value data {
        {"A", toml::value{{"a", 1}}},
        {"B", toml::value{{"b", 2}}},
        {"C", toml::value{{"c", 3}}},
        {"D", toml::value{{"d", 4}}}
    };

    std::cout << data;

    return 0;
}

Produces this serialized output:

[D]
d = 4
[C]
c = 3

[B]
b = 2

[A]
a = 1

For some reason, the serializer doesn't add an empty line between the first and second table. Should be easy to fix? I had a quick look but coudn't find why it does that.

ToruNiina added a commit that referenced this issue Mar 29, 2021
@ToruNiina
Copy link
Owner

I guess I have fixed it. After checking CI status, I will merge it.

@nulaft
Copy link
Author

nulaft commented Mar 30, 2021

It solves the problem partially. I have a new test case:

#define TOML11_DISABLE_STD_FILESYSTEM
#include "../toml11-3.6.1/toml.hpp"
#include <iostream>

int main()
{
    toml::value data {
        {"O", 0},
        {"A", toml::value{{"a", 1}}},
        {"B", toml::value{{"b", 3}, {"C", toml::value{{"c", 2}}}}},
        {"D", toml::value{{"d", 4}}}
    };

    std::cout << data;

    return 0;
}

Which formats like this:

O = 0
[D]
d = 4

[B]
b = 3
[B.C]
c = 2


[A]
a = 1

I think it should space it like this. Whether or not there should be an empty line before [B.C] is down to taste...

O = 0

[D]
d = 4

[B]
b = 3
[B.C]
c = 2

[A]
a = 1

@ToruNiina
Copy link
Owner

I added another patch to format your example in the following way.

O = 0

[B]
b = 3

[B.C]
c = 2

[D]
d = 4

[A]
a = 1

Although it is not completely the same as your proposal (it has an empty line between [B] and [B.C]), I'm going to add this as a quick fix. The reason is because it would be a bit more complicated to control the number of empty lines depending on the recursion level and, moreover, the optimal format depends on the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants