开发者

How to emit a blank line using yaml-cpp

开发者 https://www.devze.com 2023-01-20 21:48 出处:网络
Using yaml-cpp, version 0.2.5 ... I would like to emit a blank line between entries in a list (for readability purposes).

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 开发者_StackOverflow社区have tried experimentation with the Verbatim, and Null manipulators, but have not had success.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消