[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
Draft
Conversation
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>
This was referenced Apr 20, 2026
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.
Contributor
Author
|
Commit pushed:
|
26 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Adds three useful functions to the
L_Strarena-based string API inl_os.h:l_str_printf(arena, fmt, ...)L_Str. Uses two-passl_vsnprintf(length probe then format).l_str_to_int(s, base)L_Strslice vial_strtoll.l_str_to_double(s)doublefrom anL_Strslice vial_strtod.Motivation
The
L_StrAPI covered comparison, search, split/join, upper/lower, replace, dup/cat — but had no way to build a formattedL_Strwithout manual size estimation, or parse numeric values out of a non-NUL-terminated slice. These are common operations when building string pipelines withL_Arena.Implementation notes
l_str_printfcallsl_vsnprintf((char*)0, 0, fmt, ap)first (safe: EMIT macro guards all writes behindpos+1 < n, always false when n=0), allocatesneed+1bytes, then formats. The extra byte is not exposed inl_str.len.l_str_printfis guarded by#ifdef L_WITHSNPRINTF.l_str_to_int/l_str_to_doubleuse 70/128-byte stack buffers — covers all representable numbers.Test Status
New tests in
tests/test_utils.c:test_str_to_numandtest_str_printf_arena.