BitVecFromStr
Description
Parse a bitvector from a null-terminated string using an explicit allocator.
Parameters
| Name | Direction | Description |
|---|---|---|
str |
in | Input string containing 0 and 1 characters. |
alloc |
in | Allocator to bind to the returned bitvector. |
Success
Returns parsed bitvector.
Failure
Returns an empty bitvector on invalid input or allocation failure.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:3301:
);
*bv = BitVecFromStr(StrBegin(&bin_str), BitVecAllocator(bv));
StrDeinit(&bin_str);- In
Convert.c:75:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecFromStr\n");
// Convert from string
- In
Convert.c:90:
// Test with empty string
BitVec empty_bv = BitVecFromStr("", ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&empty_bv) == 0);- In
Convert.c:350:
DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecFromStr edge cases\n");
bool result = true;- In
Convert.c:355:
// Test empty string
BitVec bv1 = BitVecFromStr("", ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&bv1) == 0);
BitVecDeinit(&bv1);- In
Convert.c:360:
// Test single character
BitVec bv2 = BitVecFromStr("1", ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&bv2) == 1);
result = result && (BitVecGet(&bv2, 0) == true);- In
Convert.c:372:
long_str[1000] = '\0';
BitVec bv3 = BitVecFromStr(long_str, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&bv3) == 1000);
result = result && (BitVecGet(&bv3, 0) == true);- In
Convert.c:452:
for (size i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) {
BitVec bv = BitVecFromStr(patterns[i], ALLOCATOR_OF(&alloc));
Str str = BitVecToStr(&bv);- In
Convert.c:576:
for (size i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
BitVec bv = BitVecFromStr(test_cases[i].pattern, ALLOCATOR_OF(&alloc));
// Test string conversion consistency
- In
Convert.c:607:
// FromInteger(0xD6, 8) -> bit[i]=(0xD6>>i)&1 -> "01101011"
// FromBytes({0xD6}, 8) -> bit[i]=(0xD6>>i)&1 -> "01101011"
BitVec bv1 = BitVecFromStr("11010110", ALLOCATOR_OF(&alloc));
BitVec bv2 = BitVecFromInteger(0xD6, 8, ALLOCATOR_OF(&alloc));
BitVec bv3 = BitVecFromBytes((u8[]) {0xD6}, 8, ALLOCATOR_OF(&alloc));- In
Convert.c:699:
large_pattern[2000] = '\0';
BitVec large_from_str = BitVecFromStr(large_pattern, ALLOCATOR_OF(&alloc));
result = result && (BitVecLen(&large_from_str) == 2000);- In
Convert.c:772:
// Test NULL string - should abort
BitVecFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
DefaultAllocatorDeinit(&alloc);- In
Write.c:537:
bool success = true;
BitVec bv1 = BitVecFromStr("10110", alloc_base);
StrAppendFmt(&output, "{}", bv1);
success = success && (ZstrCompare(StrBegin(&output), "10110") == 0);- In
Write.c:3718:
Str out = StrInit(&alloc);
BitVec bv = BitVecFromStr("1", alloc_base);
StrAppendFmt(&out, "XX{>5}", bv);- In
Write.c:5408:
static bool test_bitvec_write_no_leak(void) {
DBG_BEGIN(dbg, out);
BitVec bv = BitVecFromStr("10110", &dbg.base);
StrAppendFmt(&out, "{}", bv);
bool ok = (ZstrCompare(StrBegin(&out), "10110") == 0);- In
Write.c:5420:
Allocator *ab = ALLOCATOR_OF(&alloc);
Str out = StrInit(&alloc);
BitVec bv = BitVecFromStr("101", ab);
StrAppendFmt(&out, "{}", bv);
bool ok = (ZstrCompare(StrBegin(&out), "101") == 0);
Last updated on