Permalink
Browse files

adding 2 more frightening MRI methods

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4393 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 508b43f commit 583e43359238fff9e7dd7e1728622366080eded6 @lrz lrz committed Jul 30, 2010
Showing with 22 additions and 0 deletions.
  1. +11 −0 encoding.c
  2. +11 −0 string.c
View
@@ -560,3 +560,14 @@ rb_enc_from_index(int idx)
assert(idx >= 0 && idx < ENCODINGS_COUNT);
return rb_encodings[idx];
}
+
+VALUE
+rb_enc_associate_index(VALUE obj, int idx)
+{
+ if (TYPE(obj) == T_STRING) {
+ assert(idx >= 0 && idx < ENCODINGS_COUNT);
+ rb_str_force_encoding(obj, rb_encodings[idx]);
+ return obj;
+ }
+ rb_raise(rb_eArgError, "cannot set encoding on non-string object");
+}
View
@@ -6567,3 +6567,14 @@ rb_enc_associate(VALUE str, rb_encoding *enc)
RSTR(str)->encoding = enc;
return str;
}
+
+VALUE
+rb_str_export_to_enc(VALUE str, rb_encoding *enc)
+{
+ if (!IS_RSTR(str)) {
+ rb_raise(rb_eArgError, "cannot transcode NSString");
+ }
+ return (VALUE)str_transcode(RSTR(str), RSTR(str)->encoding, enc,
+ TRANSCODE_BEHAVIOR_RAISE_EXCEPTION,
+ TRANSCODE_BEHAVIOR_RAISE_EXCEPTION, NULL);
+}

0 comments on commit 583e433

Please sign in to comment.