StrIterFromStr
Description
Construct a forward-walking StrIter from a Str value. Alias- reframe of IterInitFromVec in string vocabulary: Str is a Vec(char), so the borrowed-data semantics and NULL-allocator alignment fallback documented on IterInitFromVec apply unchanged.
Parameters
| Name | Direction | Description |
|---|---|---|
s |
in | Source string (by value – the resulting iter holds a non-owning pointer into s’s buffer). |
Success
Returns a struct-literal StrIter covering [StrBegin(&s), StrBegin(&s) + StrLen(&s)) with pos = 0, dir = 1.
Failure
Macro cannot fail; an empty Str yields a remaining- length-0 iterator.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ProcMaps.c:217:
// `StrResize` already writes a NUL sentinel at index `length`,
// so path slices that alias the buffer are usable as `Zstr`.
StrIter si = StrIterFromStr(out->raw);
while (StrIterRemainingLength(&si)) {
ProcMapEntry e = {0};- In
Dns.c:161:
}
StrIter si = StrIterFromStr(buf);
char c;
while (StrIterRemainingLength(&si)) {- In
Dns.c:259:
u64 kw_len = sizeof(NS_KEYWORD) - 1;
StrIter si = StrIterFromStr(buf);
char c;
while (StrIterRemainingLength(&si)) { // Test completely empty object
Str json1 = StrInitFromZstr("{}", &alloc);
StrIter si1 = StrIterFromStr(json1);
struct { // Test empty object with whitespace
Str json2 = StrInitFromZstr(" { } ", &alloc);
StrIter si2 = StrIterFromStr(json2);
struct { // Test completely empty array
Str json1 = StrInitFromZstr("{\"items\":[]}", &alloc);
StrIter si1 = StrIterFromStr(json1);
Vec(i32) items = VecInit(&alloc); // Test empty array with whitespace
Str json2 = StrInitFromZstr("{\"data\": [ ] }", &alloc);
StrIter si2 = StrIterFromStr(json2);
Vec(Str) data = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
Str json = StrInitFromZstr("{\"name\":\"\",\"description\":\"\"}", &alloc);
StrIter si = StrIterFromStr(json);
struct {
Str json = StrInitFromZstr("{\"temp\":-25,\"balance\":-1000.50,\"delta\":-0.001}", &alloc);
StrIter si = StrIterFromStr(json);
struct { &alloc
);
StrIter si = StrIterFromStr(json);
struct {
Str json = StrInitFromZstr("{\"int_zero\":0,\"float_zero\":0.0,\"bool_false\":false}", &alloc);
StrIter si = StrIterFromStr(json);
struct { &alloc
);
StrIter si = StrIterFromStr(json);
struct { &alloc
);
StrIter si = StrIterFromStr(json);
struct { // Test with lots of different whitespace patterns
Str json = StrInitFromZstr(" {\n\t\"name\" : \"test\" ,\n \"value\": 42\t,\"flag\"\n:\ntrue\n}\t", &alloc);
StrIter si = StrIterFromStr(json);
struct {
Str json = StrInitFromZstr("{\"outer\":{},\"list\":[],\"deep\":{\"inner\":{}}}", &alloc);
StrIter si = StrIterFromStr(json);
struct { Str json =
StrInitFromZstr("{\"empty_obj\":{},\"filled_obj\":{\"x\":1},\"empty_arr\":[],\"filled_arr\":[1,2]}", &alloc);
StrIter si = StrIterFromStr(json);
struct { // Using smaller values that are safer to work with
Str json = StrInitFromZstr("{\"max_int\":2147483647,\"min_int\":-2147483648,\"one\":1,\"minus_one\":-1}", &alloc);
StrIter si = StrIterFromStr(json);
struct { Str json =
StrInitFromZstr("{\"tiny\":0.000001,\"huge\":999999.999999,\"zero\":0.0,\"negative_tiny\":-0.000001}", &alloc);
StrIter si = StrIterFromStr(json);
struct {
Str json = StrInitFromZstr("{\"test\": \"value\"}", &alloc);
StrIter si = StrIterFromStr(json);
bool success = true; bool success = true;
Str json = StrInitFromZstr("{\"id\": 12345, \"name\": \"test\", \"active\": true, \"score\": 98.5}", &alloc);
StrIter si = StrIterFromStr(json);
struct { &alloc
);
StrIter si = StrIterFromStr(json);
struct { &alloc
);
StrIter si = StrIterFromStr(json);
struct { &alloc
);
StrIter si = StrIterFromStr(json);
typedef Vec(AnnSymbol) Symbols; &alloc
);
StrIter si = StrIterFromStr(json);
ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)}; bool success = true;
Str json = StrInitFromZstr("{\"id\": 12345, \"name\": \"test_func\", \"size\": 1024, \"vaddr\": 4096}", &alloc);
StrIter si = StrIterFromStr(json);
FunctionInfo info = {0}; bool success = true;
Str json = StrInitFromZstr("{\"id\": 54321, \"name\": \"test_model\"}", &alloc);
StrIter si = StrIterFromStr(json);
ModelInfo info = {0}; &alloc
);
StrIter si = StrIterFromStr(json);
SearchResult result = {0}; &alloc
);
StrIter si = StrIterFromStr(json);
ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)}; &alloc
);
StrIter si = StrIterFromStr(json);
ApiResponse response = {false, StrInit(&alloc), VecInitWithDeepCopy(NULL, AnnSymbolDeinit, &alloc)};- In
Read.Simple.c:68:
bool success = true;
Str json = StrInitFromZstr("{\"name\": \"Alice\", \"city\": \"New York\"}", &alloc);
StrIter si = StrIterFromStr(json);
Str name = StrInit(&alloc); bool success = true;
Str json = StrInitFromZstr("{\"count\": 42, \"score\": 95.5, \"year\": 2024}", &alloc);
StrIter si = StrIterFromStr(json);
u32 count = 0; bool success = true;
Str json = StrInitFromZstr("{\"enabled\": true, \"visible\": false}", &alloc);
StrIter si = StrIterFromStr(json);
bool enabled = false; &alloc
);
StrIter si = StrIterFromStr(json);
Person person = {0}; bool success = true;
Str json = StrInitFromZstr("{\"debug_mode\": false, \"timeout\": 30, \"log_level\": \"INFO\"}", &alloc);
StrIter si = StrIterFromStr(json);
Config config = {0}; bool success = true;
Str json = StrInitFromZstr("{\"languages\": [\"C\", \"Python\", \"Rust\"]}", &alloc);
StrIter si = StrIterFromStr(json);
Vec(Str) languages = VecInitWithDeepCopy(NULL, StrDeinit, &alloc); &alloc
);
StrIter si = StrIterFromStr(json);
struct { &alloc
);
StrIter si = StrIterFromStr(json);
SimpleProduct product = {0};- In
RoundTrip.c:123:
} parsed = {0, 0.0, false, StrInit(&alloc)};
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_INT_KV(si, "count", parsed.count);- In
RoundTrip.c:202:
} parsed = {0};
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_INT_KV(si, "big_int", parsed.big_int);- In
RoundTrip.c:269:
} parsed = {false, true, false, true}; // Initialize with opposite values
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_BOOL_KV(si, "flag1", parsed.flag1);- In
RoundTrip.c:329:
} parsed = {StrInit(&alloc), StrInit(&alloc), StrInit(&alloc), StrInit(&alloc)};
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_STR_KV(si, "empty", parsed.empty);- In
RoundTrip.c:401:
Vec(Str) parsed_strings = VecInitWithDeepCopy(NULL, StrDeinit, &alloc);
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_ARR_KV(si, "numbers", {- In
RoundTrip.c:493:
TestPerson parsed_person = {0, StrInit(&alloc), 0, false, 0.0};
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_OBJ_KV(si, "user", {- In
RoundTrip.c:592:
parsed.flags = VecInitT(parsed.flags, &alloc);
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_OBJ_KV(si, "user", {- In
RoundTrip.c:700:
bool found_empty_object = false;
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_STR_KV(si, "empty_string", parsed_str);- In
RoundTrip.c:783:
} parsed = {0, 0, 999, 999.0, false, true}; // Initialize with different values
StrIter si = StrIterFromStr(json);
JR_OBJ(si, {
JR_INT_KV(si, "max_int", parsed.max_int);- In
Parse.c:16:
&alloc
);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);
Str *host = KvConfigGetPtr(&cfg, "host");- In
Parse.c:49:
&alloc
);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);
Str *path = KvConfigGetPtr(&cfg, "path");- In
Parse.c:74:
KvConfig cfg = KvConfigInit(&alloc);
Str src = StrInitFromZstr("host = localhost\n", &alloc);
StrIter input = StrIterFromStr(src);
Str host_copy = StrInit(&alloc);
Str *stored_host = NULL;- In
Parse.c:119:
bool disabled = true;
bool result = true;
StrIter input = StrIterFromStr(src);
(void)KvConfigParse(input, &cfg);- In
Parse.c:146:
&alloc
);
StrIter input = StrIterFromStr(src);
StrIter si = KvConfigParse(input, &cfg);
bool enabled = false;
Last updated on