summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/psych/parser.c21
-rw-r--r--ext/psych/psych.h19
2 files changed, 18 insertions, 22 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index 2b84dbc..0ea7dd2 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -45,7 +45,7 @@ static VALUE parse(VALUE self, VALUE yaml)
}
int done = 0;
- int encoding = YAML_ANY_ENCODING;
+ int encoding = rb_enc_find_index("ASCII-8BIT");
VALUE handler = rb_iv_get(self, "@handler");
@@ -61,7 +61,22 @@ static VALUE parse(VALUE self, VALUE yaml)
switch(event.type) {
case YAML_STREAM_START_EVENT:
- encoding = event.data.stream_start.encoding;
+
+ switch(event.data.stream_start.encoding) {
+ case YAML_ANY_ENCODING:
+ break;
+ case YAML_UTF8_ENCODING:
+ encoding = rb_enc_find_index("UTF-8");
+ break;
+ case YAML_UTF16LE_ENCODING:
+ encoding = rb_enc_find_index("UTF-16LE");
+ break;
+ case YAML_UTF16BE_ENCODING:
+ encoding = rb_enc_find_index("UTF-16BE");
+ break;
+ default:
+ break;
+ }
rb_funcall(handler, rb_intern("start_stream"), 1,
INT2NUM((long)event.data.stream_start.encoding)
@@ -117,7 +132,7 @@ static VALUE parse(VALUE self, VALUE yaml)
(long)event.data.scalar.length
);
- PSYCH_ASSOCIATE_ENCODING(val, encoding);
+ rb_enc_associate_index(val, encoding);
VALUE anchor = event.data.scalar.anchor ?
rb_str_new2((const char *)event.data.scalar.anchor) :
diff --git a/ext/psych/psych.h b/ext/psych/psych.h
index aafb17f..bbc92cb 100644
--- a/ext/psych/psych.h
+++ b/ext/psych/psych.h
@@ -4,25 +4,6 @@
#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>