Skip to content
Browse files

Implement a few more of the MRI encoding APIs

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4390 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 0202977 commit 508b43fce8089d6e38819097469894cb904165ee @jballanc jballanc committed
Showing with 33 additions and 0 deletions.
  1. +33 −0 encoding.c
View
33 encoding.c
@@ -484,6 +484,12 @@ rb_enc_set_default_external(VALUE encoding)
default_external = RENC(encoding);
}
+rb_encoding *
+rb_default_internal_encoding(void)
+{
+ return (rb_encoding *)default_internal;
+}
+
static int
index_of_encoding(rb_encoding_t *enc)
{
@@ -504,6 +510,27 @@ rb_enc_get_index(VALUE obj)
}
int
+rb_to_encoding_index(VALUE enc)
+{
+ if (CLASS_OF(enc) != rb_cEncoding && TYPE(enc) != T_STRING) {
+ return -1;
+ }
+ else {
+ int idx = index_of_encoding(rb_enc_get(enc));
+ if (idx >= 0) {
+ return idx;
+ }
+ else if (NIL_P(enc = rb_check_string_type(enc))) {
+ return -1;
+ }
+ if (!rb_enc_asciicompat(rb_enc_get(enc))) {
+ return -1;
+ }
+ return rb_enc_find_index(StringValueCStr(enc));
+ }
+}
+
+int
rb_enc_find_index(const char *name)
{
return index_of_encoding(rb_enc_find(name));
@@ -527,3 +554,9 @@ rb_usascii_encindex(void)
return index_of_encoding(rb_encodings[ENCODING_ASCII]);
}
+rb_encoding *
+rb_enc_from_index(int idx)
+{
+ assert(idx >= 0 && idx < ENCODINGS_COUNT);
+ return rb_encodings[idx];
+}

0 comments on commit 508b43f

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