]> andersk Git - libyaml.git/commitdiff
Fixed emitting folded scalars with trailing breaks; Forced emitting of a document...
authorKirill Simonov <xi@resolvent.net>
Sat, 27 Dec 2008 19:14:00 +0000 (19:14 +0000)
committerKirill Simonov <xi@resolvent.net>
Sat, 27 Dec 2008 19:14:00 +0000 (19:14 +0000)
include/yaml.h
src/emitter.c

index d0fe93c800549aaa8d67e9e2f37157bcccb52d4c..400cae1ead5953521529d9c90b6dce5d704cb5dd 100644 (file)
@@ -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 {
index b698714a88593894751906923b8a0904c2d5fac2..e4e3d2612b5e055965fc75eb95c953154ba7b290 100644 (file)
@@ -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;
                 }
             }
This page took 1.257634 seconds and 5 git commands to generate.