kokke / tiny-regex-c

Small portable regex in C
The Unlicense
1.23k stars 175 forks source link

use more portable character checks #52

Closed cvengler closed 3 years ago

cvengler commented 3 years ago

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.

kokke commented 3 years ago

Hi @emilengler - thanks for the PR :) I hadn't thought of supporting more than ASCII/utf-8 but sure why not.

Should we keep the previous code commented out just next to (or above) your changes?

1) That would make it easy to avoid the extra function calls. 2) I don't know if I'm being paranoid with this, but I was also worried that ctype.h could be missing on some weird C compiler-systems (embedded: I'm looking at you!).

We could also add a #define and let a macro decide?

I think we should do one of the above though. Any comments on that?

Wow, PR from a cURL contributor - I'm star-struck ;D

smlavine commented 3 years ago
2. I don't know if I'm being paranoid with this, but I was also worried that `ctype.h` could be missing on some weird C compiler-systems (embedded: I'm looking at you!).

I feel it is safe to assume that is present on all C systems. The functions used in the commit conform to C89, according to their man pages, and it is even present in my K&R book.

Interestingly, there is a passage in K&R that is almost identical to part of this commit: IMG_20210213_120233

kokke commented 3 years ago

Sounds good to me then - will merge :+1: