mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
3f1524f0d2
commit
96af6823c1
1 changed files with 10 additions and 10 deletions
20
st.c
20
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;
|
||||
|
|
Loading…
Reference in a new issue