summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-08 04:24:26 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-08 04:24:26 +0000
commit96af6823c1b49a41e873fb4d9ffa16dfce7ffdd9 (patch)
tree2a41da2823b36e6a68f934e8357b7554930c6622 /st.c
parent3f1524f0d26f19434d5f9f188db3a49d6c3f1b0a (diff)
downloadruby-96af6823c1b49a41e873fb4d9ffa16dfce7ffdd9.tar.gz
st.c: straight-forward comparison of characters
These functions are used in strcasehash, which is used to store encoding names. Encoding names often include hyphens (e.g. "UTF-8"), and ` '-' - 'A' ` is negative (cannot express in unsigned int). Don't be tricky, just do what to do. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'st.c')
-rw-r--r--st.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/st.c b/st.c
index 18b2be7bcf..ee3dbb125d 100644
--- a/st.c
+++ b/st.c
@@ -2011,18 +2011,18 @@ strhash(st_data_t arg)
int
st_locale_insensitive_strcasecmp(const char *s1, const char *s2)
{
- unsigned int c1, c2;
+ char c1, c2;
while (1) {
- c1 = (unsigned char)*s1++;
- c2 = (unsigned char)*s2++;
+ c1 = *s1++;
+ c2 = *s2++;
if (c1 == '\0' || c2 == '\0') {
if (c1 != '\0') return 1;
if (c2 != '\0') return -1;
return 0;
}
- if ((unsigned int)(c1 - 'A') <= ('Z' - 'A')) c1 += 'a' - 'A';
- if ((unsigned int)(c2 - 'A') <= ('Z' - 'A')) c2 += 'a' - 'A';
+ if (('A' <= c1) && (c1 <= 'Z')) c1 += 'a' - 'A';
+ if (('A' <= c2) && (c2 <= 'Z')) c2 += 'a' - 'A';
if (c1 != c2) {
if (c1 > c2)
return 1;
@@ -2035,18 +2035,18 @@ st_locale_insensitive_strcasecmp(const char *s1, const char *s2)
int
st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n)
{
- unsigned int c1, c2;
+ char c1, c2;
while (n--) {
- c1 = (unsigned char)*s1++;
- c2 = (unsigned char)*s2++;
+ c1 = *s1++;
+ c2 = *s2++;
if (c1 == '\0' || c2 == '\0') {
if (c1 != '\0') return 1;
if (c2 != '\0') return -1;
return 0;
}
- if ((unsigned int)(c1 - 'A') <= ('Z' - 'A')) c1 += 'a' - 'A';
- if ((unsigned int)(c2 - 'A') <= ('Z' - 'A')) c2 += 'a' - 'A';
+ if (('A' <= c1) && (c1 <= 'Z')) c1 += 'a' - 'A';
+ if (('A' <= c2) && (c2 <= 'Z')) c2 += 'a' - 'A';
if (c1 != c2) {
if (c1 > c2)
return 1;