[macruby-changes] [2825] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Oct 15 18:30:43 PDT 2009


Revision: 2825
          http://trac.macosforge.org/projects/ruby/changeset/2825
Author:   neeracher at apple.com
Date:     2009-10-15 18:30:42 -0700 (Thu, 15 Oct 2009)
Log Message:
-----------
Handle UTF-16 encoded strings passed to YAML

Modified Paths:
--------------
    MacRuby/trunk/ext/libyaml/rubyext.c
    MacRuby/trunk/spec/frozen/library/yaml/to_yaml_spec.rb

Modified: MacRuby/trunk/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/trunk/ext/libyaml/rubyext.c	2009-10-16 01:27:38 UTC (rev 2824)
+++ MacRuby/trunk/ext/libyaml/rubyext.c	2009-10-16 01:30:42 UTC (rev 2825)
@@ -162,10 +162,10 @@
 		    rb_bytestring_length(input));
 	}
 	else if (TYPE(input) == T_STRING) {
-	    // TODO: Make sure that this is Unicode-aware.
+	    const char * instring = RSTRING_PTR(input);
 	    yaml_parser_set_input_string(parser,
-		    (const unsigned char *)(RSTRING_PTR(input)),
-		    RSTRING_LEN(input));			
+		    (const unsigned char *)(instring),
+		    strlen(instring));			
 	}
 	else if (TYPE(input) == T_FILE) {
 	    yaml_parser_set_input(parser, rb_yaml_io_read_handler,
@@ -729,7 +729,7 @@
 
     int can_omit_tag = 0;
     yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag);
-    yaml_scalar_event_initialize(&ev, NULL, tag, output, RSTRING_LEN(val),
+    yaml_scalar_event_initialize(&ev, NULL, tag, output, strlen(output),
 	    can_omit_tag, can_omit_tag, rb_symbol_to_scalar_style(style));
     yaml_emitter_emit(emitter, &ev);
 

Modified: MacRuby/trunk/spec/frozen/library/yaml/to_yaml_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/yaml/to_yaml_spec.rb	2009-10-16 01:27:38 UTC (rev 2824)
+++ MacRuby/trunk/spec/frozen/library/yaml/to_yaml_spec.rb	2009-10-16 01:30:42 UTC (rev 2825)
@@ -53,6 +53,14 @@
     "I love Ruby".to_yaml.should == "--- I love Ruby\n"
   end
 
+  it "returns correct escape characters for non-ASCII Unicode characters" do
+    #
+    # Not sure if this belongs here? MN
+    #
+    str = YAML.load('--- "\U000000A9\U00002117\U0001D122"')
+    str.to_yaml.chomp.should == '--- "\xA9\u2117\U0001D122"'
+  end
+
   it "returns the YAML representation of a Struct object" do
     Person = Struct.new(:name, :gender)
     Person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct:Person\nname: Jane\ngender: female\n")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091015/99317d97/attachment.html>


More information about the macruby-changes mailing list