ruby-changes:2152
From: ko1@a...
Date: 6 Oct 2007 14:56:21 +0900
Subject: [ruby-changes:2152] nobu - Ruby:r13643 (trunk): * encoding.c (rb_enc_register): returns new index or -1 if failed.
nobu 2007-10-06 14:56:09 +0900 (Sat, 06 Oct 2007)
New Revision: 13643
Modified files:
trunk/ChangeLog
trunk/encoding.c
trunk/string.c
Log:
* encoding.c (rb_enc_register): returns new index or -1 if failed.
* encoding.c (rb_enc_alias): check if original name is registered.
* encoding.c (rb_enc_init): register in same order as kcode options in
re.c. added new aliases.
* string.c (rb_str_force_encoding): check if valid encoding name.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=13643&r2=13642
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13643&r2=13642
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=13643&r2=13642
Index: encoding.c
===================================================================
--- encoding.c (revision 13642)
+++ encoding.c (revision 13643)
@@ -25,31 +25,45 @@
static int enc_table_size;
static st_table *enc_table_alias;
-void
+int
rb_enc_register(const char *name, rb_encoding *encoding)
{
struct rb_encoding_entry *ent;
+ int newsize;
if (!enc_table) {
- enc_table = malloc(sizeof(struct rb_encoding_entry));
- enc_table_size = 1;
+ ent = malloc(sizeof(*enc_table));
+ newsize = 1;
}
else {
- enc_table_size++;
- enc_table = realloc(enc_table, sizeof(struct rb_encoding_entry)*enc_table_size);
+ newsize = enc_table_size + 1;
+ ent = realloc(enc_table, sizeof(*enc_table)*newsize);
}
- ent = &enc_table[enc_table_size-1];
+ if (!ent) return -1;
+ enc_table = ent;
+ enc_table_size = newsize;
+ ent = &enc_table[--newsize];
ent->name = name;
ent->enc = encoding;
+ return newsize;
}
-void
+int
rb_enc_alias(const char *alias, const char *orig)
{
+ st_data_t data;
+ int idx;
+
if (!enc_table_alias) {
enc_table_alias = st_init_strcasetable();
}
+ while ((idx = rb_enc_find_index(orig)) < 0) {
+ if (!st_lookup(enc_table_alias, (st_data_t)orig, &data))
+ return -1;
+ orig = (const char *)data;
+ }
st_insert(enc_table_alias, (st_data_t)alias, (st_data_t)orig);
+ return idx;
}
void
@@ -57,11 +71,13 @@
{
#define ENC_REGISTER(enc) rb_enc_register(rb_enc_name(enc), enc)
ENC_REGISTER(ONIG_ENCODING_ASCII);
+ ENC_REGISTER(ONIG_ENCODING_EUC_JP);
ENC_REGISTER(ONIG_ENCODING_SJIS);
- ENC_REGISTER(ONIG_ENCODING_EUC_JP);
ENC_REGISTER(ONIG_ENCODING_UTF8);
#undef ENC_REGISTER
- rb_enc_alias("binary", "ascii");
+ rb_enc_alias("ascii", "us-ascii");
+ rb_enc_alias("binary", "us-ascii");
+ rb_enc_alias("iso-8859-1", "us-ascii");
rb_enc_alias("sjis", "shift_jis");
}
Index: ChangeLog
===================================================================
--- ChangeLog (revision 13642)
+++ ChangeLog (revision 13643)
@@ -1,5 +1,16 @@
-Sat Oct 6 14:32:30 2007 U-nobu-PC\nobu <nobu@r...>
+Sat Oct 6 14:56:02 2007 Nobuyoshi Nakada <nobu@r...>
+ * encoding.c (rb_enc_register): returns new index or -1 if failed.
+
+ * encoding.c (rb_enc_alias): check if original name is registered.
+
+ * encoding.c (rb_enc_init): register in same order as kcode options in
+ re.c. added new aliases.
+
+ * string.c (rb_str_force_encoding): check if valid encoding name.
+
+Sat Oct 6 14:32:30 2007 Nobuyoshi Nakada <nobu@r...>
+
* insns.def (opt_eq): get rid of gcc bug.
Sat Oct 6 02:34:18 2007 Yukihiro Matsumoto <matz@r...>
Index: string.c
===================================================================
--- string.c (revision 13642)
+++ string.c (revision 13643)
@@ -5114,8 +5114,17 @@
static VALUE
rb_str_force_encoding(VALUE str, VALUE encname)
{
+ const char *name;
+ int idx;
+
+ if (NIL_P(encname)) {
+ idx = 0;
+ }
+ else if ((idx = rb_enc_find_index(name = StringValueCStr(encname))) < 0) {
+ rb_raise(rb_eArgError, "invalid encoding name - %s", name);
+ }
str_modifiable(str);
- rb_enc_associate(str, rb_enc_find(StringValueCStr(encname)));
+ rb_enc_associate_index(str, idx);
return str;
}
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml