summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-01-04 21:39:35 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-01-04 21:39:35 -0800
commit965de3c354c3b21c282d4755902616d6e63c800d (patch)
tree83a07737a52c61cdfc6950fb7956be1a7bf5ece3 /ext
parent37e694a25f2b545a64032fa75f25e9fa2ad6fa9b (diff)
downloadpsych-965de3c354c3b21c282d4755902616d6e63c800d.zip
testing scalar encoding supprt
Diffstat (limited to 'ext')
-rw-r--r--ext/psych/parser.c5
-rw-r--r--ext/psych/psych.h20
2 files changed, 25 insertions, 0 deletions
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 <ruby.h>
#include <yaml.h>
+#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 <parser.h>
#include <emitter.h>
#include <to_ruby.h>
@@ -11,4 +30,5 @@
extern VALUE mPsych;
+
#endif