Skip to content

Commit 5bc33b6

Browse files
committed
use more portable character checks
Checks like (x >= '0' && x <= '9') are highly dependent on the charset used by the operating system. Fortunately C has some functions that do the checks independently of the charset so we can achieve more portability through it.
1 parent 0b23313 commit 5bc33b6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

re.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "re.h"
3333
#include <stdio.h>
34+
#include <ctype.h>
3435

3536
/* Definitions: */
3637

@@ -289,15 +290,15 @@ void re_print(regex_t* pattern)
289290
/* Private functions: */
290291
static int matchdigit(char c)
291292
{
292-
return ((c >= '0') && (c <= '9'));
293+
return isdigit(c);
293294
}
294295
static int matchalpha(char c)
295296
{
296-
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
297+
return isalpha(c);
297298
}
298299
static int matchwhitespace(char c)
299300
{
300-
return ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') || (c == '\f') || (c == '\v'));
301+
return isspace(c);
301302
}
302303
static int matchalphanum(char c)
303304
{

0 commit comments

Comments
 (0)