[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
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>
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!
|
38 tasks
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.Implementation notes
l_str_printfcallsl_vsnprintf((char*)0, 0, fmt, ap)first (safe: EMIT macro guards all writes), allocatesneed+1bytes, then formats.l_str_printfis guarded by#ifdef L_WITHSNPRINTF.l_str_to_int/l_str_to_doubleuse 70/128-byte stack buffers.Test Status
New tests in
tests/test_utils.c:test_str_to_numandtest_str_printf_arena.