Merge AsciiCharset CT/non-CT Functions (#2688)

* Merge AsciiCharset CT/non-CT Functions

* release notes

* incorporate helpful review feedback

* re-separate 'create_set' and 'contains' but keep 'combine_sets'; update tests

* tabs (annoying IDE)

* Restored old code verbatim for smaller diff. Split combine_sets into easier to macro/function for runtime / macro version, this also allows for more easy type checks.

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
Zack Puhl
2026-01-15 15:39:48 -05:00
committed by GitHub
parent f254c27966
commit 3f7a547d8a
3 changed files with 63 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ fn void test_all()
if (c.is_bdigit()) check.updatec(8);
if (c.is_odigit()) check.updatec(16);
if (c.is_xdigit()) check.updatec(16);
if (c.is_digit()) check.updatec(32);
if (c.is_digit()) check.updatec(32);
if (c.is_graph()) check.updatec(64);
check.updatec(128);
if (c.is_punct()) check.updatec(1);
@@ -25,4 +25,44 @@ fn void test_all()
check.updatec(c.to_lower());
}
test::eq(check.final(), 7327699757963224526UL);
}
}
const AsciiCharset ALPHANUMERIC_WHITESPACE
= @combine_sets(ALPHA_UPPER_SET, ALPHA_LOWER_SET, NUMBER_SET, WHITESPACE_SET);
fn void asciicharset_contains()
{
$assert !ALPHANUMERIC_WHITESPACE.@contains('.');
$assert ALPHANUMERIC_WHITESPACE.@contains('T');
$assert ALPHANUMERIC_WHITESPACE.@contains('t');
$assert ALPHANUMERIC_WHITESPACE.@contains('8');
$assert ALPHANUMERIC_WHITESPACE.@contains(' ');
test::@check(!ALPHANUMERIC_WHITESPACE.contains('.'));
test::@check(ALPHANUMERIC_WHITESPACE.contains('T'));
test::@check(ALPHANUMERIC_WHITESPACE.contains('t'));
test::@check(ALPHANUMERIC_WHITESPACE.contains('8'));
test::@check(ALPHANUMERIC_WHITESPACE.contains(' '));
}
fn void asciicharset_create_set()
{
var $s = @create_set("abc");
$foreach $c : "abc": $assert $s.@contains($c); $endforeach
AsciiCharset xyz = create_set("xyz");
foreach (c : "xyz") test::@check(xyz.contains(c));
}
fn void asciicharset_combine_sets()
{
var $a_set = @combine_sets(@create_set("123"), @create_set("89"), @create_set("!@#$"), @create_set("something"));
$foreach $c : "something@123!": $assert $a_set.@contains($c); $endforeach
AsciiCharset a_set = combine_sets(create_set("123"), create_set("89"), create_set("!@#$"), create_set("something"));
foreach (c : "something@123!") test::@check(a_set.contains(c));
// Mixture of runtime and compile-time sets.
AsciiCharset mixed_set = combine_sets($a_set, a_set, @create_set("456"));
foreach (c : "something@123!456") test::@check(mixed_set.contains(c));
}