diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-28 20:53:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-09-28 20:53:06 -0700 |
commit | 780b789a2fb985ac8ae24eab21eb939293524542 (patch) | |
tree | 4eb755e1731e8773edf521fd3f5175aff15048a1 /ext | |
parent | b8e82a04568ec154154af68614f077d7a754bf8a (diff) | |
download | psych-780b789a2fb985ac8ae24eab21eb939293524542.zip |
adding emitter codes
Diffstat (limited to 'ext')
-rw-r--r-- | ext/psych/emitter.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ext/psych/emitter.c b/ext/psych/emitter.c index c48a8b5..1199a31 100644 --- a/ext/psych/emitter.c +++ b/ext/psych/emitter.c @@ -40,6 +40,62 @@ static VALUE start_stream(VALUE self, VALUE encoding) yaml_event_t event; yaml_stream_start_event_initialize(&event, NUM2INT(encoding)); + yaml_emitter_emit(emitter, &event); + return self; +} + +static VALUE end_stream(VALUE self) +{ + yaml_emitter_t * emitter; + Data_Get_Struct(self, yaml_emitter_t, emitter); + + yaml_event_t event; + yaml_stream_end_event_initialize(&event); + yaml_emitter_emit(emitter, &event); + return self; +} + +static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp) +{ + yaml_emitter_t * emitter; + Data_Get_Struct(self, yaml_emitter_t, emitter); + + yaml_version_directive_t version_directive; + + if(RARRAY_LEN(version) > 0) { + VALUE major = rb_ary_entry(version, 0); + VALUE minor = rb_ary_entry(version, 1); + + version_directive.major = NUM2INT(major); + version_directive.minor = NUM2INT(minor); + } + + yaml_event_t event; + yaml_document_start_event_initialize( + &event, + &version_directive, + NULL, + NULL, + imp == Qtrue ? 1 : 0 + ); + + yaml_emitter_emit(emitter, &event); + + return self; +} + +static VALUE end_document(VALUE self, VALUE imp) +{ + yaml_emitter_t * emitter; + Data_Get_Struct(self, yaml_emitter_t, emitter); + + yaml_version_directive_t version_directive; + + yaml_event_t event; + yaml_document_end_event_initialize(&event, imp == Qtrue ? 1 : 0); + + yaml_emitter_emit(emitter, &event); + return self; } @@ -53,4 +109,7 @@ void Init_psych_emitter() rb_define_method(cPsychEmitter, "initialize", initialize, 1); rb_define_method(cPsychEmitter, "start_stream", start_stream, 1); + rb_define_method(cPsychEmitter, "end_stream", end_stream, 0); + rb_define_method(cPsychEmitter, "start_document", start_document, 3); + rb_define_method(cPsychEmitter, "end_document", end_document, 1); } |