summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 19:27:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 19:27:10 +0000
commitc351afc37276bb3d82eabe142a20be10127fed27 (patch)
tree1439d697c7f32c7e8322bfd62d40ce9c2ed7e628 /st.c
parent534d057e58e68c5a65509e718366f2dab5e69e84 (diff)
* encoding.c (rb_enc_alias): allow encodings multiple aliases.
* encoding.c (rb_enc_find_index): search the encoding which has the given name and return its index if found, or -1. * st.c (type_strcasehash): case-insensitive string hash type. * string.c (rb_str_force_encoding): force encoding of self. this name comes from [ruby-dev:31894] by Martin Duerst. [ruby-dev:31744] * include/ruby/encoding.h (rb_enc_find_index, rb_enc_associate_index): prototyped. * include/ruby/encoding.h (rb_enc_isctype): direct interface to ctype. * include/ruby/st.h (st_init_strcasetable): prototyped. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/st.c b/st.c
index ffff261470..2418547ebb 100644
--- a/st.c
+++ b/st.c
@@ -52,6 +52,12 @@ static const struct st_hash_type type_strhash = {
strhash,
};
+static int strcasehash(const char *);
+static const struct st_hash_type type_strcasehash = {
+ strcasecmp,
+ strcasehash,
+};
+
static void rehash(st_table *);
#ifdef RUBY
@@ -202,6 +208,18 @@ st_init_strtable_with_size(int size)
return st_init_table_with_size(&type_strhash, size);
}
+st_table*
+st_init_strcasetable(void)
+{
+ return st_init_table(&type_strcasehash);
+}
+
+st_table*
+st_init_strcasetable_with_size(int size)
+{
+ return st_init_table_with_size(&type_strcasehash, size);
+}
+
void
st_clear(st_table *table)
{
@@ -814,6 +832,25 @@ strhash(register const char *string)
return hval;
}
+static int
+strcasehash(register const char *string)
+{
+ register unsigned int hval = FNV1_32A_INIT;
+
+ /*
+ * FNV-1a hash each octet in the buffer
+ */
+ while (*string) {
+ unsigned int c = (unsigned char)*string++;
+ if ((unsigned int)(c - 'A') > ('Z' - 'A')) c += 'a' - 'A';
+ hval ^= c;
+
+ /* multiply by the 32 bit FNV magic prime mod 2^32 */
+ hval *= FNV_32_PRIME;
+ }
+ return hval;
+}
+
int
st_numcmp(st_data_t x, st_data_t y)
{