aboutsummaryrefslogtreecommitdiff
path: root/stdlib/patterns.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-15 18:41:37 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-15 18:41:37 -0400
commite59584acbdaad082d94815550ce0794cef7220de (patch)
treea035d3a475f3953a2e46eee17961236e688c6708 /stdlib/patterns.c
parent269c98d106cffa80c2ee3c96b042500eccd8a935 (diff)
Add alphanumeric pattern
Diffstat (limited to 'stdlib/patterns.c')
-rw-r--r--stdlib/patterns.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/stdlib/patterns.c b/stdlib/patterns.c
index 2de7fe3a..0df06eba 100644
--- a/stdlib/patterns.c
+++ b/stdlib/patterns.c
@@ -382,6 +382,12 @@ static int64_t match_int(TextIter_t *state, int64_t index)
return len >= 0 ? len : -1;
}
+static int64_t match_alphanumeric(TextIter_t *state, int64_t index)
+{
+ return EAT1(state, index, uc_is_property_alphabetic((ucs4_t)grapheme) || uc_is_property_numeric((ucs4_t)grapheme))
+ ? 1 : -1;
+}
+
static int64_t match_num(TextIter_t *state, int64_t index)
{
bool negative = EAT1(state, index, grapheme == '-') ? 1 : 0;
@@ -588,6 +594,9 @@ static pat_t parse_next_pat(TextIter_t *state, int64_t *index)
case 'a':
if (strcasecmp(prop_name, "authority") == 0) {
return PAT(PAT_FUNCTION, .fn=match_authority);
+ } else if (strcasecmp(prop_name, "alphanum") == 0 || strcasecmp(prop_name, "anum") == 0
+ || strcasecmp(prop_name, "alphanumeric") == 0) {
+ return PAT(PAT_FUNCTION, .fn=match_alphanumeric);
}
break;
case 'd':