tags:

views:

24

answers:

1

Using yaml-cpp, version 0.2.5 ...

I would like to emit a blank line between entries in a list (for readability purposes). Is this possible?

I have tried experimentation with the Verbatim, and Null manipulators, but have not had success.

A: 

As of revision 420, this is possible:

YAML::Emitter emitter;
emitter << YAML::BeginSeq;
emitter << "a" << YAML::Newline << "b" << "c";
emitter << YAML::EndSeq;

produces

---
- a

- b
- c

I decided to go with YAML::Newline instead of YAML::Newline(n) since I found

  1. I usually just wanted a single newline.
  2. I kept accidentally typing YAML::Newline, which implicitly cast the function to a bool (specifically, true), so I figured other people would probably make the same mistake.

If you just want to patch your copy (and not sync with the trunk), use revisions 418-420. (Note: it's slightly trickier than the patch in the link you posted, since you have to be careful about a newline after an implicit key. See the comment on the (now closed) Issue 77 for more details.)

Jesse Beder
Thanks, very much appreciated!
Jeremy Selan
@Jeremy, if you like, you can select this answer as the "correct" answer by clicking the checkmark to the left.
Jesse Beder