[macruby-changes] [2787] MacRuby/trunk/ext/libyaml/rubyext.c

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 12 22:58:36 PDT 2009


Revision: 2787
          http://trac.macosforge.org/projects/ruby/changeset/2787
Author:   lsansonetti at apple.com
Date:     2009-10-12 22:58:35 -0700 (Mon, 12 Oct 2009)
Log Message:
-----------
implement :inline format for YAML sequences and mappings (patch by Matthias Neeracher)

Modified Paths:
--------------
    MacRuby/trunk/ext/libyaml/rubyext.c

Modified: MacRuby/trunk/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/trunk/ext/libyaml/rubyext.c	2009-10-13 03:48:56 UTC (rev 2786)
+++ MacRuby/trunk/ext/libyaml/rubyext.c	2009-10-13 05:58:35 UTC (rev 2787)
@@ -104,6 +104,7 @@
 
 static ID id_plain;
 static ID id_quote2;
+static ID id_inline;
 
 static SEL sel_to_yaml;
 static SEL sel_call;
@@ -527,6 +528,32 @@
     return style;
 }
 
+static yaml_scalar_style_t
+rb_symbol_to_sequence_style(VALUE sym)
+{
+    yaml_sequence_style_t style = YAML_ANY_SEQUENCE_STYLE;
+    if (NIL_P(sym)) {
+	return style;
+    }
+    else if (rb_to_id(sym) == id_inline) {
+	style = YAML_FLOW_SEQUENCE_STYLE;
+    }
+    return style;
+}
+
+static yaml_scalar_style_t
+rb_symbol_to_mapping_style(VALUE sym)
+{
+    yaml_mapping_style_t style = YAML_ANY_MAPPING_STYLE;
+    if (NIL_P(sym)) {
+	return style;
+    }
+    else if (rb_to_id(sym) == id_inline) {
+	style = YAML_FLOW_MAPPING_STYLE;
+    }
+    return style;
+}
+
 static yaml_char_t*
 rb_yaml_tag_or_null(VALUE tagstr, int *can_omit_tag)
 {
@@ -663,7 +690,7 @@
     int can_omit_tag = 0;
     yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag);
     yaml_sequence_start_event_initialize(&ev, NULL, tag, can_omit_tag,
-	    YAML_ANY_SEQUENCE_STYLE);
+	    rb_symbol_to_sequence_style(style));
     yaml_emitter_emit(emitter, &ev);
 
     rb_yield(self);
@@ -682,7 +709,7 @@
     int can_omit_tag = 0;
     yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag);
     yaml_mapping_start_event_initialize(&ev, NULL, tag, can_omit_tag,
-	    YAML_ANY_MAPPING_STYLE);
+	    rb_symbol_to_mapping_style(style));
     yaml_emitter_emit(emitter, &ev);
 
     rb_yield(self);
@@ -775,6 +802,7 @@
 {
     id_plain = rb_intern("plain");
     id_quote2 = rb_intern("quote2");
+    id_inline = rb_intern("inline");
 
     sel_to_yaml = sel_registerName("to_yaml:");
     sel_call = sel_registerName("call:");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091012/7bfba678/attachment.html>


More information about the macruby-changes mailing list