BitVecToStr
Description
Convert a bitvector to a string. Two forms via argument count:
BitVecToStr(bv)- usesbv’s allocator.BitVecToStr(bv, alloc)- uses the explicit allocator.
Success
Returns a string containing bit characters.
Failure
Returns an empty string if allocation fails.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
BitVec.c:1859:
// wanting true regex semantics should feed BitVecToStr to a regex
// engine themselves.
Str bv_str = BitVecToStr(bv);
bool result = false;- In
BitVec.c:1876:
}
Str bv_str = BitVecToStr(bv);
bool result = false;- In
Io.Read.c:821:
z = "10110";
StrReadFmt(z, "{}", bv1);
Str result1 = BitVecToStr(&bv1);
success = success && (ZstrCompare(StrBegin(&result1), "10110") == 0);
WriteFmt(- In
Io.Read.c:850:
z = " 1101";
StrReadFmt(z, "{}", bv4);
Str result4 = BitVecToStr(&bv4);
success = success && (ZstrCompare(StrBegin(&result4), "1101") == 0);
WriteFmt(- In
Io.Read.c:863:
z = "0";
StrReadFmt(z, "{}", bv5);
Str result5 = BitVecToStr(&bv5);
success = success && (ZstrCompare(StrBegin(&result5), "0") == 0);
WriteFmt( DefaultAllocator alloc = DefaultAllocatorInit();
WriteFmt("Testing BitVecToStr\n");
BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
// Test converting empty bitvec
Str str_obj = BitVecToStr(&bv);
result = result && (StrLen(&str_obj) == 0);
StrDeinit(&str_obj); // Test converting single bit
BitVecPush(&bv, true);
str_obj = BitVecToStr(&bv);
result = result && (StrLen(&str_obj) == 1);
result = result && (StrCmp(&str_obj, "1", 1) == 0); BitVecPush(&bv, i % 2 == 0);
}
str_obj = BitVecToStr(&bv);
result = result && (StrLen(&str_obj) == 1000);
StrDeinit(&str_obj); for (size i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) {
BitVec bv = BitVecFromStr(patterns[i], ALLOCATOR_OF(&alloc));
Str str = BitVecToStr(&bv);
// Should get exact same string back
BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
Str empty_str = BitVecToStr(&empty);
result = result && (StrLen(&empty_str) == 0);
StrDeinit(&empty_str);
// Test string conversion consistency
Str str = BitVecToStr(&bv);
result = result && (ZstrCompare(StrBegin(&str), test_cases[i].pattern) == 0);
StrDeinit(&str);
// All three should produce the same result when converted back
Str str1 = BitVecToStr(&bv1);
Str str2 = BitVecToStr(&bv2);
Str str3 = BitVecToStr(&bv3); // All three should produce the same result when converted back
Str str1 = BitVecToStr(&bv1);
Str str2 = BitVecToStr(&bv2);
Str str3 = BitVecToStr(&bv3); Str str1 = BitVecToStr(&bv1);
Str str2 = BitVecToStr(&bv2);
Str str3 = BitVecToStr(&bv3);
// At least two of them should match (bit order might affect one)
// Test string conversion
Str large_str = BitVecToStr(&large_bv);
result = result && (StrLen(&large_str) == 1000); // function-level ValidateBitVec instead of dereferencing NULL
// inside the BitVecAllocator accessor macro.
BitVecToStr((BitVec *)NULL, ALLOCATOR_OF(&alloc));
DefaultAllocatorDeinit(&alloc);
Last updated on