summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-01-09 12:37:16 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-01-09 12:37:16 -0800
commit4e684d7b7819163dcd3629c88e23f026ce0ac48f (patch)
tree76b0ba140084e993cb473fb7e78ed8605f267799
parent56e4e0a032b6899b2fdff117a17e6e9d9bcc72e0 (diff)
downloadpsych-4e684d7b7819163dcd3629c88e23f026ce0ac48f.zip
adding encoding support checks
-rw-r--r--Manifest.txt28
-rw-r--r--Rakefile4
-rw-r--r--ext/psych/parser.c24
-rw-r--r--ext/psych/psych.h5
-rw-r--r--lib/psych.rb1
-rw-r--r--lib/psych/yaml.rb (renamed from lib/psych/ruby.rb)0
-rw-r--r--test/helper.rb1
7 files changed, 57 insertions, 6 deletions
diff --git a/Manifest.txt b/Manifest.txt
index e1b1ee3..6e81727 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -10,9 +10,14 @@ ext/psych/parser.c
ext/psych/parser.h
ext/psych/psych.c
ext/psych/psych.h
+ext/psych/to_ruby.c
+ext/psych/to_ruby.h
+ext/psych/yaml_tree.c
+ext/psych/yaml_tree.h
lib/psych.rb
lib/psych/emitter.rb
lib/psych/handler.rb
+lib/psych/nodes.rb
lib/psych/nodes/alias.rb
lib/psych/nodes/document.rb
lib/psych/nodes/mapping.rb
@@ -20,24 +25,41 @@ lib/psych/nodes/node.rb
lib/psych/nodes/scalar.rb
lib/psych/nodes/sequence.rb
lib/psych/nodes/stream.rb
+lib/psych/omap.rb
lib/psych/parser.rb
-lib/psych/ruby.rb
lib/psych/scalar_scanner.rb
+lib/psych/set.rb
lib/psych/tree_builder.rb
lib/psych/visitable.rb
lib/psych/visitors.rb
lib/psych/visitors/emitter.rb
lib/psych/visitors/to_ruby.rb
lib/psych/visitors/visitor.rb
-lib/psych/visitors/yast_builder.rb
+lib/psych/visitors/yaml_tree.rb
+lib/psych/yaml.rb
+test/helper.rb
+test/psych/test_document.rb
+test/psych/test_emitter.rb
+test/psych/test_encoding.rb
test/psych/test_parser.rb
+test/psych/test_scalar.rb
test/psych/test_serialize_subclasses.rb
+test/psych/test_struct.rb
test/psych/test_to_yaml_properties.rb
test/psych/test_tree_builder.rb
test/test_psych.rb
test/test_scalar_scanner.rb
test/visitors/test_emitter.rb
test/visitors/test_to_ruby.rb
-test/visitors/test_yast_builder.rb
+test/visitors/test_yaml_tree.rb
+test/yaml/test_array.rb
+test/yaml/test_boolean.rb
+test/yaml/test_class.rb
+test/yaml/test_exception.rb
+test/yaml/test_hash.rb
+test/yaml/test_null.rb
+test/yaml/test_omap.rb
+test/yaml/test_set.rb
test/yaml/test_string.rb
+test/yaml/test_symbol.rb
test/yaml/test_yaml.rb
diff --git a/Rakefile b/Rakefile
index d5fa904..cd806c4 100644
--- a/Rakefile
+++ b/Rakefile
@@ -3,8 +3,8 @@
$: << File.join(File.dirname(__FILE__), 'lib')
begin
- require 'psych'
- $" << "yaml.rb"
+ #require 'psych'
+ #$" << "yaml.rb"
rescue LoadError
end
diff --git a/ext/psych/parser.c b/ext/psych/parser.c
index fe0c823..c5ecda2 100644
--- a/ext/psych/parser.c
+++ b/ext/psych/parser.c
@@ -58,7 +58,9 @@ static VALUE parse(VALUE self, VALUE yaml)
}
int done = 0;
+#ifdef HAVE_RUBY_ENCODING_H
int encoding = rb_enc_find_index("ASCII-8BIT");
+#endif
VALUE handler = rb_iv_get(self, "@handler");
@@ -75,6 +77,7 @@ static VALUE parse(VALUE self, VALUE yaml)
switch(event.type) {
case YAML_STREAM_START_EVENT:
+#ifdef HAVE_RUBY_ENCODING_H
switch(event.data.stream_start.encoding) {
case YAML_ANY_ENCODING:
break;
@@ -90,6 +93,7 @@ static VALUE parse(VALUE self, VALUE yaml)
default:
break;
}
+#endif
rb_funcall(handler, id_start_stream, 1,
INT2NUM((long)event.data.stream_start.encoding)
@@ -116,13 +120,17 @@ static VALUE parse(VALUE self, VALUE yaml)
VALUE handle = Qnil;
if(start->handle) {
handle = rb_str_new2((const char *)start->handle);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(handle, encoding);
+#endif
}
VALUE prefix = Qnil;
if(start->prefix) {
prefix = rb_str_new2((const char *)start->prefix);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(prefix, encoding);
+#endif
}
VALUE pair = rb_ary_new3((long)2, handle, prefix);
@@ -145,7 +153,9 @@ static VALUE parse(VALUE self, VALUE yaml)
VALUE alias = Qnil;
if(event.data.alias.anchor) {
alias = rb_str_new2((const char *)event.data.alias.anchor);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(alias, encoding);
+#endif
}
rb_funcall(handler, id_alias, 1, alias);
@@ -158,18 +168,24 @@ static VALUE parse(VALUE self, VALUE yaml)
(long)event.data.scalar.length
);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(val, encoding);
+#endif
VALUE anchor = Qnil;
if(event.data.scalar.anchor) {
anchor = rb_str_new2((const char *)event.data.scalar.anchor);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(anchor, encoding);
+#endif
}
VALUE tag = Qnil;
if(event.data.scalar.tag) {
tag = rb_str_new2((const char *)event.data.scalar.tag);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(tag, encoding);
+#endif
}
VALUE plain_implicit =
@@ -189,13 +205,17 @@ static VALUE parse(VALUE self, VALUE yaml)
VALUE anchor = Qnil;
if(event.data.sequence_start.anchor) {
anchor = rb_str_new2((const char *)event.data.sequence_start.anchor);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(anchor, encoding);
+#endif
}
VALUE tag = Qnil;
if(event.data.sequence_start.tag) {
tag = rb_str_new2((const char *)event.data.sequence_start.tag);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(tag, encoding);
+#endif
}
VALUE implicit =
@@ -215,13 +235,17 @@ static VALUE parse(VALUE self, VALUE yaml)
VALUE anchor = Qnil;
if(event.data.mapping_start.anchor) {
anchor = rb_str_new2((const char *)event.data.mapping_start.anchor);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(anchor, encoding);
+#endif
}
VALUE tag = Qnil;
if(event.data.mapping_start.tag) {
tag = rb_str_new2((const char *)event.data.mapping_start.tag);
+#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(tag, encoding);
+#endif
}
VALUE implicit =
diff --git a/ext/psych/psych.h b/ext/psych/psych.h
index bbc92cb..9f1be44 100644
--- a/ext/psych/psych.h
+++ b/ext/psych/psych.h
@@ -2,6 +2,11 @@
#define PSYCH_H
#include <ruby.h>
+
+#ifdef HAVE_RUBY_ENCODING_H
+#include <ruby/encoding.h>
+#endif
+
#include <yaml.h>
#include <parser.h>
diff --git a/lib/psych.rb b/lib/psych.rb
index 6419dbb..ed9321e 100644
--- a/lib/psych.rb
+++ b/lib/psych.rb
@@ -6,7 +6,6 @@ require 'psych/visitors'
require 'psych/handler'
require 'psych/tree_builder'
require 'psych/parser'
-require 'psych/ruby'
require 'psych/omap'
require 'psych/set'
diff --git a/lib/psych/ruby.rb b/lib/psych/yaml.rb
index 3a2e124..3a2e124 100644
--- a/lib/psych/ruby.rb
+++ b/lib/psych/yaml.rb
diff --git a/test/helper.rb b/test/helper.rb
index 0ca324c..c271650 100644
--- a/test/helper.rb
+++ b/test/helper.rb
@@ -1,2 +1,3 @@
require 'test/unit'
require 'psych'
+require 'psych/yaml'