[macruby-changes] [3742] MacRuby/branches/icu/ext/json/rubyext.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 11 16:36:58 PST 2010


Revision: 3742
          http://trac.macosforge.org/projects/ruby/changeset/3742
Author:   lsansonetti at apple.com
Date:     2010-03-11 16:36:56 -0800 (Thu, 11 Mar 2010)
Log Message:
-----------
do not use CF anymore

Modified Paths:
--------------
    MacRuby/branches/icu/ext/json/rubyext.c

Modified: MacRuby/branches/icu/ext/json/rubyext.c
===================================================================
--- MacRuby/branches/icu/ext/json/rubyext.c	2010-03-12 00:19:14 UTC (rev 3741)
+++ MacRuby/branches/icu/ext/json/rubyext.c	2010-03-12 00:36:56 UTC (rev 3742)
@@ -212,15 +212,13 @@
     const unsigned char* buffer;
     unsigned int len;
     rb_json_generator_t* gen = RJSONGenerator(self);
-    
+
     json_encode_part(gen, obj);
     yajl_gen_get_buf(gen->generator, &buffer, &len);
-    
-    VALUE resultBuf = (VALUE)CFStringCreateWithBytes(NULL, (const UInt8*)buffer, len, kCFStringEncodingUTF8, false);
-    CFMakeCollectable((CFTypeRef)resultBuf);
+
+    VALUE res = rb_str_new((const char *)buffer, len);
     yajl_gen_clear(gen->generator);
-    
-    return resultBuf;
+    return res;
 }
 
 static void
@@ -320,8 +318,7 @@
 static int
 yajl_handle_string(void* ctx, const unsigned char* value, unsigned int len)
 {
-    VALUE str = (VALUE)CFStringCreateWithBytes(NULL, (const UInt8*)value, len, kCFStringEncodingUTF8, false);
-    CFMakeCollectable((CFTypeRef)str);
+    VALUE str = rb_str_new((const char *)value, len);
     yajl_set_static_value(ctx, str);
     return 1;
 }
@@ -330,12 +327,11 @@
 yajl_handle_hash_key(void* ctx, const unsigned char* value, unsigned int len)
 {
     rb_json_parser_t* parser = RJSONParser(ctx);
-    
-    VALUE keyStr = (VALUE)CFStringCreateWithBytes(NULL, (const UInt8*)value, len, kCFStringEncodingUTF8, false);
-    CFMakeCollectable((CFTypeRef)keyStr);
-    
+
+    VALUE keyStr = rb_str_new((const char *)value, len); 
+
     if (parser->symbolizeKeys) {
-        ID key = rb_intern(RSTRING_PTR(keyStr));
+        ID key = rb_intern_str(keyStr);
         yajl_set_static_value(ctx, ID2SYM(key));
     }
     else {
@@ -521,15 +517,11 @@
 static VALUE
 rb_object_to_json(VALUE self, SEL sel, int argc, VALUE* argv)
 {
-    VALUE buf, str;
-    
-    str = rb_vm_call_with_cache(to_s_cache, self, sel_to_s, 0, 0);
-    
-    buf = (VALUE)CFStringCreateMutable(NULL, 0);
-    CFMakeCollectable((CFTypeRef)buf);
-    CFStringAppendCString((CFMutableStringRef)buf, "\"", kCFStringEncodingUTF8);
-    CFStringAppend((CFMutableStringRef)buf, (CFStringRef)str);
-    CFStringAppendCString((CFMutableStringRef)buf, "\"", kCFStringEncodingUTF8);
+    VALUE str = rb_vm_call_with_cache(to_s_cache, self, sel_to_s, 0, 0);
+
+    VALUE buf = rb_str_new2("\"");
+    rb_str_concat(buf, str);
+    rb_str_cat2(buf, "\"");
     return buf;
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100311/7c35c084/attachment-0001.html>


More information about the macruby-changes mailing list