JReadBool
Description
Read a boolean value (“true” or “false”) from input string.
Parameters
| Name | Direction | Description |
|---|---|---|
si |
in | Current reading position in input string |
b |
out | Pointer to bool to store parsed result |
Success
Returns StrIter advanced past parsed boolean
Failure
Returns original StrIter if invalid or unrecognized value
Usage example (Cross-references)
Usage examples (Cross-references)
- In
JSON.h:385:
do { \
bool UNPL(my_b) = 0; \
si = JReadBool((si), &UNPL(my_b)); \
(b) = UNPL(my_b); \
} while (0)- In
JSON.h:408:
if (!StrCmp(&key, (k))) { \
bool UNPL(my_b) = 0; \
si = JReadBool((si), &UNPL(my_b)); \
(b) = UNPL(my_b); \
} \
- In
JSON.c:496:
}
StrIter JReadBool(StrIter si, bool *b) {
if (!StrIterRemainingLength(&si)) {
return si;- In
JSON.c:599:
StrIter before_si = si;
bool b;
si = JReadBool(si, &b);
if (StrIterIndex(&si) == StrIterIndex(&before_si)) { StrIter si = StrIterFromStr(j);
bool b = true;
StrIter out = JReadBool(si, &b);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadBool advanced on malformed 'tru3'"); StrIter out = JReadBool(si, &b);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadBool advanced on malformed 'tru3'");
success = false;
} StrIter si = StrIterFromStr(j);
bool b = true;
StrIter out = JReadBool(si, &b);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadBool advanced on malformed 'fXlse'"); StrIter out = JReadBool(si, &b);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadBool advanced on malformed 'fXlse'");
success = false;
} StrIter si = StrIterFromStr(j);
bool b = true;
StrIter out = JReadBool(si, &b);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadBool advanced on too-short 'tr'"); StrIter out = JReadBool(si, &b);
if (StrIterIndex(&out) != StrIterIndex(&si)) {
WriteFmtLn("[DEBUG] JReadBool advanced on too-short 'tr'");
success = false;
} StrIter si = StrIterFromStr(j);
bool b = false;
StrIter out = JReadBool(si, &b);
// value correct and exactly 4 bytes consumed
if (!(b == true && StrIterIndex(&out) == 4)) { // value correct and exactly 4 bytes consumed
if (!(b == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadBool 'true' value/advance wrong: b={}, idx={}", b, StrIterIndex(&out));
success = false;
} StrIter si = StrIterFromStr(j);
bool b = true;
StrIter out = JReadBool(si, &b);
if (!(b == false && StrIterIndex(&out) == 5)) {
WriteFmtLn("[DEBUG] JReadBool 'false' value/advance wrong: b={}, idx={}", b, StrIterIndex(&out)); StrIter out = JReadBool(si, &b);
if (!(b == false && StrIterIndex(&out) == 5)) {
WriteFmtLn("[DEBUG] JReadBool 'false' value/advance wrong: b={}, idx={}", b, StrIterIndex(&out));
success = false;
} StrIter si = StrIterFromStr(j);
bool b = false;
StrIter out = JReadBool(si, &b);
if (!(b == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadBool exact 'true' wrong: b={}, idx={}", b, StrIterIndex(&out)); StrIter out = JReadBool(si, &b);
if (!(b == true && StrIterIndex(&out) == 4)) {
WriteFmtLn("[DEBUG] JReadBool exact 'true' wrong: b={}, idx={}", b, StrIterIndex(&out));
success = false;
} StrIter si = StrIterFromStr(j);
bool b = true;
StrIter out = JReadBool(si, &b);
if (!(b == false && StrIterIndex(&out) == 5)) {
WriteFmtLn("[DEBUG] JReadBool exact 'false' wrong: b={}, idx={}", b, StrIterIndex(&out)); StrIter out = JReadBool(si, &b);
if (!(b == false && StrIterIndex(&out) == 5)) {
WriteFmtLn("[DEBUG] JReadBool exact 'false' wrong: b={}, idx={}", b, StrIterIndex(&out));
success = false;
}
Last updated on