StrIterPeek
Description
Read the current character into *out without advancing. Propagating alias for IterPeekAt(mi, 0, out); see IterPeekAt for the full contract.
Parameters
| Name | Direction | Description |
|---|---|---|
mi |
in | Pointer to the StrIter to peek into. |
out |
out | Destination char *; receives the current character. |
Success
*out is set to the current character; the cursor is not advanced; returns true.
Failure
Iterator is exhausted; *out is not written, returns false.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
JSON.h:448:
/* starting of an array */ \
char UNPL(jr_c); \
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != '[') { \
LOG_ERROR("Invalid array start. Expected '['."); \
si = UNPL(saved_si); \
- In
JSON.h:460:
\
/* while not at the end of array. */ \
while (StrIterPeek(&si, &UNPL(jr_c)) && UNPL(jr_c) != ']') { \
if (UNPL(expect_comma)) { \
if (UNPL(jr_c) != ',') { \
- In
JSON.h:498:
/* end of array */ \
if (!UNPL(failed)) { \
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != ']') { \
LOG_ERROR("Invalid end of array. Expected ']'."); \
UNPL(failed) = true; \
- In
JSON.h:544:
/* starting of an object */ \
char UNPL(jr_c); \
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != '{') { \
LOG_ERROR("Invalid object start. Expected '{'."); \
si = UNPL(saved_si); \
- In
JSON.h:557:
\
/* while not at the end of object. */ \
while (StrIterPeek(&si, &UNPL(jr_c)) && UNPL(jr_c) != '}') { \
if (UNPL(expect_comma)) { \
if (UNPL(jr_c) != ',') { \
- In
JSON.h:586:
\
\
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != ':') { \
LOG_ERROR("Expected ':' after key string. Failed to read JSON"); \
StrDeinit(&key); \
- In
JSON.h:628:
\
if (!UNPL(failed)) { \
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != '}') { \
LOG_ERROR("Expected end of object '}' but found '{c}'", UNPL(jr_c)); \
UNPL(failed) = true; \
- In
ArgParse.c:83:
u64 v = 0;
char c;
while (StrIterPeek(&si, &c) && c >= '0' && c <= '9') {
u64 d = (u64)(c - '0');
if (v > (~(u64)0 - d) / 10)- In
Io.c:822:
char fc = 0;
while (StrIterPeek(&fsi, &fc)) {
if (fc != '{') {
// Literal byte: must match the cursor exactly. A mismatch or
- In
Io.c:838:
// `{{` escapes to a single literal '{' byte.
char esc = 0;
if (StrIterPeek(&fsi, &esc) && esc == '{') {
if (IterRemainingLength(iter) < 1 || *(const u8 *)IterPos(iter) != (u8)'{') {
*iter = start;- In
Io.c:850:
Zstr spec_start = (Zstr)StrIterPos(&fsi);
char sc = 0;
while (StrIterPeek(&fsi, &sc) && sc != '}') {
StrIterMustNext(&fsi);
}- In
Io.c:1025:
StrIter fsi = StrIterFromZstr(fmtstr);
char fc = 0;
while (StrIterPeek(&fsi, &fc)) {
if (fc != '{') {
// Literal byte: emit verbatim (mirrors the read side's match).
- In
Io.c:1037:
// `{{` escapes to a single literal '{' byte.
char esc = 0;
if (StrIterPeek(&fsi, &esc) && esc == '{') {
if (!StrPushBackR(out, '{')) {
return false;- In
Io.c:1047:
Zstr spec_start = (Zstr)StrIterPos(&fsi);
char sc = 0;
while (StrIterPeek(&fsi, &sc) && sc != '}') {
StrIterMustNext(&fsi);
}- In
Io.c:2658:
char c = 0;
while (StrIterPeek(&si, &c) && IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:2676:
StrIter saved = si;
Zstr start = StrIterDataAt(&si, StrIterIndex(&si));
while (StrIterPeek(&si, &c) && !IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:2698:
bool has_decimal = false;
while (StrIterPeek(&si, &c)) {
// A second '.' ends the number; the parser proper rejects
// multi-dot mantissas, so stopping here keeps the rejected tail
- In
Io.c:2714:
StrIterMustNext(&si);
if (StrIterPeek(&si, &c) && (c == '+' || c == '-')) {
StrIterMustNext(&si);
}- In
Io.c:2718:
}
if (!StrIterPeek(&si, &c) || !IS_DIGIT(c)) {
StrIterMustPrev(&si);
break;- In
Io.c:2723:
}
while (StrIterPeek(&si, &c) && IS_DIGIT(c)) {
StrIterMustNext(&si);
}- In
Io.c:2771:
char c = 0;
while (StrIterPeek(&si, &c) && IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:2789:
StrIter saved = si;
while (StrIterPeek(&si, &c)) {
if (!is_valid_number_char(c, StrIterIndex(&si) == StrIterIndex(&saved), false)) {
break;- In
Io.c:2890:
char c = 0; \
\
while (StrIterPeek(&si, &c) && IS_SPACE(c)) { \
StrIterMustNext(&si); \
} \
- In
Io.c:2901:
\
StrIter saved = si; \
while (StrIterPeek(&si, &c)) { \
if (!is_valid_number_char(c, StrIterIndex(&si) == StrIterIndex(&saved), false)) { \
break; \
- In
Io.c:3188:
char c = 0;
while (StrIterPeek(&si, &c) && IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:3211:
StrIter hex_saved = si;
while (StrIterPeek(&si, &c) && IS_XDIGIT(c)) {
StrIterMustNext(&si);
}- In
Io.c:3252:
StrIter oct_saved = si;
while (StrIterPeek(&si, &c) && c >= '0' && c <= '7') {
StrIterMustNext(&si);
}- In
Io.c:3286:
StrIter bin_saved = si;
while (StrIterPeek(&si, &c) && (c == '0' || c == '1')) {
StrIterMustNext(&si);
}- In
Io.c:3324:
char c = 0;
while (StrIterPeek(&si, &c) && IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:3339:
char d0 = 0;
(void)StrIterPeek(&si, &d0);
if (d0 == '+') {
StrIterMustNext(&si);- In
Io.c:3363:
}
while (StrIterPeek(&si, &c) && int_fmt_digit_matches_radix(c, radix)) {
StrIterMustNext(&si);
}- In
Io.c:3373:
char trailing = 0;
if (StrIterPeek(&si, &trailing) && trailing == '_') {
LOG_ERROR("Int reads do not accept digit separators");
return start;- In
Io.c:3421:
char c = 0;
while (StrIterPeek(&si, &c) && IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:3477:
char c = 0;
while (StrIterPeek(&si, &c) && IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:3495:
StrIter saved = si;
Zstr start = StrIterDataAt(&si, StrIterIndex(&si));
while (StrIterPeek(&si, &c) && !IS_SPACE(c)) {
StrIterMustNext(&si);
}- In
Io.c:3519:
bool has_decimal = false;
while (StrIterPeek(&si, &c)) {
if (c == '.') {
if (has_decimal)- In
Io.c:3532:
StrIterMustNext(&si);
if (StrIterPeek(&si, &c) && (c == '+' || c == '-')) {
StrIterMustNext(&si);
}- In
Io.c:3536:
}
if (!StrIterPeek(&si, &c) || !IS_DIGIT(c)) {
StrIterMustPrev(&si);
break;- In
Io.c:3541:
}
while (StrIterPeek(&si, &c) && IS_DIGIT(c)) {
StrIterMustNext(&si);
}- In
Dns.c:137:
static void skip_hspace_iter(StrIter *si) {
char c;
while (StrIterPeek(si, &c) && is_hspace(c)) {
StrIterMustNext(si);
}- In
Dns.c:146:
static void skip_to_eol_iter(StrIter *si) {
char c;
while (StrIterPeek(si, &c) && c != '\n') {
StrIterMustNext(si);
}- In
Dns.c:167:
// Comment / blank line -> eat the whole line.
if (!StrIterPeek(&si, &c) || c == '#' || c == '\n' || c == '\r') {
skip_to_eol_iter(&si);
continue;- In
Dns.c:174:
// First token: IP literal.
size ip_start = StrIterIndex(&si);
while (StrIterPeek(&si, &c) && !is_hspace(c) && c != '\n') {
StrIterMustNext(&si);
}- In
Dns.c:202:
// Subsequent tokens: name + aliases.
while (StrIterPeek(&si, &c) && c != '\n') {
skip_hspace_iter(&si);
if (!StrIterPeek(&si, &c) || c == '\n' || c == '#') {- In
Dns.c:204:
while (StrIterPeek(&si, &c) && c != '\n') {
skip_hspace_iter(&si);
if (!StrIterPeek(&si, &c) || c == '\n' || c == '#') {
break;
}- In
Dns.c:208:
}
size nm_start = StrIterIndex(&si);
while (StrIterPeek(&si, &c) && !is_hspace(c) && c != '\n' && c != '#') {
StrIterMustNext(&si);
}- In
Dns.c:264:
skip_hspace_iter(&si);
if (!StrIterPeek(&si, &c) || c == '#' || c == ';' || c == '\n' || c == '\r') {
skip_to_eol_iter(&si);
continue;- In
Dns.c:280:
size ip_start = StrIterIndex(&si);
while (StrIterPeek(&si, &c) && !is_hspace(c) && c != '\n' && c != '#') {
StrIterMustNext(&si);
}- In
Dns.c:29:
u64 total_bytes = 0;
char c;
while (StrIterPeek(&si, &c)) {
// Find next dot or end-of-string.
size seg_start = StrIterIndex(&si);- In
Dns.c:32:
// Find next dot or end-of-string.
size seg_start = StrIterIndex(&si);
while (StrIterPeek(&si, &c) && c != '.') {
StrIterMustNext(&si);
}- In
Dns.c:57:
return false;
}
if (StrIterPeek(&si, &c) && c == '.') {
StrIterMustNext(&si);
}- In
KvConfig.c:81:
static StrIter kvconfig_consume_line_end(StrIter si) {
char c;
if (StrIterPeek(&si, &c) && c == '\r') {
StrIterMustNext(&si);
}- In
KvConfig.c:84:
StrIterMustNext(&si);
}
if (StrIterPeek(&si, &c) && c == '\n') {
StrIterMustNext(&si);
}- In
KvConfig.c:92:
StrIter KvConfigSkipWhitespace(StrIter si) {
char c;
while (StrIterPeek(&si, &c) && kvconfig_is_space(c)) {
StrIterMustNext(&si);
}- In
KvConfig.c:100:
StrIter KvConfigSkipLine(StrIter si) {
char c;
while (StrIterPeek(&si, &c) && c != '\n') {
StrIterMustNext(&si);
}- In
KvConfig.c:116:
char c;
while (StrIterPeek(&si, &c)) {
if (c == '=' || c == ':' || kvconfig_is_space(c) || c == '\n' || kvconfig_is_comment_start(c)) {
break;- In
KvConfig.c:144:
char c;
if (!StrIterPeek(&si, &c) || c == '\n' || kvconfig_is_comment_start(c)) {
return si;
}- In
KvConfig.c:152:
StrIterMustNext(&si);
while (StrIterPeek(&si, &c)) {
if (c == quote) {
StrIterMustNext(&si);- In
KvConfig.c:160:
if (c == '\\') {
StrIterMustNext(&si);
if (!StrIterPeek(&si, &c)) {
LOG_ERROR("Unexpected end of quoted config value");
StrClear(value);- In
KvConfig.c:195:
}
while (StrIterPeek(&si, &c) && c != '\n') {
if (kvconfig_is_comment_start(c) && StrLen(value) > 0 &&
kvconfig_is_space(StrCharAt(value, StrLen(value) - 1))) {- In
KvConfig.c:237:
char c;
if (!StrIterPeek(&si, &c) || (c != '=' && c != ':')) {
LOG_ERROR("Expected '=' or ':' after config key");
StrClear(key);- In
KvConfig.c:254:
si = KvConfigSkipWhitespace(si);
if (!StrIterPeek(&si, &c)) {
// EOF after value is fine - last line without newline.
return si;- In
KvConfig.c:282:
char c;
while (StrIterPeek(&si, &c)) {
Str key = StrInit(MapAllocator(cfg));
Str value = StrInit(MapAllocator(cfg));- In
KvConfig.c:287:
StrIter read_si;
while (StrIterPeek(&si, &c)) {
if (c == '\n') {
StrIterMustNext(&si);- In
KvConfig.c:296:
si = KvConfigSkipWhitespace(si);
char c2;
if (!StrIterPeek(&si, &c2) || c2 == '\n') {
si = kvconfig_consume_line_end(si);
continue;- In
KvConfig.c:305:
}
if (!StrIterPeek(&si, &c)) {
StrDeinit(&key);
StrDeinit(&value);- In
ProcMaps.c:50:
int consumed = 0;
char c;
while (StrIterPeek(si, &c)) {
int d = hex_digit_value(c);
if (d < 0)- In
ProcMaps.c:66:
static bool expect_char(StrIter *si, char want) {
char c;
if (!StrIterPeek(si, &c) || c != want)
return false;
StrIterMustNext(si);- In
ProcMaps.c:74:
static void skip_ws(StrIter *si) {
char c;
while (StrIterPeek(si, &c) && (c == ' ' || c == '\t')) {
StrIterMustNext(si);
}- In
ProcMaps.c:82:
static void skip_token(StrIter *si) {
char c;
while (StrIterPeek(si, &c) && c != ' ' && c != '\t' && c != '\n') {
StrIterMustNext(si);
}- In
ProcMaps.c:143:
size path_start_pos = StrIterIndex(si);
char c;
while (StrIterPeek(si, &c) && c != '\n') {
StrIterMustNext(si);
}- In
ProcMaps.c:180:
// Skip past whatever line we couldn't parse.
char c;
while (StrIterPeek(&si, &c) && c != '\n') {
StrIterMustNext(&si);
}- In
JSON.c:22:
// starting of an object
char c;
if (!StrIterPeek(&si, &c) || c != '{') {
LOG_ERROR("Invalid object start. Expected '{'.");
return saved_si;- In
JSON.c:40:
// while not at the end of object.
while (StrIterPeek(&si, &c) && c != '}') {
if (expect_comma) {
if (c != ',') {- In
JSON.c:67:
si = JSkipWhitespace(si);
if (!StrIterPeek(&si, &c) || c != ':') {
LOG_ERROR("Expected ':' after key string. Failed to read JSON");
StrDeinit(&key);- In
JSON.c:97:
}
if (!StrIterPeek(&si, &c) || c != '}') {
LOG_ERROR("Expected end of object '}' but found '{c}'", c);
DefaultAllocatorDeinit(&scratch);- In
JSON.c:117:
char c;
if (!StrIterPeek(&si, &c) || c != '[') {
LOG_ERROR("Invalid array start. Expected '['.");
return saved_si;- In
JSON.c:128:
// while not at the end of array.
while (StrIterPeek(&si, &c) && c != ']') {
if (expect_comma) {
if (c != ',') {- In
JSON.c:155:
// end of array
if (!StrIterPeek(&si, &c) || c != ']') {
LOG_ERROR("Invalid end of array. Expected ']'.");
return saved_si;- In
JSON.c:166:
StrIter JSkipWhitespace(StrIter si) {
char c;
while (StrIterPeek(&si, &c)) {
switch (c) {
case ' ' :- In
JSON.c:195:
// string start
char c;
if (StrIterPeek(&si, &c) && c == '"') {
StrIterMustNext(&si);- In
JSON.c:199:
// while a printable character
while (StrIterPeek(&si, &c)) {
// three cases
// - end of string (return)
- In
JSON.c:213:
case '\\' :
StrIterMustNext(&si);
if (!StrIterPeek(&si, &c)) {
LOG_ERROR("Unexpected end of string.");
StrClear(str);- In
JSON.c:315:
bool is_neg = false;
char c;
if (StrIterPeek(&si, &c) && c == '-') {
is_neg = true;
StrIterMustNext(&si);- In
JSON.c:325:
bool is_parsing = true;
while (is_parsing && StrIterPeek(&si, &c)) {
switch (c) {
case 'E' :- In
JSON.c:510:
char c;
if (StrIterRemainingLength(&si) >= 4) {
if (StrIterPeek(&si, &c) && c == 't') {
Zstr pos = StrIterPos(&si);
if (pos && ZstrCompareN(pos, "true", 4) == 0) {- In
JSON.c:522:
if (StrIterRemainingLength(&si) >= 5) {
if (StrIterPeek(&si, &c) && c == 'f') {
Zstr pos = StrIterPos(&si);
if (pos && ZstrCompareN(pos, "false", 5) == 0) {- In
JSON.c:560:
char c;
if (StrIterRemainingLength(&si) >= 4) {
if (StrIterPeek(&si, &c) && c == 'n') {
Zstr pos = StrIterPos(&si);
if (pos && ZstrCompareN(pos, "null", 4) == 0) {- In
JSON.c:590:
char c;
if (!StrIterPeek(&si, &c)) {
LOG_ERROR("Failed to read value. Invalid JSON");
return si;- In
StrIter.c:50:
StrIter si = StrIterFromZstr("xy");
char c = 0;
if (!StrIterPeek(&si, &c) || c != 'x') {
return false;
} si = JSkipWhitespace(si); \
char UNPL(jr_c); \
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != '{') { \
LOG_ERROR("Invalid object start. Expected '{'."); \
si = UNPL(saved_si); \
bool UNPL(expect_comma) = false; \
bool UNPL(failed) = false; \
while (StrIterPeek(&si, &UNPL(jr_c)) && UNPL(jr_c) != '}') { \
if (UNPL(expect_comma)) { \
if (UNPL(jr_c) != ',') { \
si = UNPL(read_si); \
si = JSkipWhitespace(si); \
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != ':') { \
LOG_ERROR("Expected ':' after key string. Failed to read JSON"); \
StrDeinit(&key); \
} \
if (!UNPL(failed)) { \
if (!StrIterPeek(&si, &UNPL(jr_c)) || UNPL(jr_c) != '}') { \
LOG_ERROR("Expected end of object '}' but found '{c}'", UNPL(jr_c)); \
UNPL(failed) = true; \
char c = '\0';
if (!StrIterPeek(&si, &c) || c != '{') {
WriteFmt("[DEBUG] Peek check failed: expected '{', got '{c}'\n", c);
success = false;- In
Parse.c:72:
// After skipping "xy" and the LF, the iterator sits on 'Z' at index 3.
result = result && (StrIterIndex(&si) == 3);
result = result && StrIterPeek(&si, &c) && (c == 'Z');
StrDeinit(&src);- In
Parse.c:94:
// "a" then one LF consumed -> index 2, sitting on the second LF.
result = result && (StrIterIndex(&si) == 2);
result = result && StrIterPeek(&si, &c) && (c == '\n');
StrDeinit(&src);
Last updated on