StrAppendFmt
Description
Append a formatted string to out. Existing contents are preserved; new content lands at the end of the buffer.
Parameters
| Name | Direction | Description |
|---|---|---|
out |
out | Destination Str. Existing bytes are kept. |
fmtstr |
in | Format string with {} placeholders. |
Success
out extended with the formatted content; returns true.
Failure
Returns false. May log diagnostics; out may be left partially extended on allocation failure mid-write.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Log.h:44:
HeapAllocator UNPL(log_alloc) = HeapAllocatorInit(); \
Str UNPL(m) = StrInit(&UNPL(log_alloc)); \
StrAppendFmt(&UNPL(m), __VA_ARGS__); \
LogWrite(LOG_MESSAGE_TYPE_FATAL, __func__, __LINE__, StrBegin(&UNPL(m))); \
StrDeinit(&UNPL(m)); \
- In
Log.h:68:
HeapAllocator UNPL(log_alloc) = HeapAllocatorInit(); \
Str UNPL(m) = StrInit(&UNPL(log_alloc)); \
StrAppendFmt(&UNPL(m), __VA_ARGS__); \
LogWrite(LOG_MESSAGE_TYPE_ERROR, __func__, __LINE__, StrBegin(&UNPL(m))); \
StrDeinit(&UNPL(m)); \
- In
Log.h:91:
HeapAllocator UNPL(log_alloc) = HeapAllocatorInit(); \
Str UNPL(m) = StrInit(&UNPL(log_alloc)); \
StrAppendFmt(&UNPL(m), __VA_ARGS__); \
LogWrite(LOG_MESSAGE_TYPE_INFO, __func__, __LINE__, StrBegin(&UNPL(m))); \
StrDeinit(&UNPL(m)); \
- In
Log.h:126:
HeapAllocator UNPL(log_alloc) = HeapAllocatorInit(); \
Str UNPL(m) = StrInit(&UNPL(log_alloc)); \
StrAppendFmt(&UNPL(m), __VA_ARGS__); \
StrInitStack(UNPL(syserr), 256) { \
StrError(UNPL(sys_eno), &UNPL(syserr)); \
- In
Log.h:129:
StrInitStack(UNPL(syserr), 256) { \
StrError(UNPL(sys_eno), &UNPL(syserr)); \
StrAppendFmt(&UNPL(m), " : {}", UNPL(syserr)); \
} \
LogWrite(LOG_MESSAGE_TYPE_FATAL, __func__, __LINE__, StrBegin(&UNPL(m))); \
- In
Log.h:155:
HeapAllocator UNPL(log_alloc) = HeapAllocatorInit(); \
Str UNPL(m) = StrInit(&UNPL(log_alloc)); \
StrAppendFmt(&UNPL(m), __VA_ARGS__); \
StrInitStack(UNPL(syserr), 256) { \
StrError(UNPL(sys_eno), &UNPL(syserr)); \
- In
Log.h:158:
StrInitStack(UNPL(syserr), 256) { \
StrError(UNPL(sys_eno), &UNPL(syserr)); \
StrAppendFmt(&UNPL(m), " : {}", UNPL(syserr)); \
} \
LogWrite(LOG_MESSAGE_TYPE_ERROR, __func__, __LINE__, StrBegin(&UNPL(m))); \
- In
Log.h:183:
HeapAllocator UNPL(log_alloc) = HeapAllocatorInit(); \
Str UNPL(m) = StrInit(&UNPL(log_alloc)); \
StrAppendFmt(&UNPL(m), __VA_ARGS__); \
StrInitStack(UNPL(syserr), 256) { \
StrError(UNPL(sys_eno), &UNPL(syserr)); \
- In
Log.h:186:
StrInitStack(UNPL(syserr), 256) { \
StrError(UNPL(sys_eno), &UNPL(syserr)); \
StrAppendFmt(&UNPL(m), " : {}", UNPL(syserr)); \
} \
LogWrite(LOG_MESSAGE_TYPE_INFO, __func__, __LINE__, StrBegin(&UNPL(m))); \
- In
Proc.h:341:
do { \
Str UNPL(buf) = StrInit(); \
StrAppendFmt(&UNPL(buf), __VA_ARGS__); \
ProcWriteToStdin((p), &UNPL(buf)); \
StrDeinit(&UNPL(buf)); \
- In
Proc.h:366:
do { \
Str UNPL(buf) = StrInit(); \
StrAppendFmt(&UNPL(buf), __VA_ARGS__); \
StrPushBackR(&UNPL(buf), '\n'); \
ProcWriteToStdin((p), &UNPL(buf)); \
- In
JSON.h:745:
StrPushBackR(&(j), ','); \
} \
StrAppendFmt(&(j), "\"{}\":", (Zstr)(k)); \
JW_OBJ(j, writer); \
} while (0)- In
JSON.h:811:
StrPushBackR(&(j), ','); \
} \
StrAppendFmt(&(j), "\"{}\":", (Zstr)(k)); \
JW_ARR(j, arr, item, writer); \
} while (0)- In
JSON.h:832:
do { \
i64 UNPL(my_int) = (i); \
StrAppendFmt(&(j), "{}", UNPL(my_int)); \
} while (0)- In
JSON.h:857:
StrPushBackR(&(j), ','); \
} \
StrAppendFmt(&(j), "\"{}\":", (Zstr)(k)); \
JW_INT(j, i); \
} while (0)- In
JSON.h:878:
do { \
f64 UNPL(my_flt) = (f); \
StrAppendFmt(&(j), "{}", UNPL(my_flt)); \
} while (0)- In
JSON.h:903:
StrPushBackR(&(j), ','); \
} \
StrAppendFmt(&(j), "\"{}\":", (Zstr)(k)); \
JW_FLT(j, f); \
} while (0)- In
JSON.h:925:
const Str *UNPL(jw_s) = &(s); \
u64 UNPL(jw_len) = StrLen(UNPL(jw_s)); \
StrAppendFmt(&(j), "\"{}\"", UNPL(jw_len) ? (Zstr)StrBegin(UNPL(jw_s)) : (Zstr) ""); \
} while (0)- In
JSON.h:950:
StrPushBackR(&(j), ','); \
} \
StrAppendFmt(&(j), "\"{}\":", (Zstr)(k)); \
JW_STR(j, s); \
} while (0)- In
JSON.h:970:
#define JW_BOOL(j, b) \
do { \
StrAppendFmt(&(j), "{}", (Zstr)((b) ? "true" : "false")); \
} while (0)- In
JSON.h:995:
StrPushBackR(&(j), ','); \
} \
StrAppendFmt(&(j), "\"{}\":", (Zstr)(k)); \
JW_BOOL(j, b); \
} while (0)- In
Sys.c:242:
ValidateStr(err_str);
StrClear(err_str);
StrAppendFmt(err_str, "{} (errno {})", errno_description(eno), eno);
return err_str;
}- In
Log.c:55:
HeapAllocator h = HeapAllocatorInit();
Str full = StrInit(&h);
StrAppendFmt(&full, "[{}] [{}:{}] {}\n", (Zstr)NAMES[type], (Zstr)tag, line, (Zstr)msg);
File out = (type == LOG_MESSAGE_TYPE_INFO) ? FileFromFd(1) : FileFromFd(2);- In
Io.c:1670:
LOG_FATAL("Invalid arguments");
}
if (!StrAppendFmt(
o,
"{04}-{02}-{02}T{02}:{02}:{02}",- In
Io.c:1682:
return false;
}
if (dt->nanosecond != 0 && !StrAppendFmt(o, ".{09}", dt->nanosecond)) {
return false;
}- In
Io.c:1686:
}
if (dt->utc_offset_seconds == 0) {
return StrAppendFmt(o, "Z");
}
i32 off = dt->utc_offset_seconds;- In
Io.c:1693:
u32 om = (ao % 3600) / 60;
if (off < 0) {
return StrAppendFmt(o, "-{02}:{02}", oh, om);
}
return StrAppendFmt(o, "+{02}:{02}", oh, om);- In
Io.c:1695:
return StrAppendFmt(o, "-{02}:{02}", oh, om);
}
return StrAppendFmt(o, "+{02}:{02}", oh, om);
}- In
Debug.c:295:
// so emit raw IPs in this build.
for (size i = 0; i < count; ++i) {
StrAppendFmt(&rendered, " #{} {x}\n", (u32)i, (u64)frames[i].ip);
}
#endif- In
Debug.c:535:
return;
StrAppendFmt(out, "DebugAllocator: {} live allocation(s):\n", (u64)MapPairCount(&self->live));
MapForeachPairPtr(&self->live, key_ptr, val_ptr) {
StrAppendFmt(out, " leak: {x} ({} bytes)\n", (u64)*key_ptr, (u64)val_ptr->requested_size);- In
Debug.c:537:
StrAppendFmt(out, "DebugAllocator: {} live allocation(s):\n", (u64)MapPairCount(&self->live));
MapForeachPairPtr(&self->live, key_ptr, val_ptr) {
StrAppendFmt(out, " leak: {x} ({} bytes)\n", (u64)*key_ptr, (u64)val_ptr->requested_size);
if (val_ptr->alloc_trace_n > 0) {
#if !defined(LOG_NO_BACKTRACE) || !LOG_NO_BACKTRACE- In
Debug.c:543:
#else
for (size i = 0; i < val_ptr->alloc_trace_n; ++i) {
StrAppendFmt(out, " #{} {x}\n", (u32)i, (u64)val_ptr->alloc_trace[i].ip);
}
#endif- In
Dir.c:558:
bool inner_ok = false;
StrInitStack(child, DIR_REMOVE_ALL_PATH_CAP) {
StrAppendFmt(&child, trail_sep ? "{}{}" : "{}/{}", path, entry_nm);
if (e->type == DIR_ENTRY_TYPE_DIRECTORY) {
inner_ok = DirRemoveAll(&child);- In
Backtrace.c:246:
if (named) {
StrAppendFmt(out, " #{} {}+{x} [{x}]", (u32)i, sym_name, (u64)sym_off, (u64)ip);
} else {
StrAppendFmt(out, " #{} {x}", (u32)i, (u64)ip);- In
Backtrace.c:248:
StrAppendFmt(out, " #{} {}+{x} [{x}]", (u32)i, sym_name, (u64)sym_off, (u64)ip);
} else {
StrAppendFmt(out, " #{} {x}", (u32)i, (u64)ip);
}- In
Backtrace.c:254:
if (g_dbghelp_initialized && SymGetLineFromAddr64(proc, ip, &line_disp, &line) && line.FileName) {
Zstr fname = sys_basename_of(line.FileName);
StrAppendFmt(out, " ({}:{})", fname, (u32)line.LineNumber);
}
StrPushBackR(out, '\n');- In
Backtrace.c:412:
if (named) {
Zstr mod = sys_basename_of(mod_path);
StrAppendFmt(out, " #{} {}!{}+{x} [{x}]\n", (u32)i, mod, sym_name, (u64)sym_off, ip);
} else if (mod_path) {
Zstr mod = sys_basename_of(mod_path);- In
Backtrace.c:415:
} else if (mod_path) {
Zstr mod = sys_basename_of(mod_path);
StrAppendFmt(out, " #{} {}+? [{x}]\n", (u32)i, mod, ip);
} else {
StrAppendFmt(out, " #{} {x}\n", (u32)i, ip);- In
Backtrace.c:417:
StrAppendFmt(out, " #{} {}+? [{x}]\n", (u32)i, mod, ip);
} else {
StrAppendFmt(out, " #{} {x}\n", (u32)i, ip);
}
}- In
Backtrace.c:464:
if (r->symbol_name) {
Zstr mod = sys_basename_of(r->module_path);
StrAppendFmt(out, " #{} {}!{}+{x} [{x}]", idx, mod, r->symbol_name, r->offset, (u64)ip);
} else if (r->module_path) {
Zstr mod = sys_basename_of(r->module_path);- In
Backtrace.c:467:
} else if (r->module_path) {
Zstr mod = sys_basename_of(r->module_path);
StrAppendFmt(out, " #{} {}+{x} [{x}]", idx, mod, r->offset, (u64)ip);
} else {
StrAppendFmt(out, " #{} {x}", idx, (u64)ip);- In
Backtrace.c:469:
StrAppendFmt(out, " #{} {}+{x} [{x}]", idx, mod, r->offset, (u64)ip);
} else {
StrAppendFmt(out, " #{} {x}", idx, (u64)ip);
}
if (r->source_file) {- In
Backtrace.c:474:
Zstr file = sys_basename_of(r->source_file);
if (r->source_line > 0) {
StrAppendFmt(out, " ({}:{})", file, r->source_line);
} else {
StrAppendFmt(out, " ({})", file);- In
Backtrace.c:476:
StrAppendFmt(out, " ({}:{})", file, r->source_line);
} else {
StrAppendFmt(out, " ({})", file);
}
}- In
Backtrace.c:488:
emit_resolved_line(out, (u32)i, &r, frames[i].ip);
} else {
StrAppendFmt(out, " #{} {x}\n", (u32)i, (u64)frames[i].ip);
}
}- In
Backtrace.c:497:
if (!SymbolResolverInit(&res, alloc)) {
for (size i = 0; i < count; ++i) {
StrAppendFmt(out, " #{} {x}\n", (u32)i, (u64)frames[i].ip);
}
return;- In
Socket.c:475:
StrResize(&host, ZstrLen(host_data));
port = FROM_BIG_ENDIAN2(sa->sin_port);
StrAppendFmt(&out, "{}:{}", (Zstr)host_data, (u32)port);
} else if (addr->family == SOCKET_FAMILY_INET6) {
const struct sockaddr_in6 *sa = (const struct sockaddr_in6 *)addr->raw;- In
Socket.c:486:
StrResize(&host, ZstrLen(host_data));
port = FROM_BIG_ENDIAN2(sa->sin6_port);
StrAppendFmt(&out, "[{}]:{}", (Zstr)host_data, (u32)port);
} else {
LOG_ERROR("SocketAddrFormat: unknown family {}", (u32)addr->family);- In
Http.c:471:
}
StrAppendFmt(
&out,
"HTTP/1.1 {}\r\n"- In
Http.c:482:
VecForeachPtr(&response->headers, header) {
StrAppendFmt(&out, "{}: {}\r\n", header->key, header->value);
}- In
Http.c:485:
}
StrAppendFmt(&out, "\r\n");
if (StrLen(&response->body)) {- In
File.c:966:
Str in = StrInit(alloc_base);
StrAppendFmt(&in, "string-content");
i64 wrote = FileWriteAndClose(&path, &in); // Build the out-of-range marker "#N " that only the `<=` mutant emits.
Str ns = StrInit(&scratch);
StrAppendFmt(&ns, "#{} ", n);
ok = ok && (ZstrFindSubstring(StrBegin(&out), "leak:") != NULL);- In
DateTime.c:148:
Str s = StrInit(&alloc);
DateTime d = DateTimeFromUnixNs(T_2021 * NS_PER_SEC, 0);
StrAppendFmt(&s, "{}", d);
bool ok = ZstrCompare(StrBegin(&s), "2021-01-01T00:00:00Z") == 0;
StrDeinit(&s);- In
DateTime.c:159:
Str s = StrInit(&alloc);
DateTime d = DateTimeFromUnixNs(T_2021 * NS_PER_SEC, IST);
StrAppendFmt(&s, "{}", d);
bool ok = ZstrCompare(StrBegin(&s), "2021-01-01T05:30:00+05:30") == 0;
StrDeinit(&s);- In
DateTime.c:170:
Str s = StrInit(&alloc);
DateTime d = DateTimeFromUnixNs(T_2021 * NS_PER_SEC + 123456789ull, 0);
StrAppendFmt(&s, "{}", d);
bool ok = ZstrCompare(StrBegin(&s), "2021-01-01T00:00:00.123456789Z") == 0;
StrDeinit(&s);- In
DateTime.c:182:
Str s = StrInit(&alloc);
DateTime a = DateTimeFromUnixNs(T_2021 * NS_PER_SEC + 123456789ull, MST);
StrAppendFmt(&s, "{}", a);
DateTime b = {0};- In
UserTypes.c:65:
return false;
}
return StrAppendFmt(o, "({}, {})", p->x, p->y);
}- In
UserTypes.c:85:
return false;
}
return StrAppendFmt(o, "[{}..{}]", b->min, b->max);
}- In
UserTypes.c:105:
return false;
}
return StrAppendFmt(o, "{}:{}@{}", r->id, r->bbox, r->centroid);
}- In
UserTypes.c:134:
Point2D p = {.x = 3, .y = 4};
bool ok = StrAppendFmt(&out, "{}", p);
ok = ok && (ZstrCompare(StrBegin(&out), "(3, 4)") == 0);- In
UserTypes.c:150:
Point2D p = {.x = -1, .y = 2};
i32 count = 7;
bool ok = StrAppendFmt(&out, "got {} hits at {}", count, p);
ok = ok && (ZstrCompare(StrBegin(&out), "got 7 hits at (-1, 2)") == 0);- In
UserTypes.c:178:
Point2D dst = {0};
bool ok = StrAppendFmt(&out, "{}", src);
Zstr in = StrBegin(&out);
StrReadFmt(in, "{}", dst);- In
UserTypes.c:198:
.max = {.x = 10, .y = 20}
};
bool ok = StrAppendFmt(&out, "{}", b);
ok = ok && (ZstrCompare(StrBegin(&out), "[(0, 0)..(10, 20)]") == 0);- In
UserTypes.c:218:
Bounds dst = {0};
bool ok = StrAppendFmt(&out, "{}", src);
Zstr in = StrBegin(&out);
StrReadFmt(in, "{}", dst);- In
UserTypes.c:241:
.centroid = { .x = 50, .y = 25},
};
bool ok = StrAppendFmt(&out, "{}", r);
ok = ok && (ZstrCompare(StrBegin(&out), "42:[(0, 0)..(100, 50)]@(50, 25)") == 0);- In
UserTypes.c:262:
Region dst = {0};
bool ok = StrAppendFmt(&out, "{}", src);
Zstr in = StrBegin(&out);
StrReadFmt(in, "{}", dst);- In
UserTypes.c:295:
// arms (i32 implicit, Region, Point2D, f64) and proves nested user
// types and built-ins coexist in one IOFMT expansion.
bool ok = StrAppendFmt(&out, "score={.1} region={} origin={}", score, region, origin);
ok = ok && (ZstrCompare(StrBegin(&out), "score=1.5 region=7:[(1, 2)..(3, 4)]@(2, 3) origin=(0, 0)") == 0);- In
Write.c:45:
bool success = true;
StrAppendFmt(&output, "");
success = success && (StrLen(&output) == 0);
StrClear(&output);- In
Write.c:49:
StrClear(&output);
StrAppendFmt(&output, "Hello, world!");
success = success && (ZstrCompare(StrBegin(&output), "Hello, world!") == 0);
StrClear(&output);- In
Write.c:53:
StrClear(&output);
StrAppendFmt(&output, "{{Hello}}");
success = success && (ZstrCompare(StrBegin(&output), "{Hello}") == 0);
StrClear(&output);- In
Write.c:57:
StrClear(&output);
StrAppendFmt(&output, "{{{{");
success = success && (ZstrCompare(StrBegin(&output), "{{") == 0);- In
Write.c:74:
Zstr str = "Hello";
StrAppendFmt(&output, "{}", str);
success = success && (ZstrCompare(StrBegin(&output), "Hello") == 0);
StrClear(&output);- In
Write.c:79:
Zstr empty = "";
StrAppendFmt(&output, "{}", empty);
success = success && (StrLen(&output) == 0);
StrClear(&output);- In
Write.c:83:
StrClear(&output);
StrAppendFmt(&output, "{>10}", str);
success = success && (ZstrCompare(StrBegin(&output), " Hello") == 0);
StrClear(&output);- In
Write.c:87:
StrClear(&output);
StrAppendFmt(&output, "{<10}", str);
success = success && (ZstrCompare(StrBegin(&output), "Hello ") == 0);
StrClear(&output);- In
Write.c:91:
StrClear(&output);
StrAppendFmt(&output, "{^10}", str);
success = success && (ZstrCompare(StrBegin(&output), " Hello ") == 0);
StrClear(&output);- In
Write.c:96:
Str s = StrInitFromZstr("World", &alloc);
StrAppendFmt(&output, "{}", s);
success = success && (ZstrCompare(StrBegin(&output), "World") == 0);
StrDeinit(&s);- In
Write.c:114:
i8 i8_val = -42;
StrAppendFmt(&output, "{}", i8_val);
success = success && (ZstrCompare(StrBegin(&output), "-42") == 0);
StrClear(&output);- In
Write.c:119:
i16 i16_val = -1234;
StrAppendFmt(&output, "{}", i16_val);
success = success && (ZstrCompare(StrBegin(&output), "-1234") == 0);
StrClear(&output);- In
Write.c:124:
i32 i32_val = -123456;
StrAppendFmt(&output, "{}", i32_val);
success = success && (ZstrCompare(StrBegin(&output), "-123456") == 0);
StrClear(&output);- In
Write.c:129:
i64 i64_val = -1234567890LL;
StrAppendFmt(&output, "{}", i64_val);
success = success && (ZstrCompare(StrBegin(&output), "-1234567890") == 0);
StrClear(&output);- In
Write.c:134:
u8 u8_val = 42;
StrAppendFmt(&output, "{}", u8_val);
success = success && (ZstrCompare(StrBegin(&output), "42") == 0);
StrClear(&output);- In
Write.c:139:
u16 u16_val = 1234;
StrAppendFmt(&output, "{}", u16_val);
success = success && (ZstrCompare(StrBegin(&output), "1234") == 0);
StrClear(&output);- In
Write.c:144:
u32 u32_val = 123456;
StrAppendFmt(&output, "{}", u32_val);
success = success && (ZstrCompare(StrBegin(&output), "123456") == 0);
StrClear(&output);- In
Write.c:149:
u64 u64_val = 1234567890ULL;
StrAppendFmt(&output, "{}", u64_val);
success = success && (ZstrCompare(StrBegin(&output), "1234567890") == 0);
StrClear(&output);- In
Write.c:154:
i8 i8_max = 127;
StrAppendFmt(&output, "{}", i8_max);
success = success && (ZstrCompare(StrBegin(&output), "127") == 0);
StrClear(&output);- In
Write.c:159:
i8 i8_min = -128;
StrAppendFmt(&output, "{}", i8_min);
success = success && (ZstrCompare(StrBegin(&output), "-128") == 0);
StrClear(&output);- In
Write.c:164:
u8 u8_max = 255;
StrAppendFmt(&output, "{}", u8_max);
success = success && (ZstrCompare(StrBegin(&output), "255") == 0);
StrClear(&output);- In
Write.c:169:
u8 u8_min = 0;
StrAppendFmt(&output, "{}", u8_min);
success = success && (ZstrCompare(StrBegin(&output), "0") == 0);- In
Write.c:186:
u32 val = 0xDEADBEEF;
StrAppendFmt(&output, "{x}", val);
success = success && (ZstrCompare(StrBegin(&output), "0xdeadbeef") == 0);
StrClear(&output);- In
Write.c:190:
StrClear(&output);
StrAppendFmt(&output, "{X}", val);
success = success && (ZstrCompare(StrBegin(&output), "0xDEADBEEF") == 0);- In
Write.c:207:
u8 val = 0xA5; // 10100101 in binary
StrAppendFmt(&output, "{b}", val);
success = success && (ZstrCompare(StrBegin(&output), "0b10100101") == 0);- In
Write.c:224:
u16 val = 0777;
StrAppendFmt(&output, "{o}", val);
success = success && (ZstrCompare(StrBegin(&output), "0o777") == 0);- In
Write.c:241:
f32 f32_val = 3.14159f;
StrAppendFmt(&output, "{}", f32_val);
success = success && (ZstrCompare(StrBegin(&output), "3.141590") == 0);
StrClear(&output);- In
Write.c:246:
f64 f64_val = 2.71828;
StrAppendFmt(&output, "{}", f64_val);
success = success && (ZstrCompare(StrBegin(&output), "2.718280") == 0);- In
Write.c:264:
f64 val = 3.14159265359;
StrAppendFmt(&output, "{.2}", val);
success = success && (ZstrCompare(StrBegin(&output), "3.14") == 0);
StrClear(&output);- In
Write.c:268:
StrClear(&output);
StrAppendFmt(&output, "{.0}", val);
success = success && (ZstrCompare(StrBegin(&output), "3") == 0);
StrClear(&output);- In
Write.c:272:
StrClear(&output);
StrAppendFmt(&output, "{.10}", val);
success = success && (ZstrCompare(StrBegin(&output), "3.1415926536") == 0);- In
Write.c:289:
f64 pos_inf = F64_INFINITY;
StrAppendFmt(&output, "{}", pos_inf);
success = success && (ZstrCompare(StrBegin(&output), "inf") == 0);
StrClear(&output);- In
Write.c:294:
f64 neg_inf = -F64_INFINITY;
StrAppendFmt(&output, "{}", neg_inf);
success = success && (ZstrCompare(StrBegin(&output), "-inf") == 0);
StrClear(&output);- In
Write.c:299:
f64 nan_val = F64_NAN;
StrAppendFmt(&output, "{}", nan_val);
success = success && (ZstrCompare(StrBegin(&output), "nan") == 0);- In
Write.c:316:
i32 val = 42;
StrAppendFmt(&output, "{5}", val);
success = success && (ZstrCompare(StrBegin(&output), " 42") == 0);
StrClear(&output);- In
Write.c:320:
StrClear(&output);
StrAppendFmt(&output, "{<5}", val);
success = success && (ZstrCompare(StrBegin(&output), "42 ") == 0);
StrClear(&output);- In
Write.c:324:
StrClear(&output);
StrAppendFmt(&output, "{^5}", val);
success = success && (ZstrCompare(StrBegin(&output), " 42 ") == 0);
StrClear(&output);- In
Write.c:329:
Zstr str = "abc";
StrAppendFmt(&output, "{5}", str);
success = success && (ZstrCompare(StrBegin(&output), " abc") == 0);
StrClear(&output);- In
Write.c:333:
StrClear(&output);
StrAppendFmt(&output, "{<5}", str);
success = success && (ZstrCompare(StrBegin(&output), "abc ") == 0);
StrClear(&output);- In
Write.c:337:
StrClear(&output);
StrAppendFmt(&output, "{^5}", str);
success = success && (ZstrCompare(StrBegin(&output), " abc ") == 0);- In
Write.c:357:
f64 pi = 3.14;
StrAppendFmt(&output, "{} {} {}", hello, num, pi);
success = success && (ZstrCompare(StrBegin(&output), "Hello 42 3.140000") == 0);
StrClear(&output);- In
Write.c:361:
StrClear(&output);
StrAppendFmt(&output, "{} {} {}", pi, hello, num);
success = success && (ZstrCompare(StrBegin(&output), "3.140000 Hello 42") == 0);- In
Write.c:378:
Zstr mixed_case = "MiXeD CaSe";
StrAppendFmt(&output, "{c}", mixed_case);
success = success && (ZstrCompare(StrBegin(&output), "MiXeD CaSe") == 0);
StrClear(&output);- In
Write.c:382:
StrClear(&output);
StrAppendFmt(&output, "{a}", mixed_case);
success = success && (ZstrCompare(StrBegin(&output), "mixed case") == 0);
StrClear(&output);- In
Write.c:386:
StrClear(&output);
StrAppendFmt(&output, "{A}", mixed_case);
success = success && (ZstrCompare(StrBegin(&output), "MIXED CASE") == 0);
StrClear(&output);- In
Write.c:392:
Str s = StrInitFromZstr("MiXeD CaSe", &alloc);
StrAppendFmt(&output, "{c}", s);
success = success && (ZstrCompare(StrBegin(&output), "MiXeD CaSe") == 0);
StrClear(&output);- In
Write.c:396:
StrClear(&output);
StrAppendFmt(&output, "{a}", s);
success = success && (ZstrCompare(StrBegin(&output), "mixed case") == 0);
StrClear(&output);- In
Write.c:400:
StrClear(&output);
StrAppendFmt(&output, "{A}", s);
success = success && (ZstrCompare(StrBegin(&output), "MIXED CASE") == 0);
StrClear(&output);- In
Write.c:407:
u8 lower_char = 'm';
StrAppendFmt(&output, "{c}", upper_char);
success = success && (ZstrCompare(StrBegin(&output), "M") == 0);
StrClear(&output);- In
Write.c:411:
StrClear(&output);
StrAppendFmt(&output, "{a}", upper_char);
success = success && (ZstrCompare(StrBegin(&output), "m") == 0);
StrClear(&output);- In
Write.c:415:
StrClear(&output);
StrAppendFmt(&output, "{A}", lower_char);
success = success && (ZstrCompare(StrBegin(&output), "M") == 0);
StrClear(&output);- In
Write.c:421:
u16 u16_value = ('A' << 8) | 'B'; // big-endian "AB"
StrAppendFmt(&output, "{c}", u16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'A' && StrBegin(&output)[1] == 'B');
StrClear(&output);- In
Write.c:425:
StrClear(&output);
StrAppendFmt(&output, "{a}", u16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'a' && StrBegin(&output)[1] == 'b');
StrClear(&output);- In
Write.c:429:
StrClear(&output);
StrAppendFmt(&output, "{A}", u16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'A' && StrBegin(&output)[1] == 'B');
StrClear(&output);- In
Write.c:435:
i16 i16_value = ('C' << 8) | 'd'; // big-endian "Cd"
StrAppendFmt(&output, "{c}", i16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'C' && StrBegin(&output)[1] == 'd');
StrClear(&output);- In
Write.c:439:
StrClear(&output);
StrAppendFmt(&output, "{a}", i16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'c' && StrBegin(&output)[1] == 'd');
StrClear(&output);- In
Write.c:443:
StrClear(&output);
StrAppendFmt(&output, "{A}", i16_value);
success = success && (StrLen(&output) == 2 && StrBegin(&output)[0] == 'C' && StrBegin(&output)[1] == 'D');
StrClear(&output);- In
Write.c:449:
u32 u32_value = ('E' << 24) | ('f' << 16) | ('G' << 8) | 'h'; // big-endian "EfGh"
StrAppendFmt(&output, "{c}", u32_value);
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'E' && StrBegin(&output)[1] == 'f' &&
StrBegin(&output)[2] == 'G' && StrBegin(&output)[3] == 'h');- In
Write.c:454:
StrClear(&output);
StrAppendFmt(&output, "{a}", u32_value);
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'e' && StrBegin(&output)[1] == 'f' &&
StrBegin(&output)[2] == 'g' && StrBegin(&output)[3] == 'h');- In
Write.c:459:
StrClear(&output);
StrAppendFmt(&output, "{A}", u32_value);
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'E' && StrBegin(&output)[1] == 'F' &&
StrBegin(&output)[2] == 'G' && StrBegin(&output)[3] == 'H');- In
Write.c:466:
i32 i32_value = ('I' << 24) | ('j' << 16) | ('K' << 8) | 'l'; // big-endian "IjKl"
StrAppendFmt(&output, "{c}", i32_value);
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'I' && StrBegin(&output)[1] == 'j' &&
StrBegin(&output)[2] == 'K' && StrBegin(&output)[3] == 'l');- In
Write.c:471:
StrClear(&output);
StrAppendFmt(&output, "{a}", i32_value);
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'i' && StrBegin(&output)[1] == 'j' &&
StrBegin(&output)[2] == 'k' && StrBegin(&output)[3] == 'l');- In
Write.c:476:
StrClear(&output);
StrAppendFmt(&output, "{A}", i32_value);
success = success && (StrLen(&output) == 4 && StrBegin(&output)[0] == 'I' && StrBegin(&output)[1] == 'J' &&
StrBegin(&output)[2] == 'K' && StrBegin(&output)[3] == 'L');- In
Write.c:484:
('r' << 16) | ('S' << 8) | 't'; // big-endian "MnOpQrSt"
StrAppendFmt(&output, "{c}", u64_value);
success = success && (StrLen(&output) == 8 && StrBegin(&output)[0] == 'M' && StrBegin(&output)[1] == 'n' &&
StrBegin(&output)[2] == 'O' && StrBegin(&output)[3] == 'p' && StrBegin(&output)[4] == 'Q' &&- In
Write.c:490:
StrClear(&output);
StrAppendFmt(&output, "{a}", u64_value);
success = success && (StrLen(&output) == 8 && StrBegin(&output)[0] == 'm' && StrBegin(&output)[1] == 'n' &&
StrBegin(&output)[2] == 'o' && StrBegin(&output)[3] == 'p' && StrBegin(&output)[4] == 'q' &&- In
Write.c:496:
StrClear(&output);
StrAppendFmt(&output, "{A}", u64_value);
success = success && (StrLen(&output) == 8 && StrBegin(&output)[0] == 'M' && StrBegin(&output)[1] == 'N' &&
StrBegin(&output)[2] == 'O' && StrBegin(&output)[3] == 'P' && StrBegin(&output)[4] == 'Q' &&- In
Write.c:505:
('z' << 16) | ('1' << 8) | '2'; // big-endian "UvWxYz12"
StrAppendFmt(&output, "{c}", i64_value);
success = success && (StrLen(&output) == 8 && StrBegin(&output)[0] == 'U' && StrBegin(&output)[1] == 'v' &&
StrBegin(&output)[2] == 'W' && StrBegin(&output)[3] == 'x' && StrBegin(&output)[4] == 'Y' &&- In
Write.c:511:
StrClear(&output);
StrAppendFmt(&output, "{a}", i64_value);
success = success && (StrLen(&output) == 8 && StrBegin(&output)[0] == 'u' && StrBegin(&output)[1] == 'v' &&
StrBegin(&output)[2] == 'w' && StrBegin(&output)[3] == 'x' && StrBegin(&output)[4] == 'y' &&- In
Write.c:517:
StrClear(&output);
StrAppendFmt(&output, "{A}", i64_value);
success = success && (StrLen(&output) == 8 && StrBegin(&output)[0] == 'U' && StrBegin(&output)[1] == 'V' &&
StrBegin(&output)[2] == 'W' && StrBegin(&output)[3] == 'X' && StrBegin(&output)[4] == 'Y' &&- In
Write.c:538:
BitVec bv1 = BitVecFromStr("10110", alloc_base);
StrAppendFmt(&output, "{}", bv1);
success = success && (ZstrCompare(StrBegin(&output), "10110") == 0);
StrClear(&output);- In
Write.c:543:
BitVec bv_empty = BitVecInit(alloc_base);
StrAppendFmt(&output, "{}", bv_empty);
success = success && (StrLen(&output) == 0);
StrClear(&output);- In
Write.c:548:
BitVec bv2 = BitVecFromInteger(0xABCD, 16, alloc_base);
StrAppendFmt(&output, "{x}", bv2);
success = success && (ZstrCompare(StrBegin(&output), "0xabcd") == 0);
StrClear(&output);- In
Write.c:552:
StrClear(&output);
StrAppendFmt(&output, "{X}", bv2);
success = success && (ZstrCompare(StrBegin(&output), "0xABCD") == 0);
StrClear(&output);- In
Write.c:557:
BitVec bv3 = BitVecFromInteger(0755, 10, alloc_base);
StrAppendFmt(&output, "{o}", bv3);
success = success && (ZstrCompare(StrBegin(&output), "0o755") == 0);
StrClear(&output);- In
Write.c:561:
StrClear(&output);
StrAppendFmt(&output, "{>10}", bv1);
success = success && (ZstrCompare(StrBegin(&output), " 10110") == 0);
StrClear(&output);- In
Write.c:565:
StrClear(&output);
StrAppendFmt(&output, "{<10}", bv1);
success = success && (ZstrCompare(StrBegin(&output), "10110 ") == 0);
StrClear(&output);- In
Write.c:569:
StrClear(&output);
StrAppendFmt(&output, "{^10}", bv1);
success = success && (ZstrCompare(StrBegin(&output), " 10110 ") == 0);
StrClear(&output);- In
Write.c:574:
BitVec bv_zero = BitVecFromInteger(0, 1, alloc_base);
StrAppendFmt(&output, "{x}", bv_zero);
success = success && (ZstrCompare(StrBegin(&output), "0x0") == 0);
StrClear(&output);- In
Write.c:578:
StrClear(&output);
StrAppendFmt(&output, "{o}", bv_zero);
success = success && (ZstrCompare(StrBegin(&output), "0o0") == 0);
StrClear(&output);- In
Write.c:606:
Int oct_val = IntFrom(493, alloc_base);
StrAppendFmt(&output, "{}", big_dec);
success = success && (ZstrCompare(StrBegin(&output), "123456789012345678901234567890") == 0);
StrClear(&output);- In
Write.c:610:
StrClear(&output);
StrAppendFmt(&output, "{x}", hex_val);
success = success && (ZstrCompare(StrBegin(&output), "deadbeefcafebabe1234") == 0);
StrClear(&output);- In
Write.c:614:
StrClear(&output);
StrAppendFmt(&output, "{X}", hex_val);
success = success && (ZstrCompare(StrBegin(&output), "DEADBEEFCAFEBABE1234") == 0);
StrClear(&output);- In
Write.c:618:
StrClear(&output);
StrAppendFmt(&output, "{b}", bin_val);
success = success && (ZstrCompare(StrBegin(&output), "10100011") == 0);
StrClear(&output);- In
Write.c:622:
StrClear(&output);
StrAppendFmt(&output, "{o}", oct_val);
success = success && (ZstrCompare(StrBegin(&output), "755") == 0);
StrClear(&output);- In
Write.c:626:
StrClear(&output);
StrAppendFmt(&output, "{>34}", big_dec);
success = success && (ZstrCompare(StrBegin(&output), " 123456789012345678901234567890") == 0);- In
Write.c:650:
Float short_v = FloatFromStr("1.2", alloc_base);
StrAppendFmt(&output, "{}", exact);
success = success && (ZstrCompare(StrBegin(&output), "1234567890.012345") == 0);
StrClear(&output);- In
Write.c:654:
StrClear(&output);
StrAppendFmt(&output, "{e}", sci);
success = success && (ZstrCompare(StrBegin(&output), "1.234567e+04") == 0);
StrClear(&output);- In
Write.c:658:
StrClear(&output);
StrAppendFmt(&output, "{E}", sci);
success = success && (ZstrCompare(StrBegin(&output), "1.234567E+04") == 0);
StrClear(&output);- In
Write.c:662:
StrClear(&output);
StrAppendFmt(&output, "{.3}", short_v);
success = success && (ZstrCompare(StrBegin(&output), "1.200") == 0);
StrClear(&output);- In
Write.c:666:
StrClear(&output);
StrAppendFmt(&output, "{>18}", sci);
success = success && (ZstrCompare(StrBegin(&output), " 12345.67") == 0);- In
Write.c:683:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInit(&alloc);
StrAppendFmt(&s, "old prefix ");
StrWriteFmt(&s, "fresh {}", LVAL(42));
bool ok = (StrLen(&s) == 8) && (StrBegin(&s)[0] == 'f') && (StrBegin(&s)[StrLen(&s) - 1] == '2');- In
Write.c:698:
DefaultAllocator alloc = DefaultAllocatorInit();
Str s = StrInit(&alloc);
StrAppendFmt(&s, "AAAAAAAA");
size before_length = StrLen(&s);
bool ok = StrPatchFmt(&s, 2, "{}", LVAL(1234));- In
Write.c:724:
BufPushBytes(&b, (const u8 *)"hello", 5);
StrAppendFmt(&output, "{}", b); // Buf is a first-class {} argument now
bool ok = ZstrCompare(StrBegin(&output), "hello") == 0;- In
Write.c:748:
// 0x1B (ESC) is non-printable -> "\x1b".
u8 esc = 0x1B;
StrAppendFmt(&out, "{c}", esc);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x1b") == 0);
StrClear(&out);- In
Write.c:754:
// 0x07 (BEL) -> "\x07".
u8 bel = 0x07;
StrAppendFmt(&out, "{c}", bel);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x07") == 0);
StrClear(&out);- In
Write.c:760:
// 0xFF with caps spec -> uppercase hex digits "\xFF".
u8 hi = 0xFF;
StrAppendFmt(&out, "{A}", hi);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xFF") == 0);
StrClear(&out);- In
Write.c:766:
// 0xAB lowercase by default for {c}.
u8 ab = 0xAB;
StrAppendFmt(&out, "{c}", ab);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xab") == 0);- In
Write.c:916:
DateTime utc = DateTimeFromUnixNs(base, 0);
StrClear(&s);
StrAppendFmt(&s, "{}", utc);
ok = ok && ZstrCompare(StrBegin(&s), "2021-01-01T00:00:00Z") == 0;- In
Write.c:921:
DateTime ist = DateTimeFromUnixNs(base, 19800); // +05:30
StrClear(&s);
StrAppendFmt(&s, "{}", ist);
ok = ok && ZstrCompare(StrBegin(&s), "2021-01-01T05:30:00+05:30") == 0;- In
Write.c:926:
DateTime neg = DateTimeFromUnixNs(base, -34200); // -09:30
StrClear(&s);
StrAppendFmt(&s, "{}", neg);
ok = ok && ZstrCompare(StrBegin(&s), "2020-12-31T14:30:00-09:30") == 0;- In
Write.c:931:
DateTime frac = DateTimeFromUnixNs(base + 123456789ull, 0);
StrClear(&s);
StrAppendFmt(&s, "{}", frac);
ok = ok && ZstrCompare(StrBegin(&s), "2021-01-01T00:00:00.123456789Z") == 0;- In
Write.c:1190:
Str s = StrInitFromZstr("xyz", &alloc);
StrAppendFmt(&output, "AB");
// width 6, right-aligned: "xyz" (content_len 3) gets 3 pad spaces.
StrAppendFmt(&output, "{>6}", s);- In
Write.c:1192:
StrAppendFmt(&output, "AB");
// width 6, right-aligned: "xyz" (content_len 3) gets 3 pad spaces.
StrAppendFmt(&output, "{>6}", s);
// start_len was 2 ("AB"), content_len = StrLen(o) - start_len = 3, pad to
// width 6 => 3 spaces. StrPad with ALIGN_RIGHT pushes the pad to the FRONT
- In
Write.c:1214:
Str s = StrInitFromZstr("hi", &alloc);
StrAppendFmt(&output, "{<5}", s);
ok = ok && (ZstrCompare(StrBegin(&output), "hi ") == 0);- In
Write.c:1235:
StrPushBackR(&s, (char)0x0F); // single byte 0x0F -> "f"
StrAppendFmt(&output, "{X}", s);
ok = ok && (ZstrCompare(StrBegin(&output), "0x0F") == 0);- In
Write.c:1255:
StrPushBackR(&s, (char)0x0F);
StrAppendFmt(&output, "{x}", s);
ok = ok && (ZstrCompare(StrBegin(&output), "0x0f") == 0);- In
Write.c:1277:
StrPushBackR(&s, (char)0x02);
StrAppendFmt(&output, "{x}", s);
// gt_to_ge => " 0x01 0x02" (leading space); gt_to_le => "0x010x02".
ok = ok && (ZstrCompare(StrBegin(&output), "0x01 0x02") == 0);- In
Write.c:1298:
StrPushBackR(&s, (char)0x05);
StrAppendFmt(&output, "{x}", s);
ok = ok && (ZstrCompare(StrBegin(&output), "0x05") == 0);- In
Write.c:1316:
Str s = StrInitFromZstr("hello", &alloc);
StrAppendFmt(&output, "{.3}", s);
ok = ok && (ZstrCompare(StrBegin(&output), "hel") == 0);- In
Write.c:1334:
Str s = StrInitFromZstr("hello", &alloc);
StrAppendFmt(&output, "{.0}", s);
ok = ok && (StrLen(&output) == 0);- In
Write.c:1522:
Zstr s = "AB"; // 0x41 0x42
StrAppendFmt(&output, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&output), "0x41 0x42") == 0);- In
Write.c:1538:
Zstr s = "Z"; // 0x5a
StrAppendFmt(&output, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&output), "0x5a") == 0);- In
Write.c:1555:
Zstr s = "\xab"; // single byte 0xab
StrAppendFmt(&output, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&output), "0xab") == 0);- In
Write.c:1572:
Zstr s = "\xab";
StrAppendFmt(&output, "{X}", s);
bool ok = (ZstrCompare(StrBegin(&output), "0xAB") == 0);- In
Write.c:1588:
Zstr s = "\x05"; // single byte 0x05
StrAppendFmt(&output, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&output), "0x05") == 0);- In
Write.c:1603:
Zstr s = "\xfe";
StrAppendFmt(&output, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&output), "0xfe") == 0);- In
Write.c:1619:
Zstr s = "Hello";
StrAppendFmt(&output, "{.3}", s);
bool ok = (ZstrCompare(StrBegin(&output), "Hel") == 0);- In
Write.c:1635:
Zstr s = "Hi";
StrAppendFmt(&output, "{.10}", s);
bool ok = (ZstrCompare(StrBegin(&output), "Hi") == 0);- In
Write.c:1652:
Zstr s = "Hello";
StrAppendFmt(&output, "{.0}", s);
bool ok = (StrLen(&output) == 0);- In
Write.c:1668:
Zstr s = "Hello";
StrAppendFmt(&output, "{.1}", s);
bool ok = (ZstrCompare(StrBegin(&output), "H") == 0);- In
Write.c:1687:
Zstr s = "Hi";
StrAppendFmt(&output, "abc{>10}", s);
bool ok = (ZstrCompare(StrBegin(&output), " abcHi") == 0);- In
Write.c:1702:
Zstr s = "Hi";
StrAppendFmt(&output, "xy{<10}", s);
bool ok = (ZstrCompare(StrBegin(&output), "xyHi ") == 0);- In
Write.c:1717:
Zstr s = "";
StrAppendFmt(&output, "{>5}", s);
bool ok = (ZstrCompare(StrBegin(&output), " ") == 0);- In
Write.c:1983:
Float v = FloatFromStr("1.0", alloc_base);
StrAppendFmt(&output, "{e}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1e+00") == 0);- In
Write.c:2003:
Float v = FloatFromStr("0.0", alloc_base);
StrAppendFmt(&output, "{.0e}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "0e+00") == 0);- In
Write.c:2025:
Float v = FloatFromStr("0.0", alloc_base);
StrAppendFmt(&output, "{.3e}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "0.000e+00") == 0);- In
Write.c:2046:
Float v = FloatFromStr("12.0", alloc_base);
StrAppendFmt(&output, "{.2e}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1.20e+01") == 0);- In
Write.c:2066:
Float v = FloatFromStr("12345.67", alloc_base);
StrAppendFmt(&output, "{e}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1.234567e+04") == 0);
StrClear(&output);- In
Write.c:2070:
StrClear(&output);
StrAppendFmt(&output, "{E}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1.234567E+04") == 0);- In
Write.c:2560:
bool ok = true;
StrAppendFmt(&out, "{05}", (u32)42);
ok = ok && (ZstrCompare(StrBegin(&out), "00042") == 0);
ok = ok && (StrLen(&out) == 5);- In
Write.c:2582:
bool ok = true;
StrAppendFmt(&out, "{05}", (u32)12345);
ok = ok && (ZstrCompare(StrBegin(&out), "12345") == 0);
ok = ok && (StrLen(&out) == 5);- In
Write.c:2608:
bool ok = true;
StrAppendFmt(&out, "{06}", (i32)-42);
ok = ok && (ZstrCompare(StrBegin(&out), "-00042") == 0);
ok = ok && (StrLen(&out) == 6);- In
Write.c:2637:
bool ok = true;
StrAppendFmt(&out, "{05}", (i32)42);
ok = ok && (ZstrCompare(StrBegin(&out), "00042") == 0);- In
Write.c:2665:
bool ok = true;
StrAppendFmt(&out, "{08}", (i32)-7);
ok = ok && (ZstrCompare(StrBegin(&out), "-0000007") == 0);
ok = ok && (StrLen(&out) == 8);- In
Write.c:2690:
bool ok = true;
StrAppendFmt(&out, "{016x}", (u32)0xFF);
ok = ok && (ZstrCompare(StrBegin(&out), "00000000000000ff") == 0);
ok = ok && (StrLen(&out) == 16);- In
Write.c:2827:
f64 v = 1.5;
StrAppendFmt(&output, "{}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1.500000") == 0);- In
Write.c:2847:
f64 v = 1.5;
StrAppendFmt(&output, "{e}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1.500000e+00") == 0);- In
Write.c:2865:
f64 v = 1.5;
StrAppendFmt(&output, "{E}", v);
ok = ok && (ZstrCompare(StrBegin(&output), "1.500000E+00") == 0);- In
Write.c:2887:
f64 v = 1.5;
StrAppendFmt(&output, "{12}", v);
ok = ok && (ZstrCompare(StrBegin(&output), " 1.500000") == 0);
ok = ok && (StrLen(&output) == 12);- In
Write.c:2912:
f64 v = 1.5;
StrAppendFmt(&output, "{12}", v);
ok = ok && (ZstrCompare(StrBegin(&output), " XYZ1.500000") == 0);- In
Write.c:2931:
f64 v = 1.5;
StrAppendFmt(&output, "{12}", v);
ok = ok && (StrLen(&output) == 12);- In
Write.c:2953:
Float v = FloatFromStr("1.0", &alloc.base);
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1e+00") == 0);- In
Write.c:2973:
Float v = FloatFromStr("0.001", &alloc.base);
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1e-03") == 0);- In
Write.c:2992:
Float v = FloatFromStr("1e12", &alloc.base);
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1e+12") == 0);- In
Write.c:3082:
i64 v = 255; // 0xff
StrAppendFmt(&out, "{x}", v);
// Real: lowercase hex "0xff". base->42 mutant fails (not "0xff");
// and_to_or mutant would force caps -> "0xFF".
- In
Write.c:3097:
i64 v = 255;
StrAppendFmt(&out, "{X}", v);
// Real: uppercase hex "0xFF". ne_to_eq mutant inverts caps -> "0xff".
bool ok = (ZstrCompare(StrBegin(&out), "0xFF") == 0);- In
Write.c:3111:
i64 v = 5; // 0b101
StrAppendFmt(&out, "{b}", v);
bool ok = (ZstrCompare(StrBegin(&out), "0b101") == 0);- In
Write.c:3124:
i64 v = 8; // 0o10
StrAppendFmt(&out, "{o}", v);
bool ok = (ZstrCompare(StrBegin(&out), "0o10") == 0);- In
Write.c:3138:
i64 v = -42;
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "-42") == 0);- In
Write.c:3151:
i64 v = 42;
StrAppendFmt(&out, "X{5}", v);
bool ok = (ZstrCompare(StrBegin(&out), " X42") == 0);- In
Write.c:3166:
i64 v = 42;
StrAppendFmt(&out, "X{05}", v);
// start_len=1, content "42" len 2, width 5 -> three '0' fills: "X00042".
bool ok = (ZstrCompare(StrBegin(&out), "X00042") == 0);- In
Write.c:3232:
bool success = true;
StrAppendFmt(&output, "{c}", a);
success = (ZstrCompare(StrBegin(&output), "A") == 0);- In
Write.c:3251:
bool success = true;
StrAppendFmt(&output, "{c}", a);
success = (ZstrCompare(StrBegin(&output), "z") == 0);- In
Write.c:3276:
bool success = true;
StrAppendFmt(&output, "ab");
StrAppendFmt(&output, "{>6}", seven);
success = (ZstrCompare(StrBegin(&output), " ab7") == 0);- In
Write.c:3277:
StrAppendFmt(&output, "ab");
StrAppendFmt(&output, "{>6}", seven);
success = (ZstrCompare(StrBegin(&output), " ab7") == 0);- In
Write.c:3297:
i32 v = 5;
bool ok = !StrAppendFmt(&out, "{", v); // unclosed -> must return false
StrDeinit(&out);- In
Write.c:3315:
u8 v = 200;
bool ok = StrAppendFmt(&out, "{1r}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "200") == 0);- In
Write.c:3335:
u16 v = 258;
bool ok = StrAppendFmt(&out, "{2r}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "258") == 0);- In
Write.c:3355:
u32 v = 65538;
bool ok = StrAppendFmt(&out, "{4r}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "65538") == 0);- In
Write.c:3375:
u64 v = 4294967298ULL;
bool ok = StrAppendFmt(&out, "{8r}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "4294967298") == 0);- In
Write.c:3394:
i64 v = 4294967298LL;
bool ok = StrAppendFmt(&out, "{8r}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "4294967298") == 0);- In
Write.c:3413:
f64 v = 1.5;
bool ok = StrAppendFmt(&out, "{8r}", v);
ok = ok && (StrLen(&out) > 0); // returns false under the mutant
- In
Write.c:3436:
// Pre-existing content so start_len != 0 at the point _write_u64 runs.
StrAppendFmt(&out, "X:");
u64 v = 255;
// content_len = StrLen(o) - start_len = 3 ("255"), width 8 -> 5 pad spaces.
- In
Write.c:3441:
// StrPad ALIGN_RIGHT prepends the pad to the FRONT of the whole buffer, so
// the "X:" prefix rides along after the spaces: " X:255" (len 10).
StrAppendFmt(&out, "{8}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " X:255") == 0);- In
Write.c:3457:
u64 v = 7;
StrAppendFmt(&out, "{5}", v); // " 7"
ok = ok && (ZstrCompare(StrBegin(&out), " 7") == 0);
StrClear(&out);- In
Write.c:3462:
// Left-align variant so a dropped pad is unambiguous.
StrAppendFmt(&out, "{<5}", v); // "7 "
ok = ok && (ZstrCompare(StrBegin(&out), "7 ") == 0);- In
Write.c:3478:
bool ok = true;
StrAppendFmt(&out, "p"); // start_len = 1
u64 v = 42;
StrAppendFmt(&out, "{05}", v); // zero-pad width 5 -> "00042"
- In
Write.c:3480:
StrAppendFmt(&out, "p"); // start_len = 1
u64 v = 42;
StrAppendFmt(&out, "{05}", v); // zero-pad width 5 -> "00042"
ok = ok && (ZstrCompare(StrBegin(&out), "p00042") == 0);- In
Write.c:3635:
Float v = FloatFromStr("12345.67", alloc_base);
StrAppendFmt(&out, "{e}", v);
bool ok = ZstrCompare(StrBegin(&out), "1.234567e+04") == 0;- In
Write.c:3654:
Float v = FloatFromStr("12345.67", alloc_base);
StrAppendFmt(&out, "{.2e}", v);
bool ok = ZstrCompare(StrBegin(&out), "1.23e+04") == 0;- In
Write.c:3679:
Float v = FloatFromStr("1.2", alloc_base);
StrAppendFmt(&out, "XX");
StrAppendFmt(&out, "{>5}", v);
bool ok = ZstrCompare(StrBegin(&out), " XX1.2") == 0 && StrLen(&out) == 7;- In
Write.c:3680:
StrAppendFmt(&out, "XX");
StrAppendFmt(&out, "{>5}", v);
bool ok = ZstrCompare(StrBegin(&out), " XX1.2") == 0 && StrLen(&out) == 7;- In
Write.c:3720:
BitVec bv = BitVecFromStr("1", alloc_base);
StrAppendFmt(&out, "XX{>5}", bv);
bool ok = (StrLen(&out) == 7) && (ZstrCompare(StrBegin(&out), " XX1") == 0);- In
Write.c:3843:
Zstr name = "hello";
StrAppendFmt(&output, "{s}", ZstrIO(name, alloc_base));
bool ok = (ZstrCompare(StrBegin(&output), "hello") == 0);- In
Write.c:3859:
i8 v = (i8)'Q';
StrAppendFmt(&output, "{c}", v);
bool ok = (StrLen(&output) == 1) && (StrBegin(&output)[0] == 'Q');- In
Write.c:3880:
MemCopy(&v, &bits, sizeof(v));
StrAppendFmt(&output, "{c}", v);
bool ok = (StrLen(&output) == 4) && (ZstrCompare(StrBegin(&output), "BCDE") == 0);- In
Write.c:3967:
Str src = StrInit(&alloc);
StrPushBackR(&src, 0x1A);
StrAppendFmt(&out, "{c}", src);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x1a") == 0);
StrClear(&out);- In
Write.c:3975:
// of the boundary too => "\xa1".
StrPushBackR(&src, 0xA1);
StrAppendFmt(&out, "{c}", src);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xa1") == 0);- In
Write.c:4001:
// "1.2" has 1 fractional digit; {.5} requests 5 -> 4 zeros are padded.
Float f = FloatFromStr("1.2", alloc_base);
StrAppendFmt(&out, "{.5}", f);
ok = ok && (ZstrCompare(StrBegin(&out), "1.20000") == 0);
StrClear(&out);- In
Write.c:4006:
Float g = FloatFromStr("3.14", alloc_base);
StrAppendFmt(&out, "{.6}", g);
ok = ok && (ZstrCompare(StrBegin(&out), "3.140000") == 0);- In
Write.c:4031:
// 255 is 3 digits; zero-pad to width 3 -> exactly fits, no leading zeros.
u32 v = 255;
StrAppendFmt(&out, "{03}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "255") == 0);
StrClear(&out);- In
Write.c:4036:
// Sanity: width one wider really does pad (guards against a no-op pad).
StrAppendFmt(&out, "{04}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "0255") == 0);- In
Write.c:4057:
// "abc" is 3 chars; field width 3 -> no padding at all.
Zstr s = "abc";
StrAppendFmt(&out, "{3}", s);
ok = ok && (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);- In
Write.c:4062:
// Left/center at the exact boundary likewise add nothing.
StrAppendFmt(&out, "{<3}", s);
ok = ok && (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);- In
Write.c:4066:
StrClear(&out);
StrAppendFmt(&out, "{^3}", s);
ok = ok && (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);- In
Write.c:4071:
// Sanity: width 4 does pad (one space, right-aligned default).
StrAppendFmt(&out, "{4}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " abc") == 0);- In
Write.c:4117:
bool ok = true;
StrAppendFmt(&s, "AAAAAAAA");
size before = StrLen(&s);
ok = ok && StrPatchFmt(&s, 2, "{}", LVAL(1234));- In
Write.c:4143:
Str s = StrInitFromZstr("hello", &alloc);
StrAppendFmt(&out, "{}", s); // width defaults to 0 -> no padding
ok = ok && (ZstrCompare(StrBegin(&out), "hello") == 0);- In
Write.c:4167:
f64 v = 3.14;
StrAppendFmt(&out, "{}", v); // default precision 6
ok = ok && (ZstrCompare(StrBegin(&out), "3.140000") == 0);
StrClear(&out);- In
Write.c:4171:
StrClear(&out);
StrAppendFmt(&out, "{.2}", v); // explicit precision 2
ok = ok && (ZstrCompare(StrBegin(&out), "3.14") == 0);- In
Write.c:4658:
bool ok = true;
StrAppendFmt(&out, "{05}", (u32)7);
ok = ok && (ZstrCompare(StrBegin(&out), "00007") == 0);- In
Write.c:4678:
bool ok = true;
StrAppendFmt(&out, "{007}", (u32)3);
ok = ok && (ZstrCompare(StrBegin(&out), "0000003") == 0);- In
Write.c:4695:
bool ok = true;
StrAppendFmt(&out, "{09}", (u32)3);
ok = ok && (ZstrCompare(StrBegin(&out), "000000003") == 0);- In
Write.c:4717:
bool ok = true;
StrAppendFmt(&out, "{9}", (u32)3);
ok = ok && (ZstrCompare(StrBegin(&out), " 3") == 0);
ok = ok && (StrLen(&out) == 9);- In
Write.c:4743:
Zstr s = "Hello";
bool rc = StrAppendFmt(&out, "{.9s}", s);
ok = ok && rc;
ok = ok && (ZstrCompare(StrBegin(&out), "Hello") == 0);- In
Write.c:4808:
Str out = StrInit(&alloc);
u32 v = 7;
StrAppendFmt(&out, "{05}", v);
bool ok = (ZstrCompare(StrBegin(&out), "00007") == 0);
StrDeinit(&out);- In
Write.c:4822:
Str out = StrInit(&alloc);
Zstr s = "ab";
StrAppendFmt(&out, "{4}", s);
bool ok = (ZstrCompare(StrBegin(&out), " ab") == 0);
StrClear(&out);- In
Write.c:4826:
StrClear(&out);
// Two-digit width exercises the width loop (151) more than once.
StrAppendFmt(&out, "{12}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " ab") == 0);
StrDeinit(&out);- In
Write.c:4841:
Str out = StrInit(&alloc);
f64 v = 3.14159;
StrAppendFmt(&out, "{.2}", v);
bool ok = (ZstrCompare(StrBegin(&out), "3.14") == 0);
StrClear(&out);- In
Write.c:4845:
StrClear(&out);
// multi-digit precision exercises the precision loop body (165).
StrAppendFmt(&out, "{.4}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "3.1416") == 0);
StrDeinit(&out);- In
Write.c:4857:
DefaultAllocator alloc = DefaultAllocatorInit();
Str out = StrInit(&alloc);
StrAppendFmt(&out, "literal");
i32 v = 5;
bool rc = StrAppendFmt(&out, "{.}", v);- In
Write.c:4859:
StrAppendFmt(&out, "literal");
i32 v = 5;
bool rc = StrAppendFmt(&out, "{.}", v);
// Real: false; output keeps only the prior "literal" (append stopped).
bool ok = (rc == false) && (ZstrCompare(StrBegin(&out), "literal") == 0);- In
Write.c:4876:
Str out = StrInit(&alloc);
i32 v = -7;
StrAppendFmt(&out, "{05}", v);
bool ok = (ZstrCompare(StrBegin(&out), "-0007") == 0);
StrDeinit(&out);- In
Write.c:4893:
Str out = StrInit(&alloc);
u32 v = 123;
StrAppendFmt(&out, "{03}", v);
bool ok = (ZstrCompare(StrBegin(&out), "123") == 0);
StrClear(&out);- In
Write.c:4896:
bool ok = (ZstrCompare(StrBegin(&out), "123") == 0);
StrClear(&out);
StrAppendFmt(&out, "{05}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "00123") == 0);
StrDeinit(&out);- In
Write.c:4909:
Str out = StrInit(&alloc);
Zstr s = "abc";
StrAppendFmt(&out, "{3}", s);
bool ok = (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);- In
Write.c:4912:
bool ok = (ZstrCompare(StrBegin(&out), "abc") == 0);
StrClear(&out);
StrAppendFmt(&out, "{5}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " abc") == 0);
StrDeinit(&out);- In
Write.c:4924:
DefaultAllocator alloc = DefaultAllocatorInit();
Str out = StrInit(&alloc);
StrAppendFmt(&out, "a{{b");
bool ok = (ZstrCompare(StrBegin(&out), "a{b") == 0);
StrDeinit(&out);- In
Write.c:4935:
DefaultAllocator alloc = DefaultAllocatorInit();
Str out = StrInit(&alloc);
StrAppendFmt(&out, "a}}b");
bool ok = (ZstrCompare(StrBegin(&out), "a}b") == 0);
StrDeinit(&out);- In
Write.c:4948:
Str out = StrInit(&alloc);
u32 v = 0xAB;
StrAppendFmt(&out, "{x}", v);
bool ok = (ZstrCompare(StrBegin(&out), "0xab") == 0);
StrDeinit(&out);- In
Write.c:4964:
Str out = StrInit(&alloc);
u16 v = 0x1234; // 4660
bool rc = StrAppendFmt(&out, "{<2r}", v);
bool ok = rc && (ZstrCompare(StrBegin(&out), "4660") == 0);
StrDeinit(&out);- In
Write.c:4977:
Str out = StrInit(&alloc);
u64 v = 0x0102030405060708ULL; // 72623859790382856
bool rc = StrAppendFmt(&out, "{>8r}", v);
bool ok = rc && (ZstrCompare(StrBegin(&out), "72623859790382856") == 0);
StrDeinit(&out);- In
Write.c:5069:
StrPushBackR(&s, (char)0x01);
StrPushBackR(&s, (char)0x4F); // multi-digit so StrLen(&hex)!=1 path
StrAppendFmt(&out, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&out), "0x01 0x4f") == 0);
StrDeinit(&s);- In
Write.c:5081:
Str s = StrInit(&dbg);
StrPushBackR(&s, (char)0x05);
StrAppendFmt(&out, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&out), "0x05") == 0);
StrDeinit(&s);- In
Write.c:5091:
DBG_BEGIN(dbg, out);
Zstr s = "\x01\x4f";
StrAppendFmt(&out, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&out), "0x01 0x4f") == 0);
return ok && dbg_no_leak(&dbg, &out);- In
Write.c:5099:
DBG_BEGIN(dbg, out);
Zstr s = "\x05";
StrAppendFmt(&out, "{x}", s);
bool ok = (ZstrCompare(StrBegin(&out), "0x05") == 0);
return ok && dbg_no_leak(&dbg, &out);- In
Write.c:5110:
Str out = StrInit(&alloc);
Str s = StrInitFromZstr("hi", &alloc);
StrAppendFmt(&out, "{}", s); // width 0 default
bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);
StrClear(&out);- In
Write.c:5113:
bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);
StrClear(&out);
StrAppendFmt(&out, "{5}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " hi") == 0);
StrDeinit(&s);- In
Write.c:5125:
Str out = StrInit(&alloc);
Zstr s = "hi";
StrAppendFmt(&out, "{}", s);
bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);
StrClear(&out);- In
Write.c:5128:
bool ok = (ZstrCompare(StrBegin(&out), "hi") == 0);
StrClear(&out);
StrAppendFmt(&out, "{5}", s);
ok = ok && (ZstrCompare(StrBegin(&out), " hi") == 0);
StrDeinit(&out);- In
Write.c:5142:
DBG_BEGIN(dbg, out);
u64 v = 1234567890ULL;
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1234567890") == 0);
return ok && dbg_no_leak(&dbg, &out);- In
Write.c:5150:
DBG_BEGIN(dbg, out);
i64 v = -1234567890LL;
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "-1234567890") == 0);
return ok && dbg_no_leak(&dbg, &out);- In
Write.c:5160:
Str out = StrInit(&alloc);
u64 v = 42;
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "42") == 0);
StrClear(&out);- In
Write.c:5163:
bool ok = (ZstrCompare(StrBegin(&out), "42") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 42") == 0);
StrDeinit(&out);- In
Write.c:5174:
Str out = StrInit(&alloc);
i64 v = -42;
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "-42") == 0);
StrClear(&out);- In
Write.c:5177:
bool ok = (ZstrCompare(StrBegin(&out), "-42") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " -42") == 0);
StrDeinit(&out);- In
Write.c:5194:
((u64)'F' << 16) | ((u64)'G' << 8) | (u64)'H';
MemCopy(&v, &bits, sizeof(v));
StrAppendFmt(&out, "{c}", v);
bool ok = (ZstrCompare(StrBegin(&out), "ABCDEFGH") == 0);
StrDeinit(&out);- In
Write.c:5206:
Str out = StrInit(&alloc);
f64 ninf = -F64_INFINITY;
StrAppendFmt(&out, "{}", ninf);
bool ok = (ZstrCompare(StrBegin(&out), "-inf") == 0);
StrClear(&out);- In
Write.c:5210:
StrClear(&out);
f64 pinf = F64_INFINITY;
StrAppendFmt(&out, "{}", pinf);
ok = ok && (ZstrCompare(StrBegin(&out), "inf") == 0);
StrDeinit(&out);- In
Write.c:5225:
Str out = StrInit(&alloc);
f64 v = 1.5;
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.500000") == 0);
StrClear(&out);- In
Write.c:5229:
StrClear(&out);
// explicit precision 2 to contrast.
StrAppendFmt(&out, "{.2}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "1.50") == 0);
StrDeinit(&out);- In
Write.c:5240:
DBG_BEGIN(dbg, out);
f64 v = 2.71828;
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "2.718280") == 0);
return ok && dbg_no_leak(&dbg, &out);- In
Write.c:5250:
Str out = StrInit(&alloc);
f64 v = 1.5;
StrAppendFmt(&out, "{.1}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.5") == 0);
StrClear(&out);- In
Write.c:5253:
bool ok = (ZstrCompare(StrBegin(&out), "1.5") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6.1}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 1.5") == 0);
StrDeinit(&out);- In
Write.c:5267:
Str out = StrInit(&alloc);
Float v = FloatFromStr("12345.67", ab);
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.234567e+04") == 0);
StrClear(&out);- In
Write.c:5271:
StrClear(&out);
Float w = FloatFromStr("0.001234", ab);
StrAppendFmt(&out, "{e}", w);
ok = ok && (ZstrCompare(StrBegin(&out), "1.234e-03") == 0);
FloatDeinit(&v);- In
Write.c:5291:
Str out = StrInit(&alloc);
Float v = FloatFromStr("1.0", ab);
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1e+00") == 0);
FloatDeinit(&v);- In
Write.c:5306:
Str out = StrInit(&alloc);
Float v = FloatFromStr("2.0", ab);
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "2e+00") == 0);
FloatDeinit(&v);- In
Write.c:5320:
DBG_BEGIN(dbg, out);
Float v = FloatFromStr("1234567890.012345", &dbg.base);
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1234567890.012345") == 0);
FloatDeinit(&v);- In
Write.c:5332:
Str out = StrInit(&alloc);
Float v = FloatFromStr("3.14159", ab);
StrAppendFmt(&out, "{.2}", v);
bool ok = (ZstrCompare(StrBegin(&out), "3.14") == 0);
StrClear(&out);- In
Write.c:5336:
StrClear(&out);
// precision longer than frac pads with zeros.
StrAppendFmt(&out, "{.8}", v);
ok = ok && (ZstrCompare(StrBegin(&out), "3.14159000") == 0);
FloatDeinit(&v);- In
Write.c:5351:
Str out = StrInit(&alloc);
Float v = FloatFromStr("5", ab);
StrAppendFmt(&out, "{.3}", v);
bool ok = (ZstrCompare(StrBegin(&out), "5.000") == 0);
FloatDeinit(&v);- In
Write.c:5362:
DBG_BEGIN(dbg, out);
Float v = FloatFromStr("12345.67", &dbg.base);
StrAppendFmt(&out, "{e}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.234567e+04") == 0);
FloatDeinit(&v);- In
Write.c:5375:
Str out = StrInit(&alloc);
Float v = FloatFromStr("1.5", ab);
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "1.5") == 0);
StrClear(&out);- In
Write.c:5378:
bool ok = (ZstrCompare(StrBegin(&out), "1.5") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 1.5") == 0);
FloatDeinit(&v);- In
Write.c:5394:
Str out = StrInit(&alloc);
Float v = FloatFromStr("1.5", ab);
StrAppendFmt(&out, "AB");
StrAppendFmt(&out, "{>6}", v);
bool ok = (ZstrCompare(StrBegin(&out), " AB1.5") == 0);- In
Write.c:5395:
Float v = FloatFromStr("1.5", ab);
StrAppendFmt(&out, "AB");
StrAppendFmt(&out, "{>6}", v);
bool ok = (ZstrCompare(StrBegin(&out), " AB1.5") == 0);
FloatDeinit(&v);- In
Write.c:5409:
DBG_BEGIN(dbg, out);
BitVec bv = BitVecFromStr("10110", &dbg.base);
StrAppendFmt(&out, "{}", bv);
bool ok = (ZstrCompare(StrBegin(&out), "10110") == 0);
BitVecDeinit(&bv);- In
Write.c:5421:
Str out = StrInit(&alloc);
BitVec bv = BitVecFromStr("101", ab);
StrAppendFmt(&out, "{}", bv);
bool ok = (ZstrCompare(StrBegin(&out), "101") == 0);
StrClear(&out);- In
Write.c:5424:
bool ok = (ZstrCompare(StrBegin(&out), "101") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", bv);
ok = ok && (ZstrCompare(StrBegin(&out), " 101") == 0);
BitVecDeinit(&bv);- In
Write.c:5438:
DBG_BEGIN(dbg, out);
Int v = IntFromStr("123456789012345678901234567890", &dbg.base);
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "123456789012345678901234567890") == 0);
IntDeinit(&v);- In
Write.c:5450:
Str out = StrInit(&alloc);
Int v = IntFrom(42, ab);
StrAppendFmt(&out, "{}", v);
bool ok = (ZstrCompare(StrBegin(&out), "42") == 0);
StrClear(&out);- In
Write.c:5453:
bool ok = (ZstrCompare(StrBegin(&out), "42") == 0);
StrClear(&out);
StrAppendFmt(&out, "{6}", v);
ok = ok && (ZstrCompare(StrBegin(&out), " 42") == 0);
IntDeinit(&v);- In
Write.c:5473:
DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
Str out = StrInit(ALLOCATOR_OF(&dbg));
bool ok = StrAppendFmt(&out, "{x}", s) && (StrLen(&out) > 0);
StrDeinit(&out);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);- In
Write.c:5485:
bool test_leak_write_f64_default_freed(void) {
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", 1e300) && (StrLen(&out) > 0);
LEAK_WRITE_EPILOGUE();
}- In
Write.c:5494:
Float f = FloatFromStr("12345678901234567890123456789012345678901234567890.5", ALLOCATOR_OF(&fa));
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", f) && (StrLen(&out) > 0);
StrDeinit(&out);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);- In
Write.c:5520:
Str out = StrInit(adbg);
bool ok = StrAppendFmt(&out, "{e}", v);
ok = ok && (StrLen(&out) > 0);- In
Write.c:5546:
Str out = StrInit(adbg);
bool ok = StrAppendFmt(&out, "{.3e}", v);
ok = ok && (StrLen(&out) > 0);- In
Write.c:5572:
Str out = StrInit(adbg);
bool ok = StrAppendFmt(&out, "{.2}", v);
ok = ok && (StrLen(&out) > 0);- In
Write.c:5599:
Str out = StrInit(adbg);
bool ok = StrAppendFmt(&out, "{.2}", v);
ok = ok && (StrLen(&out) > 0);- In
Write.c:5626:
Zstr s = "AB"; // multi-byte Zstr -> hex loop runs per byte
Str out = StrInit(adbg);
bool ok = StrAppendFmt(&out, "{x}", s);
ok = ok && (StrLen(&out) > 0);- In
Write.c:5650:
i32 v = -123456;
Str out = StrInit(adbg);
bool ok = StrAppendFmt(&out, "{}", v);
ok = ok && (StrLen(&out) > 0);- In
Write.c:5663:
bool test_leak_write_u64_temp_freed(void) {
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", (u64)12345678901234ull) && (StrLen(&out) > 0);
LEAK_WRITE_EPILOGUE();
}- In
Write.c:5669:
bool test_leak_write_f64_temp_freed(void) {
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", (f64)3.14159) && (StrLen(&out) > 0);
LEAK_WRITE_EPILOGUE();
}- In
Write.c:5676:
HeapAllocator va = HeapAllocatorInit();
Str s = StrInit(ALLOCATOR_OF(&va));
StrAppendFmt(&s, "payload");
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", s) && (StrLen(&out) > 0);- In
Write.c:5678:
StrAppendFmt(&s, "payload");
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", s) && (StrLen(&out) > 0);
StrDeinit(&out);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);- In
Write.c:5691:
Int v = IntFromStr("123456789012345678901234567890", ALLOCATOR_OF(&va));
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", v) && (StrLen(&out) > 0);
StrDeinit(&out);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);- In
Write.c:5704:
Float v = FloatFromStr("2.718281828", ALLOCATOR_OF(&va));
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", v) && (StrLen(&out) > 0);
StrDeinit(&out);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);- In
Write.c:5718:
BitVecResize(&v, 12);
LEAK_WRITE_PRELUDE();
ok = ok && StrAppendFmt(&out, "{}", v) && (StrLen(&out) > 0);
StrDeinit(&out);
ok = ok && (DebugAllocatorLiveCount(&dbg) == 0) && (DebugAllocatorLiveBytes(&dbg) == 0);- In
Read.c:1435:
Str out = StrInit(&alloc);
bool ok = StrAppendFmt(&out, "}}");
ok = ok && (ZstrCompare(StrBegin(&out), "}") == 0);- In
Read.c:1566:
u16 v = (u16)0x1AE0; // big-endian bytes: 0x1A, 0xE0
StrAppendFmt(&output, "{c}", v);
bool ok = (ZstrCompare(StrBegin(&output), "\\x1a\\xe0") == 0);- In
Read.c:1857:
Zstr b = "\x12";
StrAppendFmt(&out, "{c}", b);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x12") == 0);- In
Read.c:1875:
Zstr b = "\x90";
StrAppendFmt(&out, "{c}", b);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x90") == 0);- In
Read.c:1896:
Zstr b = "\xab";
StrAppendFmt(&out, "{c}", b);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xab") == 0);- In
Read.c:1916:
Zstr b = "\xcd";
StrAppendFmt(&out, "{c}", b);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xcd") == 0);- In
Read.c:1936:
Zstr b = "\xab";
StrAppendFmt(&out, "{A}", b);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xAB") == 0);- In
Read.c:1954:
Zstr b = "\xcd";
StrAppendFmt(&out, "{A}", b);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xCD") == 0);- In
Read.c:1973:
Zstr lo_letter = "\x1b";
StrAppendFmt(&out, "{c}", lo_letter);
ok = ok && (ZstrCompare(StrBegin(&out), "\\x1b") == 0);
StrClear(&out);- In
Read.c:1978:
Zstr hi_letter = "\xb1";
StrAppendFmt(&out, "{c}", hi_letter);
ok = ok && (ZstrCompare(StrBegin(&out), "\\xb1") == 0);- In
Init.c:148:
// Test StrAppendFmt function
bool test_str_WriteFmt(void) {
WriteFmt("Testing StrAppendFmt\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Init.c:153:
Str s = StrInit(&alloc);
StrAppendFmt(&s, "Hello, {}!", &"World"[0]);
// Validate the string
- In
Insert.c:338:
// StrAppendf formatter.
bool test_str_write_fmt_append(void) {
WriteFmt("Testing StrAppendFmt append\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Insert.c:345:
// Append formatted suffix.
StrAppendFmt(&s, " {} {}", (Zstr) "World", (u32)2023);
// Check that the string was appended correctly
- In
Foreach.c:44:
Str result = StrInit(&alloc);
StrForeachIdx(&s, chr, idx) {
StrAppendFmt(&result, "{c}{}", chr, idx);
}- In
Foreach.c:69:
StrForeachReverseIdx(&s, chr, idx) {
// Append the character and its index to the result string
StrAppendFmt(&result, "{c}{}", chr, idx);
}- In
Foreach.c:93:
StrForeachPtrIdx(&s, chrptr, idx) {
// Append the character (via pointer) and its index to the result string
StrAppendFmt(&result, "{c}{}", *chrptr, idx);
// Modify the original string by converting to uppercase
- In
Foreach.c:126:
StrForeachReversePtrIdx(&s, chrptr, idx) {
// Append the character (via pointer) and its index to the result string
StrAppendFmt(&result, "{c}{}", *chrptr, idx);
// Modify the original string by converting to uppercase
- In
Foreach.c:289:
StrForeachInRangeIdx(&s, chr, idx, 6, 11) {
// Append the character and its index to the result string
StrAppendFmt(&result, "{c}{}", chr, idx);
}- In
Foreach.c:359:
StrForeachPtrInRangeIdx(&s, chrptr, idx, 6, 11) {
// Append the character and its index to the result string
StrAppendFmt(&result, "{c}{}", *chrptr, idx);
// Modify the original string by converting to uppercase
- In
Socket.c:1541:
Str spec = StrInit(a);
StrAppendFmt(&spec, "{}", (Zstr) "1.2.3.4:4660");
SocketAddr addr;- In
Http.c:45:
HttpResponse response = HttpResponseInit(alloc_base);
Str body = StrInit(alloc_base);
StrAppendFmt(&body, "<h1>hi</h1>");
HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &body);
StrDeinit(&body);- In
Http.c:158:
Str raw = StrInit(alloc_base);
StrAppendFmt(&raw, "GET / HTTP/1.1\r\n");
// 101 headers -- one past the cap of 100.
for (u64 i = 0; i < 101; i++) {- In
Http.c:161:
// 101 headers -- one past the cap of 100.
for (u64 i = 0; i < 101; i++) {
StrAppendFmt(&raw, "X-H{}: v\r\n", i);
}
StrAppendFmt(&raw, "\r\n");- In
Http.c:163:
StrAppendFmt(&raw, "X-H{}: v\r\n", i);
}
StrAppendFmt(&raw, "\r\n");
HttpRequest req = HttpRequestInit(alloc_base);- In
Http.c:186:
Str raw = StrInit(alloc_base);
StrAppendFmt(&raw, "GET / HTTP/1.1\r\n");
for (u64 i = 0; i < 100; i++) {
StrAppendFmt(&raw, "X-H{}: v\r\n", i);- In
Http.c:188:
StrAppendFmt(&raw, "GET / HTTP/1.1\r\n");
for (u64 i = 0; i < 100; i++) {
StrAppendFmt(&raw, "X-H{}: v\r\n", i);
}
StrAppendFmt(&raw, "\r\n");- In
Http.c:190:
StrAppendFmt(&raw, "X-H{}: v\r\n", i);
}
StrAppendFmt(&raw, "\r\n");
HttpRequest req = HttpRequestInit(alloc_base);- In
Http.c:300:
HttpHeader hh = HttpHeaderInit(adbg);
StrAppendFmt(&hh.key, "X-A-Reasonably-Long-Header-Key-Name");
StrAppendFmt(&hh.value, "a-reasonably-long-header-value-string");- In
Http.c:301:
HttpHeader hh = HttpHeaderInit(adbg);
StrAppendFmt(&hh.key, "X-A-Reasonably-Long-Header-Key-Name");
StrAppendFmt(&hh.value, "a-reasonably-long-header-value-string");
bool ok = VecPushBackR(&headers, hh);- In
Http.c:351:
Str first = StrInit(adbg);
StrAppendFmt(&first, "<h1>first-body-long-enough-to-heap-allocate</h1>");
HttpResponse response = HttpResponseInit(adbg);- In
Http.c:357:
Str second = StrInit(adbg);
StrAppendFmt(&second, "<h1>second-body-also-long-enough-to-heap</h1>");
// Second call must free the first body before installing the second.
HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &second);- In
Http.c:381:
// Pre-fill body with a heap-backed string.
Str first = StrInit(adbg);
StrAppendFmt(&first, "<h1>old-body-long-enough-to-force-heap-here</h1>");
HttpResponse response = HttpResponseInit(adbg);
HttpRespondWithHtml(&response, HTTP_RESPONSE_CODE_OK, &first); Str source_key = StrInit(&alloc);
u64 source_id = VecLen(&response.data) > 0 ? VecAt(&response.data, 0).source_function_id : 0;
StrAppendFmt(&source_key, "{}", source_id);
JW_OBJ_KV(json, StrBegin(&source_key), { AnnSymbol *s = &VecAt(&response.data, 0);
Str target_key = StrInit(&alloc);
StrAppendFmt(&target_key, "{}", s->target_function_id);
JW_OBJ_KV(json, StrBegin(&target_key), { VecForeach(&symbols, symbol) {
Str source_key = StrInit(&alloc);
StrAppendFmt(&source_key, "{}", symbol.source_function_id);
JW_OBJ_KV(json, StrBegin(&source_key), { JW_OBJ_KV(json, StrBegin(&source_key), {
Str target_key = StrInit(&alloc);
StrAppendFmt(&target_key, "{}", symbol.target_function_id);
JW_OBJ_KV(json, StrBegin(&target_key), {
Last updated on