Created
July 28, 2010 23:01
-
-
Save jballanc/496642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/encoding.c b/encoding.c | |
index 82ffb39..2fe275d 100644 | |
--- a/encoding.c | |
+++ b/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]; | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment