Skip to content
This repository
Browse code

added #find

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/icu@3727 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 4ede6523c72b94099704576df5b758ed8b530fe9 1 parent 96b3e87
authored March 10, 2010

Showing 1 changed file with 19 additions and 7 deletions. Show diff stats Hide diff stats

  1. 26  encoding.c
26  encoding.c
@@ -69,6 +69,18 @@ mr_enc_s_aliases(VALUE klass, SEL sel)
69 69
 }
70 70
 
71 71
 static VALUE
  72
+mr_enc_s_find(VALUE klass, SEL sel, VALUE name)
  73
+{
  74
+    StringValue(name);
  75
+    rb_encoding_t *enc = rb_enc_find(RSTRING_PTR(name));
  76
+    if (enc == NULL) {
  77
+	rb_raise(rb_eArgError, "unknown encoding name - %s",
  78
+		RSTRING_PTR(name));
  79
+    }
  80
+    return (VALUE)enc;
  81
+}
  82
+
  83
+static VALUE
72 84
 mr_enc_s_default_internal(VALUE klass, SEL sel)
73 85
 {
74 86
     return (VALUE)default_internal;
@@ -260,22 +272,22 @@ Init_Encoding(void)
260 272
     rb_objc_define_method(rb_cEncoding, "dummy?", mr_enc_dummy_p, 0);
261 273
     rb_objc_define_method(rb_cEncoding, "ascii_compatible?",
262 274
 	    mr_enc_ascii_compatible_p, 0);
263  
-    rb_objc_define_method(CLASS_OF(rb_cEncoding), "list", mr_enc_s_list, 0);
264  
-    rb_objc_define_method(CLASS_OF(rb_cEncoding), "name_list",
  275
+    rb_objc_define_method(*(VALUE *)rb_cEncoding, "list", mr_enc_s_list, 0);
  276
+    rb_objc_define_method(*(VALUE *)rb_cEncoding, "name_list",
265 277
 	    mr_enc_s_name_list, 0);
266  
-    rb_objc_define_method(CLASS_OF(rb_cEncoding), "aliases",
  278
+    rb_objc_define_method(*(VALUE *)rb_cEncoding, "aliases",
267 279
 	    mr_enc_s_aliases, 0);
268  
-    //rb_define_singleton_method(rb_cEncoding, "find", enc_find, 1);
269  
-    rb_objc_define_method(CLASS_OF(rb_cEncoding), "compatible?",
  280
+    rb_objc_define_method(*(VALUE *)rb_cEncoding, "find", mr_enc_s_find, 1);
  281
+    rb_objc_define_method(*(VALUE *)rb_cEncoding, "compatible?",
270 282
 	    mr_enc_s_is_compatible, 2); // in string.c
271 283
 
272 284
     //rb_define_method(rb_cEncoding, "_dump", enc_dump, -1);
273 285
     //rb_define_singleton_method(rb_cEncoding, "_load", enc_load, 1);
274 286
 
275  
-    rb_objc_define_method(CLASS_OF(rb_cEncoding), "default_external",
  287
+    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_external",
276 288
 	    mr_enc_s_default_external, 0);
277 289
     //rb_define_singleton_method(rb_cEncoding, "default_external=", set_default_external, 1);
278  
-    rb_objc_define_method(CLASS_OF(rb_cEncoding), "default_internal",
  290
+    rb_objc_define_method(*(VALUE *)rb_cEncoding, "default_internal",
279 291
 	    mr_enc_s_default_internal, 0);
280 292
     //rb_define_singleton_method(rb_cEncoding, "default_internal=", set_default_internal, 1);
281 293
     //rb_define_singleton_method(rb_cEncoding, "locale_charmap", rb_locale_charmap, 0);

0 notes on commit 4ede652

Please sign in to comment.
Something went wrong with that request. Please try again.