Commit 75a4636f by Edward Thomson

git__tolower: a tolower() that isn't dumb

Some brain damaged tolower() implementations appear to want to
take the locale into account, and this may require taking some
insanely aggressive lock on the locale and slowing down what should
be the most trivial of trivial calls for people who just want to
downcase ASCII.
parent 006548da
......@@ -156,7 +156,7 @@ int git_config_file_normalize_section(char *start, char *end)
if (end && scan >= end)
break;
if (isalnum(*scan))
*scan = (char)tolower(*scan);
*scan = (char)git__tolower(*scan);
else if (*scan != '-' || scan == start)
return GIT_EINVALIDSPEC;
}
......@@ -1083,7 +1083,7 @@ static int parse_section_header(struct reader *reader, char **section_out)
goto fail_parse;
}
name[name_length++] = (char) tolower(c);
name[name_length++] = (char)git__tolower(c);
} while ((c = line[pos++]) != ']');
......
......@@ -164,8 +164,8 @@ p_fnmatchx(const char *pattern, const char *string, int flags, size_t recurs)
default:
normal:
if (c != *string && !((flags & FNM_CASEFOLD) &&
(tolower((unsigned char)c) ==
tolower((unsigned char)*string))))
(git__tolower((unsigned char)c) ==
git__tolower((unsigned char)*string))))
return (FNM_NOMATCH);
++string;
break;
......@@ -190,7 +190,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
++pattern;
if (flags & FNM_CASEFOLD)
test = (char)tolower((unsigned char)test);
test = (char)git__tolower((unsigned char)test);
/*
* A right bracket shall lose its special meaning and represent
......@@ -207,7 +207,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
if (c == '/' && (flags & FNM_PATHNAME))
return (RANGE_NOMATCH);
if ((flags & FNM_CASEFOLD))
c = (char)tolower((unsigned char)c);
c = (char)git__tolower((unsigned char)c);
if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
......@@ -216,7 +216,7 @@ rangematch(const char *pattern, char test, int flags, char **newp)
if (c2 == EOS)
return (RANGE_ERROR);
if (flags & FNM_CASEFOLD)
c2 = (char)tolower((unsigned char)c2);
c2 = (char)git__tolower((unsigned char)c2);
if (c <= test && test <= c2)
ok = 1;
} else if (c == test)
......
......@@ -1401,10 +1401,10 @@ GIT_INLINE(bool) workdir_path_is_dotgit(const git_buf *path)
if (path->ptr[len - 1] == '/')
len--;
if (tolower(path->ptr[len - 1]) != 't' ||
tolower(path->ptr[len - 2]) != 'i' ||
tolower(path->ptr[len - 3]) != 'g' ||
tolower(path->ptr[len - 4]) != '.')
if (git__tolower(path->ptr[len - 1]) != 't' ||
git__tolower(path->ptr[len - 2]) != 'i' ||
git__tolower(path->ptr[len - 3]) != 'g' ||
git__tolower(path->ptr[len - 4]) != '.')
return false;
return (len == 4 || path->ptr[len - 5] == '/');
......
......@@ -84,7 +84,7 @@ void gitno_consume_n(gitno_buffer *buf, size_t cons)
int gitno__match_host(const char *pattern, const char *host)
{
for (;;) {
char c = tolower(*pattern++);
char c = git__tolower(*pattern++);
if (c == '\0')
return *host ? -1 : 0;
......@@ -102,7 +102,7 @@ int gitno__match_host(const char *pattern, const char *host)
*/
while(*host) {
char h = tolower(*host);
char h = git__tolower(*host);
if (c == h)
return gitno__match_host(pattern, host++);
if (h == '.')
......@@ -112,7 +112,7 @@ int gitno__match_host(const char *pattern, const char *host)
return -1;
}
if (c != tolower(*host++))
if (c != git__tolower(*host++))
return -1;
}
......
......@@ -1471,7 +1471,7 @@ static int32_t next_hfs_char(const char **in, size_t *len)
* the ASCII range, which is perfectly fine, because the
* git folder name can only be composed of ascii characters
*/
return tolower(codepoint);
return git__tolower(codepoint);
}
return 0; /* NULL byte -- end of string */
}
......
......@@ -171,9 +171,9 @@ int git__strcmp(const char *a, const char *b)
int git__strcasecmp(const char *a, const char *b)
{
while (*a && *b && tolower(*a) == tolower(*b))
while (*a && *b && git__tolower(*a) == git__tolower(*b))
++a, ++b;
return ((unsigned char)tolower(*a) - (unsigned char)tolower(*b));
return ((unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b));
}
int git__strcasesort_cmp(const char *a, const char *b)
......@@ -182,7 +182,7 @@ int git__strcasesort_cmp(const char *a, const char *b)
while (*a && *b) {
if (*a != *b) {
if (tolower(*a) != tolower(*b))
if (git__tolower(*a) != git__tolower(*b))
break;
/* use case in sort order even if not in equivalence */
if (!cmp)
......@@ -193,7 +193,7 @@ int git__strcasesort_cmp(const char *a, const char *b)
}
if (*a || *b)
return (unsigned char)tolower(*a) - (unsigned char)tolower(*b);
return (unsigned char)git__tolower(*a) - (unsigned char)git__tolower(*b);
return cmp;
}
......@@ -212,8 +212,8 @@ int git__strncasecmp(const char *a, const char *b, size_t sz)
int al, bl;
do {
al = (unsigned char)tolower(*a);
bl = (unsigned char)tolower(*b);
al = (unsigned char)git__tolower(*a);
bl = (unsigned char)git__tolower(*b);
++a, ++b;
} while (--sz && al && al == bl);
......@@ -225,7 +225,7 @@ void git__strntolower(char *str, size_t len)
size_t i;
for (i = 0; i < len; ++i) {
str[i] = (char) tolower(str[i]);
str[i] = (char)git__tolower(str[i]);
}
}
......@@ -255,8 +255,8 @@ int git__prefixncmp_icase(const char *str, size_t str_n, const char *prefix)
int s, p;
while(str_n--) {
s = (unsigned char)tolower(*str++);
p = (unsigned char)tolower(*prefix++);
s = (unsigned char)git__tolower(*str++);
p = (unsigned char)git__tolower(*prefix++);
if (s != p)
return s - p;
......
......@@ -275,6 +275,15 @@ extern char *git__strsep(char **end, const char *sep);
extern void git__strntolower(char *str, size_t len);
extern void git__strtolower(char *str);
#ifdef GIT_WIN32
GIT_INLINE(int) git__tolower(int c)
{
return (c >= 'A' && c <= 'Z') ? (c + 32) : c;
}
#else
# define git__tolower(a) tolower(a)
#endif
GIT_INLINE(const char *) git__next_line(const char *s)
{
while (*s && *s != '\n') s++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment