jpsim / Yams

A Sweet and Swifty YAML parser.
https://jpsim.com/Yams
MIT License
1.12k stars 144 forks source link

Array / Sequence single-line flow style format encoding option? #339

Closed tatewake closed 2 years ago

tatewake commented 2 years ago

Hi there, I've looked into YAMLEncoder and everything looks great. Did have one request though, to have an option to output arrays / sequences via a single line "flow" style (like so):

items: [a, b, c]

Versus how it currently outputs in "block" format:

items:
  -- a
  -- b
  -- c

I noticed that the YAMLDecoder can accept arrays in either flow / non-flow format, but I don't see any way to get them written in single-line flow format from within YAMLEncoder.

Ideally, this might be something configurable via YAMLEncoder.Options. Perhaps .sequenceStyle = .flow or something similar.

tatewake commented 2 years ago

Hi @jpsim , I've created a PR for this, please see it here. I've tried to make the changes minimally intrusive, but please feel free to make further changes were you might see fit.

jpsim commented 2 years ago

Merged your PR. Thanks again!