JReadNull
Description
Read a “null” value from input string.
Parameters
| Name | Direction | Description |
|---|---|---|
si |
in | Current reading position in input string |
is_null |
out | Pointer to bool set to true if “null” found |
Success
Returns StrIter advanced past “null”
Failure
Returns original StrIter if “null” not found
Usage example (Cross-references)
Usage examples (Cross-references)
- In
JSON.c:545:
}
StrIter JReadNull(StrIter si, bool *is_null) {
if (!StrIterRemainingLength(&si)) {
return si;- In
JSON.c:616:
StrIter before_si = si;
bool n;
si = JReadNull(si, &n);
if (StrIterIndex(&si) == StrIterIndex(&before_si)) { StrIter si = StrIterFromStr(j);
bool is_null = true;
StrIter out = JReadNull(si, &is_null);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadNull advanced on malformed 'nuXX'"); StrIter out = JReadNull(si, &is_null);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadNull advanced on malformed 'nuXX'");
success = false;
} StrIter si = StrIterFromStr(j);
bool is_null = false;
StrIter out = JReadNull(si, &is_null);
if (!(is_null == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadNull 'null' value/advance wrong: n={}, idx={}", is_null, StrIterIndex(&out)); StrIter out = JReadNull(si, &is_null);
if (!(is_null == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadNull 'null' value/advance wrong: n={}, idx={}", is_null, StrIterIndex(&out));
success = false;
} StrIter si = StrIterFromStr(j);
bool is_null = false;
StrIter out = JReadNull(si, &is_null);
if (!(is_null == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadNull exact 'null' wrong: n={}, idx={}", is_null, StrIterIndex(&out)); StrIter out = JReadNull(si, &is_null);
if (!(is_null == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadNull exact 'null' wrong: n={}, idx={}", is_null, StrIterIndex(&out));
success = false;
} // remain false -- assert it is NOT truthy.
bool test_js_null_clears_flag_on_non_null(void) {
WriteFmtLn("Testing JReadNull clears is_null on a non-null token");
DefaultAllocator alloc = DefaultAllocatorInit(); StrIter si = StrIterFromStr(j);
bool is_null = true; // poison: must be overwritten to false
StrIter out = JReadNull(si, &is_null);
// Malformed -> iterator rewinds (no advance).
// Malformed -> iterator rewinds (no advance).
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadNull advanced on malformed 'nuII'");
success = false;
} // The unconditional clear must have run: a truthy mutant fails here.
if (is_null != false) {
WriteFmtLn("[DEBUG] JReadNull left is_null truthy on non-null input: {}", is_null);
success = false;
} // mutant cannot satisfy one test by sabotaging the other.
bool test_js_null_sets_flag_on_null(void) {
WriteFmtLn("Testing JReadNull sets is_null on a real null token");
DefaultAllocator alloc = DefaultAllocatorInit(); StrIter si = StrIterFromStr(j);
bool is_null = false;
StrIter out = JReadNull(si, &is_null);
if (!(is_null == true && StrIterIndex(&out) == 4)) {
if (!(is_null == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadNull 'null' value/advance wrong: n={}, idx={}", is_null, StrIterIndex(&out));
success = false;
}
Last updated on