diff options
| author | Karl Zylinski <karl@zylinski.se> | 2024-06-25 22:32:20 +0200 |
|---|---|---|
| committer | Karl Zylinski <karl@zylinski.se> | 2024-06-25 22:32:20 +0200 |
| commit | 4e2d12c5400bbc789a9573dd4806ea308b40bb5c (patch) | |
| tree | a68968ffd7a1bf49c0938c932e81552689411384 | |
| parent | 5d1d98cef32a42e9bc2020efd1328954a3f37ca7 (diff) | |
Added fmt.ctprint
| -rw-r--r-- | core/fmt/fmt.odin | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index b1c95866f..424e4e6e8 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -368,6 +368,25 @@ caprintf :: proc(format: string, args: ..any, newline := false) -> cstring { caprintfln :: proc(format: string, args: ..any) -> cstring { return caprintf(format, ..args, newline=true) } +// Creates a formatted C string +// +// *Allocates Using Context's Temporary Allocator* +// +// Inputs: +// - args: A variadic list of arguments to be formatted. +// - sep: An optional separator string (default is a single space). +// +// Returns: A formatted C string. +// +@(require_results) +ctprint :: proc(args: ..any, sep := " ") -> cstring { + str: strings.Builder + strings.builder_init(&str, context.temp_allocator) + sbprint(&str, ..args, sep=sep) + strings.write_byte(&str, 0) + s := strings.to_string(str) + return cstring(raw_data(s)) +} // Creates a formatted C string // // *Allocates Using Context's Temporary Allocator* |