8000 msvc: Do not use `isspace` · libgit2/libgit2@0f49200 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f49200

Browse files
committed
msvc: Do not use isspace
Locale-aware bullshit bitting my ass again yo
1 parent e65752b commit 0f49200

File tree

7 files changed

+33
-18
lines changed

7 files changed

+33
-18
lines changed

src/attr_file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ int git_attr_fnmatch__parse(
344344

345345
pattern = *base;
346346

347-
while (isspace(*pattern)) pattern++;
347+
while (git__isspace(*pattern)) pattern++;
348348
if (!*pattern || *pattern == '#') {
349349
*base = git__next_line(pattern);
350350
return GIT_ENOTFOUND;
@@ -368,7 +368,7 @@ int git_attr_fnmatch__parse(
368368
slash_count = 0;
369369
for (scan = pattern; *scan != '\0'; ++scan) {
370370
/* scan until (non-escaped) white space */
371-
if (isspace(*scan) && *(scan - 1) != '\\')
371+
if (git__isspace(*scan) && *(scan - 1) != '\\')
372372
break;
373373

374374
if (*scan == '/') {
@@ -485,7 +485,7 @@ int git_attr_assignment__parse(
485485
const char *name_start, *value_start;
486486

487487
/* skip leading blanks */
488-
while (isspace(*scan) && *scan != '\n') scan++;
488+
while (git__isspace(*scan) && *scan != '\n') scan++;
489489

490490
/* allocate assign if needed */
491491
if (!assign) {
@@ -509,7 +509,7 @@ int git_attr_assignment__parse(
509509

510510
/* find the name */
511511
name_start = scan;
512-
while (*scan && !isspace(*scan) && *scan != '=') {
512+
while (*scan && !git__isspace(*scan) && *scan != '=') {
513513
assign->name_hash =
514514
((assign->name_hash << 5) + assign->name_hash) + *scan;
515515
scan++;
@@ -518,7 +518,7 @@ int git_attr_assignment__parse(
518518
/* must have found lone prefix (" - ") or leading = ("=foo")
519519
* or end of buffer -- advance until whitespace and continue
520520
*/
521-
while (*scan && !isspace(*scan)) scan++;
521+
while (*scan && !git__isspace(*scan)) scan++;
522522
continue;
523523
}
524524

@@ -528,7 +528,7 @@ int git_attr_assignment__parse(
528528

529529
/* if there is an equals sign, find the value */
530530
if (*scan == '=') {
531-
for (value_start = ++scan; *scan && !isspace(*scan); ++scan);
531+
for (value_start = ++scan; *scan && !git__isspace(*scan); ++scan);
532532

533533
/* if we found a value, allocate permanent storage for it */
534534
if (scan > value_start) {

src/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ int git_buf_join(
400400
void git_buf_rtrim(git_buf *buf)
401401
{
402402
while (buf->size > 0) {
403-
if (!isspace(buf->ptr[buf->size - 1]))
403+
if (!git__isspace(buf->ptr[buf->size - 1]))
404404
break;
405405

406406
buf->size--;

src/config_file.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ static int cfg_getchar(diskfile_backend *cfg_file, int flags)
525525
assert(cfg_file->reader.read_ptr);
526526

527527
do c = cfg_getchar_raw(cfg_file);
528-
while (skip_whitespace && isspace(c) &&
528+
while (skip_whitespace && git__isspace(c) &&
529529
!cfg_file->reader.eof);
530530

531531
if (skip_comments && (c == '#' || c == ';')) {
@@ -573,7 +573,7 @@ static char *cfg_readline(diskfile_backend *cfg, bool skip_whitespace)
573573

574574
if (skip_whitespace) {
575575
/* Skip empty empty lines */
576-
while (isspace(*line_src))
576+
while (git__isspace(*line_src))
577577
++line_src;
578578
}
579579

@@ -592,7 +592,7 @@ static char *cfg_readline(diskfile_backend *cfg, bool skip_whitespace)
592592
memcpy(line, line_src, line_len);
593593

594594
do line[line_len] = '\0';
595-
while (line_len-- > 0 && isspace(line[line_len]));
595+
while (line_len-- > 0 && git__isspace(line[line_len]));
596596

597597
if (*line_end == '\n')
598598
line_end++;
@@ -737,7 +737,7 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
737737
c = line[pos++];
738738

739739
do {
740-
if (isspace(c)){
740+
if (git__isspace(c)){
741741
name[name_length] = '\0';
742742
result = parse_section_header_ext(cfg, line, name, section_out);
743743
git__free(line);
@@ -844,7 +844,7 @@ static int strip_comments(char *line, int in_quotes)
844844
}
845845

846846
/* skip any space at the end */
847-
if (isspace(ptr[-1])) {
847+
if (git__isspace(ptr[-1])) {
848848
ptr--;
849849
}
850850
ptr[0] = '\0';
@@ -1272,9 +1272,9 @@ static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_val
12721272
else
12731273
value_start = var_end + 1;
12741274

1275-
if (isspace(var_end[-1])) {
1275+
if (git__isspace(var_end[-1])) {
12761276
do var_end--;
1277-
while (isspace(var_end[0]));
1277+
while (git__isspace(var_end[0]));
12781278
}
12791279

12801280
*var_name = git__strndup(line, var_end - line + 1);
@@ -1287,7 +1287,7 @@ static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_val
12871287
* Now, let's try to parse the value
12881288
*/
12891289
if (value_start != NULL) {
1290-
while (isspace(value_start[0]))
1290+
while (git__isspace(value_start[0]))
12911291
value_start++;
12921292

12931293
if (is_multiline_var(value_start)) {

src/message.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static size_t line_length_without_trailing_spaces(const char *line, size_t len)
1212
{
1313
while (len) {
1414
unsigned char c = line[len - 1];
15-
if (!isspace(c))
15+
if (!git__isspace(c))
1616
break;
1717
len--;
1818
}

src/repository.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
246246
}
247247
else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
248248
const char *gitlink = ((const char *)file.ptr) + prefix_len;
249-
while (*gitlink && isspace(*gitlink)) gitlink++;
249+
while (*gitlink && git__isspace(*gitlink)) gitlink++;
250250
error = git_path_prettify_dir(path_out, gitlink, path_out->ptr);
251251
}
252252

src/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int ba
7575
/*
7676
* White space
7777
*/
78-
while (isspace(*p))
78+
while (git__isspace(*p))
7979
p++;
8080

8181
/*

src/util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,19 @@ GIT_INLINE(size_t) git__size_t_powerof2(size_t v)
194194
return git__size_t_bitmask(v) + 1;
195195
}
196196

197+
GIT_INLINE(bool) git__isupper(int c)
198+
{
199+
return (c >= 'A' && c <= 'Z');
200+
}
201+
202+
GIT_INLINE(bool) git__isalpha(int c)
203+
{
204+
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
205+
}
206+
207+
GIT_INLINE(bool) git__isspace(int c)
208+
{
209+
return (c == ' ' || c == '\t' || c == '\n' || c == '\12');
210+
}
211+
197212
#endif /* INCLUDE_util_h__ */

0 commit comments

Comments
 (0)
0