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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
/**
* Returns 1 if c is a "whitespace" character as defined by the spec.
*/
int cmark_isspace(char c)
{
- return (c == 0x09 ||
- c == 0x20 ||
- c == 0x0a ||
- c == 0x0d);
+ return cmark_ctype_class[(int8_t)c] == 1;
}
/**
@@ -14,20 +34,17 @@ int cmark_isspace(char c)
*/
int cmark_ispunct(char c)
{
- return ((c >= 33 && c <= 47) ||
- (c >= 58 && c <= 64) ||
- (c >= 91 && c <= 96) ||
- (c >= 123 && c <= 126));
+ return cmark_ctype_class[(int8_t)c] == 2;
}
int cmark_isalnum(char c)
{
- return ((c >= 48 && c <= 57) ||
- (c >= 65 && c <= 90) ||
- (c >= 97 && c <= 122));
+ int8_t result;
+ result = cmark_ctype_class[(int8_t)c];
+ return (result == 3 || result == 4);
}
int cmark_isdigit(char c)
{
- return (c >= 48 && c <= 57);
+ return cmark_ctype_class[(int8_t)c] == 3;
}