summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-01 12:24:04 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-01 12:24:04 +0000
commit041e8291271557ca0b18f283411b013888c55955 (patch)
tree474e4518a368fcd26881d41c3f011e9525b1fdf2 /st.c
parent46933426b0a013efe1c978bbd200ea63c9ec644d (diff)
* include/ruby/encoding.h (rb_isascii): defined.
(rb_isalnum): ditto. (rb_isalpha): ditto. (rb_isblank): ditto. (rb_iscntrl): ditto. (rb_isdigit): ditto. (rb_isgraph): ditto. (rb_islower): ditto. (rb_isprint): ditto. (rb_ispunct): ditto. (rb_isspace): ditto. (rb_isupper): ditto. (rb_isxdigit): ditto. (rb_tolower): ditto. (rb_toupper): ditto. * include/ruby/st.h (st_strcasecmp): declared. (st_strncasecmp): ditto. * st.c (type_strcasehash): use st_strcasecmp instead of strcasecmp. (st_strcasecmp): defined. (st_strncasecmp): ditto. * include/ruby/ruby.h: include include/ruby/encoding.h. (ISASCII): use rb_isascii. (ISPRINT): use rb_isprint. (ISSPACE): use rb_isspace. (ISUPPER): use rb_isupper. (ISLOWER): use rb_islower. (ISALNUM): use rb_isalnum. (ISALPHA): use rb_isalpha. (ISDIGIT): use rb_isdigit. (ISXDIGIT): use rb_isxdigit. (TOUPPER): defined. (TOLOWER): ditto. (STRCASECMP): ditto. (STRNCASECMP): ditto. * dir.c, encoding.c, file.c, hash.c, process.c, ruby.c, time.c, transcode.c, ext/readline/readline.c: use locale insensitive functions. [ruby-core:14662] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14829 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/st.c b/st.c
index a0e6692..4af67ca 100644
--- a/st.c
+++ b/st.c
@@ -54,7 +54,7 @@ static const struct st_hash_type type_strhash = {
static int strcasehash(const char *);
static const struct st_hash_type type_strcasehash = {
- strcasecmp,
+ st_strcasecmp,
strcasehash,
};
@@ -861,6 +861,60 @@ strhash(register const char *string)
return hval;
}
+int
+st_strcasecmp(const char *s1, const char *s2)
+{
+ unsigned int c1, c2;
+
+ while (1) {
+ c1 = (unsigned char)*s1++;
+ c2 = (unsigned char)*s2++;
+ if (!c1) break;
+ if (!c2) break;
+ if ((unsigned int)(c1 - 'A') <= ('Z' - 'A')) c1 += 'a' - 'A';
+ if ((unsigned int)(c2 - 'A') <= ('Z' - 'A')) c2 += 'a' - 'A';
+ if (c1 != c2) {
+ if (c1 > c2)
+ return 1;
+ else
+ return -1;
+ }
+ }
+ if (c1 != '\0')
+ return 1;
+ if (c2 != '\0')
+ return -1;
+ return 0;
+}
+
+int
+st_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ unsigned int c1, c2;
+
+ while (n--) {
+ c1 = (unsigned char)*s1++;
+ c2 = (unsigned char)*s2++;
+ if (!c1) break;
+ if (!c2) break;
+ if ((unsigned int)(c1 - 'A') <= ('Z' - 'A')) c1 += 'a' - 'A';
+ if ((unsigned int)(c2 - 'A') <= ('Z' - 'A')) c2 += 'a' - 'A';
+ if (c1 != c2) {
+ if (c1 > c2)
+ return 1;
+ else
+ return -1;
+ }
+ }
+ if (n == 0)
+ return 0;
+ if (c1 != '\0')
+ return 1;
+ if (c2 != '\0')
+ return -1;
+ return 0;
+}
+
static int
strcasehash(register const char *string)
{