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

How to know if the ryml::Tree is empty? #272

Open
VolodymyrKuksa opened this issue Jul 3, 2022 · 3 comments
Open

How to know if the ryml::Tree is empty? #272

VolodymyrKuksa opened this issue Jul 3, 2022 · 3 comments

Comments

@VolodymyrKuksa
Copy link

Hello!

I've got this use case for the rapidyaml library:

char data[] = "";
ryml::Tree tree = ryml::parse_in_place(ryml::to_substr(data));
std::cout << "tree.empty() = " << tree.empty() << '\n';

The output for which is tree.empty() = 0. Apparently the m_size member of ryml::Tree is set to 1 after parsing.
How do I check if the input text contains no yaml nodes? Am I misusing rapidyaml?

The version I'm using is 0.4.1 (the latest release), built as a single header library.

@biojppm
Copy link
Owner

biojppm commented Jul 3, 2022

Yes, this is a nagging corner case that requires attention. IIRC the parser will always create the root node, thus causing this behavior.

As a workaround, you can query the number of children of the root node.

@VolodymyrKuksa
Copy link
Author

Got it, thanks for the quick reply!
Awesome library!

@biojppm biojppm reopened this Jul 4, 2022
@biojppm
Copy link
Owner

biojppm commented Jul 4, 2022

Let's not close this yet. This issue is something that should be addressed, at the very least by clarifying it in the docs, and preferably by having a behavior that is less surprising.

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