Skip to content

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

Draft
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/feat-str-printf-to-num-2026-04-20-e43284a-8ec83fa9604cf580
Draft

[Repo Assist] feat: add l_str_printf, l_str_to_int, l_str_to_double to L_Str API#140
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/feat-str-printf-to-num-2026-04-20-e43284a-8ec83fa9604cf580

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. These are common operations when building string pipelines with L_Arena.

Implementation notes

  • l_str_printf calls l_vsnprintf((char*)0, 0, fmt, ap) first (safe: EMIT macro guards all writes behind pos+1 < n, always false when n=0), allocates need+1 bytes, then formats. The extra byte is not exposed in l_str.len.
  • l_str_printf is guarded by #ifdef L_WITHSNPRINTF.
  • l_str_to_int / l_str_to_double use 70/128-byte stack buffers — covers all representable numbers.

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>
README.md is auto-generated by gen-docs.ps1; docs were restructured in #152.
Drop the auto-generated function-reference edit to unblock merging this PR.
@github-actions
Copy link
Copy Markdown
Contributor Author

Commit pushed: b261ab8

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

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