Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implement some of the MRI encoding index APIs

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4389 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit 020297798fe930f1ecf013fec6916c832cd79764 1 parent 97080bb
Laurent Sansonetti authored
Showing with 46 additions and 0 deletions.
  1. +43 −0 encoding.c
  2. +3 −0  include/ruby/encoding.h
View
43 encoding.c
@@ -484,3 +484,46 @@ rb_enc_set_default_external(VALUE encoding)
default_external = RENC(encoding);
}
+static int
+index_of_encoding(rb_encoding_t *enc)
+{
+ if (enc != NULL) {
+ for (int i = 0; i <ENCODINGS_COUNT; i++) {
+ if (rb_encodings[i] == enc) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+int
+rb_enc_get_index(VALUE obj)
+{
+ return index_of_encoding(rb_enc_get(obj));
+}
+
+int
+rb_enc_find_index(const char *name)
+{
+ return index_of_encoding(rb_enc_find(name));
+}
+
+int
+rb_ascii8bit_encindex(void)
+{
+ return index_of_encoding(rb_encodings[ENCODING_BINARY]);
+}
+
+int
+rb_utf8_encindex(void)
+{
+ return index_of_encoding(rb_encodings[ENCODING_UTF8]);
+}
+
+int
+rb_usascii_encindex(void)
+{
+ return index_of_encoding(rb_encodings[ENCODING_ASCII]);
+}
+
View
3  include/ruby/encoding.h
@@ -26,6 +26,9 @@ int rb_enc_get_index(VALUE obj);
void rb_enc_set_index(VALUE obj, int encindex);
int rb_enc_find_index(const char *name);
int rb_to_encoding_index(VALUE);
+int rb_ascii8bit_encindex(void);
+int rb_utf8_encindex(void);
+int rb_usascii_encindex(void);
rb_encoding* rb_to_encoding(VALUE);
rb_encoding* rb_enc_get(VALUE);
rb_encoding* rb_enc_compatible(VALUE,VALUE);
Please sign in to comment.
Something went wrong with that request. Please try again.