From 965de3c354c3b21c282d4755902616d6e63c800d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 4 Jan 2010 21:39:35 -0800 Subject: testing scalar encoding supprt --- ext/psych/parser.c | 5 +++++ ext/psych/psych.h | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'ext') diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 7755c80..2b84dbc 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -45,6 +45,7 @@ static VALUE parse(VALUE self, VALUE yaml) } int done = 0; + int encoding = YAML_ANY_ENCODING; VALUE handler = rb_iv_get(self, "@handler"); @@ -60,6 +61,8 @@ static VALUE parse(VALUE self, VALUE yaml) switch(event.type) { case YAML_STREAM_START_EVENT: + encoding = event.data.stream_start.encoding; + rb_funcall(handler, rb_intern("start_stream"), 1, INT2NUM((long)event.data.stream_start.encoding) ); @@ -114,6 +117,8 @@ static VALUE parse(VALUE self, VALUE yaml) (long)event.data.scalar.length ); + PSYCH_ASSOCIATE_ENCODING(val, encoding); + VALUE anchor = event.data.scalar.anchor ? rb_str_new2((const char *)event.data.scalar.anchor) : Qnil; diff --git a/ext/psych/psych.h b/ext/psych/psych.h index 76a826b..aafb17f 100644 --- a/ext/psych/psych.h +++ b/ext/psych/psych.h @@ -4,6 +4,25 @@ #include #include +#define PSYCH_ASSOCIATE_ENCODING(_value, _encoding) \ + ({ \ + switch(_encoding) { \ + case YAML_ANY_ENCODING: \ + break; \ + case YAML_UTF8_ENCODING: \ + rb_enc_associate_index(_value, rb_enc_find_index("UTF-8"));\ + break; \ + case YAML_UTF16LE_ENCODING: \ + rb_enc_associate_index(_value, rb_enc_find_index("UTF-16LE"));\ + break; \ + case YAML_UTF16BE_ENCODING: \ + rb_enc_associate_index(_value, rb_enc_find_index("UTF-16BE"));\ + break; \ + default:\ + break; \ + }\ + }) + #include #include #include @@ -11,4 +30,5 @@ extern VALUE mPsych; + #endif -- cgit v1.2.3