diff options
author | Kirill Simonov <xi@resolvent.net> | 2008-12-27 19:14:00 +0000 |
---|---|---|
committer | Kirill Simonov <xi@resolvent.net> | 2008-12-27 19:14:00 +0000 |
commit | 561ca6de7b3ee25f67e440b842b4aa1eb59a33c5 (patch) | |
tree | 1cf6af03e8ce858b81194d916b62509421bc4fe5 | |
parent | 40cc5d1517fdaf39d751add86085706a7e1568aa (diff) | |
download | libyaml-hg-561ca6de7b3ee25f67e440b842b4aa1eb59a33c5.tar.gz |
Fixed emitting folded scalars with trailing breaks; Forced emitting of a document end indicator when there is a possibility of ambiguous parsing.
-rw-r--r-- | include/yaml.h | 2 | ||||
-rw-r--r-- | src/emitter.c | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/include/yaml.h b/include/yaml.h index d0fe93c..400cae1 100644 --- a/include/yaml.h +++ b/include/yaml.h @@ -1680,6 +1680,8 @@ typedef struct yaml_emitter_s { int whitespace; /** If the last character was an indentation character (' ', '-', '?', ':')? */ int indention; + /** If an explicit document end is required? */ + int open_ended; /** Anchor analysis. */ struct { diff --git a/src/emitter.c b/src/emitter.c index b698714..e4e3d26 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -587,6 +587,17 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter, implicit = 0; } + if ((event->data.document_start.version_directive || + (event->data.document_start.tag_directives.start + != event->data.document_start.tag_directives.end)) && + emitter->open_ended) + { + if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) + return 0; + if (!yaml_emitter_write_indent(emitter)) + return 0; + } + if (event->data.document_start.version_directive) { implicit = 0; if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) @@ -638,6 +649,14 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter, else if (event->type == YAML_STREAM_END_EVENT) { + if (emitter->open_ended) + { + if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) + return 0; + if (!yaml_emitter_write_indent(emitter)) + return 0; + } + if (!yaml_emitter_flush(emitter)) return 0; @@ -1765,6 +1784,7 @@ yaml_emitter_write_indicator(yaml_emitter_t *emitter, emitter->whitespace = is_whitespace; emitter->indention = (emitter->indention && is_indention); + emitter->open_ended = 0; return 1; } @@ -1902,6 +1922,10 @@ yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, emitter->whitespace = 0; emitter->indention = 0; + if (emitter->root_context) + { + emitter->open_ended = 1; + } return 1; } @@ -2136,6 +2160,8 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, return 0; } + emitter->open_ended = 0; + string.pointer = string.end; if (string.start == string.pointer) { @@ -2153,6 +2179,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, else if (string.start == string.pointer) { chomp_hint = "+"; + emitter->open_ended = 1; } else { @@ -2162,6 +2189,7 @@ yaml_emitter_write_block_scalar_hints(yaml_emitter_t *emitter, if (IS_BREAK(string)) { chomp_hint = "+"; + emitter->open_ended = 1; } } } @@ -2237,7 +2265,7 @@ yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, while (IS_BREAK_AT(string, k)) { k += WIDTH_AT(string, k); } - if (!IS_BLANK_AT(string, k)) { + if (!IS_BLANKZ_AT(string, k)) { if (!PUT_BREAK(emitter)) return 0; } } |