Line break normalization
Osamu TAKEUCHI <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Recently, I implemented a YAML parser, which is going to be
mainly used in Microsoft Windows environments, where the
system default line breaks are "\r\n" instead of "\n".
During that, I had to think about the way to store multi-line
scalar nodes in YAML documents.
At first, I thought the best way is to use the literal style:
%YAML 1.2
---
|2+
abc
def
ghi
...
But I found a description that this document must always be
parsed as "abc\n def\nghi\n" and not as "abc\r\n def\r\nghi\r\n".
> Section 5.4. Line Break Characters
>
> Line breaks inside scalar content must be normalized by the
> YAML processor. Each such line break must be parsed into a
> single line feed character. The original line break format
> is a presentation detail and must not be used to convey
> content information.
I understood the spec wanted to have the meaning of a YAML
document be independent of the environments in which it is
interpreted.
Then, the only way I found to express "abc\r\n def\r\nghi\r\n"
in YAML was:
%YAML 1.2
---
"abc\r\n\
\ def\r\n\
ghi\r\n"
...
This is unacceptably ugly.
But I'm afraid there is no better way to do it with the current
specification. Is there any?
If we discuss some improvement of the specification to solve this
problem, I suggest two solutions.
1. Declaring a YAML processor should normalize line breaks to the
system default line breaks, instead of a single line feed "\n".
This causes the character stream expression of an unescaped text
vary depending on the environment where it is interpreted.
At first glance, this is unacceptable.
But, we should remember that, a YAML processor is allowed to or almost
required to normalize the character encoding of text data in a YAML
document to the system default, "because the character encoding is a
presentation detail and must not be used to convey content information.
(5.2. Character Encodings)"
If line break format is also a presentation detail, the specification
should require line break normalization not always to a single line feed
but to the system default.
2. Introducing a new directive, something like %LINEBREAK.
This will preserves the character stream expression of text data without
explicitely escaping line breaks.
%YAML 1.2
%LINEBREAK "\r\n"
---
|2+
abc
def
ghi
...
I vote to the first option because it is consistent to the way of dealing
with the character encoding, fmm, and %LINEBREAK directive is not good
looking for me.
Best,
Osamu Takeuchi
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july