[macruby-changes] [4389] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jul 28 13:23:22 PDT 2010
Revision: 4389
http://trac.macosforge.org/projects/ruby/changeset/4389
Author: lsansonetti at apple.com
Date: 2010-07-28 13:23:22 -0700 (Wed, 28 Jul 2010)
Log Message:
-----------
implement some of the MRI encoding index APIs
Modified Paths:
--------------
MacRuby/trunk/encoding.c
MacRuby/trunk/include/ruby/encoding.h
Modified: MacRuby/trunk/encoding.c
===================================================================
--- MacRuby/trunk/encoding.c 2010-07-28 19:47:07 UTC (rev 4388)
+++ MacRuby/trunk/encoding.c 2010-07-28 20:23:22 UTC (rev 4389)
@@ -484,3 +484,46 @@
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]);
+}
+
Modified: MacRuby/trunk/include/ruby/encoding.h
===================================================================
--- MacRuby/trunk/include/ruby/encoding.h 2010-07-28 19:47:07 UTC (rev 4388)
+++ MacRuby/trunk/include/ruby/encoding.h 2010-07-28 20:23:22 UTC (rev 4389)
@@ -26,6 +26,9 @@
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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100728/7f7c21ce/attachment-0001.html>
More information about the macruby-changes
mailing list