Skip to content

[Repo Assist] feat: add l_str_printf, l_str_to_int, l_str_to_double to L_Str API#141

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/feat-str-printf-to-num-2026-04-20-e43284a-e3d3110b124a4a63
Draft

[Repo Assist] feat: add l_str_printf, l_str_to_int, l_str_to_double to L_Str API#141
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/feat-str-printf-to-num-2026-04-20-e43284a-e3d3110b124a4a63

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Adds three useful functions to the L_Str arena-based string API in l_os.h:

Function Description
l_str_printf(arena, fmt, ...) Formats args into an arena-allocated L_Str. Uses two-pass l_vsnprintf (length probe then format).
l_str_to_int(s, base) Parses a signed integer from an L_Str slice via l_strtoll.
l_str_to_double(s) Parses a double from an L_Str slice via l_strtod.

Motivation

The L_Str API covered comparison, search, split/join, upper/lower, replace, dup/cat — but had no way to build a formatted L_Str without manual size estimation, or parse numeric values out of a non-NUL-terminated slice.

Implementation notes

  • l_str_printf calls l_vsnprintf((char*)0, 0, fmt, ap) first (safe: EMIT macro guards all writes), allocates need+1 bytes, then formats.
  • l_str_printf is guarded by #ifdef L_WITHSNPRINTF.
  • l_str_to_int / l_str_to_double use 70/128-byte stack buffers.

Test Status

New tests in tests/test_utils.c: test_str_to_num and test_str_printf_arena.

Linux (gcc)   Build PASS  Test PASS (1538 assertions)
Linux (clang) Build PASS  Test PASS (1536 assertions)

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

l_str_printf(arena, fmt, ...) formats into arena-allocated L_Str using
l_vsnprintf in two passes: length probe then actual format. Result is
exact-length (not NUL-terminated internally).

l_str_to_int(s, base) and l_str_to_double(s) parse numbers directly
from L_Str slices via l_strtoll/l_strtod with a small stack-local copy
to obtain NUL-termination; handles leading whitespace and sign.

Tests added in tests/test_utils.c (test_str_to_num,
test_str_printf_arena). CI: Linux gcc+clang PASS.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor Author

🤖 This is an automated response from Repo Assist.

This PR is an exact duplicate of #140 — both were created within 5 seconds of each other during the same run due to a race condition in the previous Repo Assist run. The branches contain identical changes (same files modified, same content).

Please close this PR and keep #140 instead. Apologies for the noise!

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants