Please note, that the question is similar like this one, but still different so that those answers won't solve my problem:
- For insertion of control characters like e.g.
\x08
, it seems that I have to use double quotes"
. - All spaces needs to be preserved exactly as given. For line breaks I use explicitly
\n
.
I have some string data which I need to store in YAML, e.g.:
" This is my quite long string data "
"This is my quite long string data"
"This_is_my_quite_long_string_data"
"Sting data\nwhich\x08contains control characters"
and need it in YAML as something like this:
Key: " This is my" +
" quite long " +
" string data "
This is no problem as long as I stay on a single line, but I don't know how to put the string content to multiple lines.
YAML block scalar styles (>
, |
) won't help here, because they don't allow escaping and they even do some whitespace stripping, newline / space substitution which is useless for my case.
Looks that the only way seems to be using double quoting "
and backslashes \
, like this:
Key: "\
This is \
my quite \
long string data\
"
Trying this in YAML online parser results in "This is my quite long string data"
as expected.
But it unfortunately fail if one of the "sub-lines" has leading space, like this:
Key: "\
This is \
my quite\
long st\
ring data\
"
This results in "This is my quitelong string data"
, removed the space between the words quite
and long
of this example. The only thing that comes to my mind to solve that, is to replace the first leading space of each sub-line by \x20
like this:
Key: "\
This is \
my quite\
\x20long st\
ring data\
"
As I'd chosen YAML to have a best possible human readable format, I find that \x20
a bit ugly solution. Maybe someone know a better approach?
For keeping human readable, I also don't want to use !!binary
for this.
Answer
Instead of \x20
, you can simply escape the first non-indentation space on the line:
Key: "\
This is \
my quite\
\ long st\
ring data\
"
This works with multiple spaces, you only need to escape the first one.
No comments:
Post a Comment