BitVecRegexMatch
Description
Simple regex-style pattern matching for bitvectors. Supports basic patterns: ‘*’ (any sequence), ‘?’ (0 or 1), ‘[01]’ (literal).
Parameters
| Name | Direction | Description |
|---|---|---|
bv |
in | Bitvector to match against |
pattern |
in | Pattern string using regex syntax |
Usage example (from documentation)
bool matches = BitVecRegexMatch(&data, "10*01"); // 10 followed by any bits, then 01
Success
true if bitvector matches the regex pattern
Failure
false on a malformed pattern string or when no match is found.
Usage example (Cross-references)
Usage examples (Cross-references)
bool test_bitvec_regex_match_null_source(void) {
WriteFmt("Testing BitVecRegexMatch(NULL, pattern) - should fatal\n");
BitVecRegexMatch(NULL, "101");
return true; bool test_bitvec_regex_match_null_source(void) {
WriteFmt("Testing BitVecRegexMatch(NULL, pattern) - should fatal\n");
BitVecRegexMatch(NULL, "101");
return true;
} DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRegexMatch(source, NULL) - should fatal\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&source, true); BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
BitVecPush(&source, true);
BitVecRegexMatch(&source, (Zstr)NULL);
BitVecDeinit(&source);
DefaultAllocatorDeinit(&alloc); DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecRegexMatch basic functionality\n");
BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
// Test simple substring match
result = result && BitVecRegexMatch(&source, "101");
result = result && !BitVecRegexMatch(&source, "111"); // Test simple substring match
result = result && BitVecRegexMatch(&source, "101");
result = result && !BitVecRegexMatch(&source, "111");
BitVecDeinit(&source); // "111" never appears in "101010" -> must be false.
Str pat_no = StrInitFromZstr("111", &alloc);
result = result && !BitVecRegexMatch(&source, &pat_no);
// Sanity: a genuine substring still matches (guards against a trivially
// always-false implementation).
Str pat_yes = StrInitFromZstr("010", &alloc);
result = result && BitVecRegexMatch(&source, &pat_yes);
StrDeinit(&pat_no); BitVecPush(&bv, false);
bool matched = BitVecRegexMatch(&bv, "101");
bool ok = (matched == true);
Last updated on