|
@@ -7,10 +7,11 @@ import "core:io"
|
|
|
/*
|
|
|
Type definition for a procedure that flushes a Builder
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
|
|
|
-**Returns** A boolean indicating whether the Builder should be reset
|
|
|
+Returns:
|
|
|
+A boolean indicating whether the Builder should be reset
|
|
|
*/
|
|
|
Builder_Flush_Proc :: #type proc(b: ^Builder) -> (do_reset: bool)
|
|
|
/*
|
|
@@ -26,10 +27,11 @@ Produces a Builder with a default length of 0 and cap of 16
|
|
|
|
|
|
*Allocates Using Provided Allocator*
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- allocator: (default is context.allocator)
|
|
|
|
|
|
-**Returns** A new Builder
|
|
|
+Returns:
|
|
|
+A new Builder
|
|
|
*/
|
|
|
builder_make_none :: proc(allocator := context.allocator) -> Builder {
|
|
|
return Builder{buf=make([dynamic]byte, allocator)}
|
|
@@ -39,11 +41,12 @@ Produces a Builder with a specified length and cap of max(16,len) byte buffer
|
|
|
|
|
|
*Allocates Using Provided Allocator*
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- len: The desired length of the Builder's buffer
|
|
|
- allocator: (default is context.allocator)
|
|
|
|
|
|
-**Returns** A new Builder
|
|
|
+Returns:
|
|
|
+A new Builder
|
|
|
*/
|
|
|
builder_make_len :: proc(len: int, allocator := context.allocator) -> Builder {
|
|
|
return Builder{buf=make([dynamic]byte, len, allocator)}
|
|
@@ -53,12 +56,13 @@ Produces a Builder with a specified length and cap
|
|
|
|
|
|
*Allocates Using Provided Allocator*
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- len: The desired length of the Builder's buffer
|
|
|
- cap: The desired capacity of the Builder's buffer, cap is max(cap, len)
|
|
|
- allocator: (default is context.allocator)
|
|
|
|
|
|
-**Returns** A new Builder
|
|
|
+Returns:
|
|
|
+A new Builder
|
|
|
*/
|
|
|
builder_make_len_cap :: proc(len, cap: int, allocator := context.allocator) -> Builder {
|
|
|
return Builder{buf=make([dynamic]byte, len, cap, allocator)}
|
|
@@ -75,11 +79,12 @@ It replaces the existing `buf`
|
|
|
|
|
|
*Allocates Using Provided Allocator*
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- allocator: (default is context.allocator)
|
|
|
|
|
|
-**Returns** initialized ^Builder
|
|
|
+Returns:
|
|
|
+initialized ^Builder
|
|
|
*/
|
|
|
builder_init_none :: proc(b: ^Builder, allocator := context.allocator) -> ^Builder {
|
|
|
b.buf = make([dynamic]byte, allocator)
|
|
@@ -91,12 +96,13 @@ It replaces the existing `buf`
|
|
|
|
|
|
*Allocates Using Provided Allocator*
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- len: The desired length of the Builder's buffer
|
|
|
- allocator: (default is context.allocator)
|
|
|
|
|
|
-**Returns** Initialized ^Builder
|
|
|
+Returns:
|
|
|
+Initialized ^Builder
|
|
|
*/
|
|
|
builder_init_len :: proc(b: ^Builder, len: int, allocator := context.allocator) -> ^Builder {
|
|
|
b.buf = make([dynamic]byte, len, allocator)
|
|
@@ -106,13 +112,14 @@ builder_init_len :: proc(b: ^Builder, len: int, allocator := context.allocator)
|
|
|
Initializes a Builder with a specified length and cap
|
|
|
It replaces the existing `buf`
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- len: The desired length of the Builder's buffer
|
|
|
- cap: The desired capacity of the Builder's buffer, actual max(len,cap)
|
|
|
- allocator: (default is context.allocator)
|
|
|
|
|
|
-**Returns** A pointer to the initialized Builder
|
|
|
+Returns:
|
|
|
+A pointer to the initialized Builder
|
|
|
*/
|
|
|
builder_init_len_cap :: proc(b: ^Builder, len, cap: int, allocator := context.allocator) -> ^Builder {
|
|
|
b.buf = make([dynamic]byte, len, cap, allocator)
|
|
@@ -158,10 +165,11 @@ _builder_stream_vtable := &_builder_stream_vtable_obj
|
|
|
/*
|
|
|
Returns an io.Stream from a Builder
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
|
|
|
-**Returns** An io.Stream
|
|
|
+Returns:
|
|
|
+An io.Stream
|
|
|
*/
|
|
|
to_stream :: proc(b: ^Builder) -> io.Stream {
|
|
|
return io.Stream{stream_vtable=_builder_stream_vtable, stream_data=b}
|
|
@@ -169,10 +177,11 @@ to_stream :: proc(b: ^Builder) -> io.Stream {
|
|
|
/*
|
|
|
Returns an io.Writer from a Builder
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
|
|
|
-**Returns** An io.Writer
|
|
|
+Returns:
|
|
|
+An io.Writer
|
|
|
*/
|
|
|
to_writer :: proc(b: ^Builder) -> io.Writer {
|
|
|
return io.to_writer(to_stream(b))
|
|
@@ -180,7 +189,7 @@ to_writer :: proc(b: ^Builder) -> io.Writer {
|
|
|
/*
|
|
|
Deletes the Builder byte buffer content
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
*/
|
|
|
builder_destroy :: proc(b: ^Builder) {
|
|
@@ -190,7 +199,7 @@ builder_destroy :: proc(b: ^Builder) {
|
|
|
/*
|
|
|
Reserves the Builder byte buffer to a specific capacity, when it's higher than before
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- cap: The desired capacity for the Builder's buffer
|
|
|
*/
|
|
@@ -200,7 +209,7 @@ builder_grow :: proc(b: ^Builder, cap: int) {
|
|
|
/*
|
|
|
Clears the Builder byte buffer content (sets len to zero)
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
*/
|
|
|
builder_reset :: proc(b: ^Builder) {
|
|
@@ -211,18 +220,23 @@ Creates a Builder from a slice of bytes with the same slice length as its capaci
|
|
|
|
|
|
*Uses Nil Allocator - Does NOT allocate*
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- backing: A slice of bytes to be used as the backing buffer
|
|
|
|
|
|
+Returns:
|
|
|
+A new Builder
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
- strings_builder_from_bytes_example :: proc() {
|
|
|
+ builder_from_bytes_example :: proc() {
|
|
|
bytes: [8]byte // <-- gets filled
|
|
|
builder := strings.builder_from_bytes(bytes[:])
|
|
|
- fmt.println(strings.write_byte(&builder, 'a')) // -> "a"
|
|
|
- fmt.println(strings.write_byte(&builder, 'b')) // -> "ab"
|
|
|
+ strings.write_byte(&builder, 'a')
|
|
|
+ fmt.println(strings.to_string(builder)) // -> "a"
|
|
|
+ strings.write_byte(&builder, 'b')
|
|
|
+ fmt.println(strings.to_string(builder)) // -> "ab"
|
|
|
}
|
|
|
|
|
|
Output:
|
|
@@ -230,7 +244,6 @@ Output:
|
|
|
a
|
|
|
ab
|
|
|
|
|
|
-**Returns** A new Builder
|
|
|
*/
|
|
|
builder_from_bytes :: proc(backing: []byte) -> Builder {
|
|
|
s := transmute(runtime.Raw_Slice)backing
|
|
@@ -249,10 +262,11 @@ builder_from_slice :: builder_from_bytes
|
|
|
/*
|
|
|
Casts the Builder byte buffer to a string and returns it
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A Builder
|
|
|
|
|
|
-**Returns** The contents of the Builder's buffer, as a string
|
|
|
+Returns:
|
|
|
+The contents of the Builder's buffer, as a string
|
|
|
*/
|
|
|
to_string :: proc(b: Builder) -> string {
|
|
|
return string(b.buf[:])
|
|
@@ -260,10 +274,11 @@ to_string :: proc(b: Builder) -> string {
|
|
|
/*
|
|
|
Returns the length of the Builder's buffer, in bytes
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A Builder
|
|
|
|
|
|
-**Returns** The length of the Builder's buffer
|
|
|
+Returns:
|
|
|
+The length of the Builder's buffer
|
|
|
*/
|
|
|
builder_len :: proc(b: Builder) -> int {
|
|
|
return len(b.buf)
|
|
@@ -271,10 +286,11 @@ builder_len :: proc(b: Builder) -> int {
|
|
|
/*
|
|
|
Returns the capacity of the Builder's buffer, in bytes
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A Builder
|
|
|
|
|
|
-**Returns** The capacity of the Builder's buffer
|
|
|
+Returns:
|
|
|
+The capacity of the Builder's buffer
|
|
|
*/
|
|
|
builder_cap :: proc(b: Builder) -> int {
|
|
|
return cap(b.buf)
|
|
@@ -282,10 +298,11 @@ builder_cap :: proc(b: Builder) -> int {
|
|
|
/*
|
|
|
The free space left in the Builder's buffer, in bytes
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A Builder
|
|
|
|
|
|
-**Returns** The available space left in the Builder's buffer
|
|
|
+Returns:
|
|
|
+The available space left in the Builder's buffer
|
|
|
*/
|
|
|
builder_space :: proc(b: Builder) -> int {
|
|
|
return cap(b.buf) - len(b.buf)
|
|
@@ -293,16 +310,21 @@ builder_space :: proc(b: Builder) -> int {
|
|
|
/*
|
|
|
Appends a byte to the Builder and returns the number of bytes appended
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- x: The byte to be appended
|
|
|
|
|
|
+Returns:
|
|
|
+The number of bytes appended
|
|
|
+
|
|
|
+NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
|
|
|
- strings_write_byte_example :: proc() {
|
|
|
+ write_byte_example :: proc() {
|
|
|
builder := strings.builder_make()
|
|
|
strings.write_byte(&builder, 'a') // 1
|
|
|
strings.write_byte(&builder, 'b') // 1
|
|
@@ -313,9 +335,6 @@ Output:
|
|
|
|
|
|
ab
|
|
|
|
|
|
-NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
-
|
|
|
-**Returns** The number of bytes appended
|
|
|
*/
|
|
|
write_byte :: proc(b: ^Builder, x: byte) -> (n: int) {
|
|
|
n0 := len(b.buf)
|
|
@@ -326,7 +345,7 @@ write_byte :: proc(b: ^Builder, x: byte) -> (n: int) {
|
|
|
/*
|
|
|
Appends a slice of bytes to the Builder and returns the number of bytes appended
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- x: The slice of bytes to be appended
|
|
|
|
|
@@ -335,7 +354,7 @@ Example:
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
|
|
|
- strings_write_bytes_example :: proc() {
|
|
|
+ write_bytes_example :: proc() {
|
|
|
builder := strings.builder_make()
|
|
|
bytes := [?]byte { 'a', 'b', 'c' }
|
|
|
strings.write_bytes(&builder, bytes[:]) // 3
|
|
@@ -344,7 +363,8 @@ Example:
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of bytes appended
|
|
|
+Returns:
|
|
|
+The number of bytes appended
|
|
|
*/
|
|
|
write_bytes :: proc(b: ^Builder, x: []byte) -> (n: int) {
|
|
|
n0 := len(b.buf)
|
|
@@ -355,16 +375,21 @@ write_bytes :: proc(b: ^Builder, x: []byte) -> (n: int) {
|
|
|
/*
|
|
|
Appends a single rune to the Builder and returns the number of bytes written and an `io.Error`
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- r: The rune to be appended
|
|
|
|
|
|
+Returns:
|
|
|
+The number of bytes written and an io.Error (if any)
|
|
|
+
|
|
|
+NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
|
|
|
- strings_write_rune_example :: proc() {
|
|
|
+ write_rune_example :: proc() {
|
|
|
builder := strings.builder_make()
|
|
|
strings.write_rune(&builder, 'ä') // 2 None
|
|
|
strings.write_rune(&builder, 'b') // 1 None
|
|
@@ -375,9 +400,6 @@ Output:
|
|
|
|
|
|
äb
|
|
|
|
|
|
-NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
-
|
|
|
-**Returns** The number of bytes written and an io.Error (if any)
|
|
|
*/
|
|
|
write_rune :: proc(b: ^Builder, r: rune) -> (int, io.Error) {
|
|
|
return io.write_rune(to_writer(b), r)
|
|
@@ -385,16 +407,21 @@ write_rune :: proc(b: ^Builder, r: rune) -> (int, io.Error) {
|
|
|
/*
|
|
|
Appends a quoted rune to the Builder and returns the number of bytes written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- r: The rune to be appended
|
|
|
|
|
|
+Returns:
|
|
|
+The number of bytes written
|
|
|
+
|
|
|
+NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
|
|
|
- strings_write_quoted_rune_example :: proc() {
|
|
|
+ write_quoted_rune_example :: proc() {
|
|
|
builder := strings.builder_make()
|
|
|
strings.write_string(&builder, "abc") // 3
|
|
|
strings.write_quoted_rune(&builder, 'ä') // 4
|
|
@@ -406,9 +433,6 @@ Output:
|
|
|
|
|
|
abc'ä'abc
|
|
|
|
|
|
-NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
-
|
|
|
-**Returns** The number of bytes written
|
|
|
*/
|
|
|
write_quoted_rune :: proc(b: ^Builder, r: rune) -> (n: int) {
|
|
|
return io.write_quoted_rune(to_writer(b), r)
|
|
@@ -416,16 +440,21 @@ write_quoted_rune :: proc(b: ^Builder, r: rune) -> (n: int) {
|
|
|
/*
|
|
|
Appends a string to the Builder and returns the number of bytes written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- s: The string to be appended
|
|
|
|
|
|
+Returns:
|
|
|
+The number of bytes written
|
|
|
+
|
|
|
+NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
|
|
|
- strings_write_string_example :: proc() {
|
|
|
+ write_string_example :: proc() {
|
|
|
builder := strings.builder_make()
|
|
|
strings.write_string(&builder, "a") // 1
|
|
|
strings.write_string(&builder, "bc") // 2
|
|
@@ -436,9 +465,6 @@ Output:
|
|
|
|
|
|
abc
|
|
|
|
|
|
-NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
-
|
|
|
-**Returns** The number of bytes written
|
|
|
*/
|
|
|
write_string :: proc(b: ^Builder, s: string) -> (n: int) {
|
|
|
n0 := len(b.buf)
|
|
@@ -449,10 +475,11 @@ write_string :: proc(b: ^Builder, s: string) -> (n: int) {
|
|
|
/*
|
|
|
Pops and returns the last byte in the Builder or 0 when the Builder is empty
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
|
|
|
-**Returns** The last byte in the Builder or 0 if empty
|
|
|
+Returns:
|
|
|
+The last byte in the Builder or 0 if empty
|
|
|
*/
|
|
|
pop_byte :: proc(b: ^Builder) -> (r: byte) {
|
|
|
if len(b.buf) == 0 {
|
|
@@ -467,10 +494,11 @@ pop_byte :: proc(b: ^Builder) -> (r: byte) {
|
|
|
/*
|
|
|
Pops the last rune in the Builder and returns the popped rune and its rune width or (0, 0) if empty
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
|
|
|
-**Returns** The popped rune and its rune width or (0, 0) if empty
|
|
|
+Returns:
|
|
|
+The popped rune and its rune width or (0, 0) if empty
|
|
|
*/
|
|
|
pop_rune :: proc(b: ^Builder) -> (r: rune, width: int) {
|
|
|
if len(b.buf) == 0 {
|
|
@@ -485,17 +513,22 @@ pop_rune :: proc(b: ^Builder) -> (r: rune, width: int) {
|
|
|
@(private)
|
|
|
DIGITS_LOWER := "0123456789abcdefx"
|
|
|
/*
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- str: The string to be quoted and appended
|
|
|
- quote: The optional quote character (default is double quotes)
|
|
|
|
|
|
+Returns:
|
|
|
+The number of bytes written
|
|
|
+
|
|
|
+NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
|
|
|
- strings_write_quoted_string_example :: proc() {
|
|
|
+ write_quoted_string_example :: proc() {
|
|
|
builder := strings.builder_make()
|
|
|
strings.write_quoted_string(&builder, "a") // 3
|
|
|
strings.write_quoted_string(&builder, "bc", '\'') // 4
|
|
@@ -507,9 +540,6 @@ Output:
|
|
|
|
|
|
"a"'bc'"xyz"
|
|
|
|
|
|
-NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
-
|
|
|
-**Returns** The number of bytes written
|
|
|
*/
|
|
|
write_quoted_string :: proc(b: ^Builder, str: string, quote: byte = '"') -> (n: int) {
|
|
|
n, _ = io.write_quoted_string(to_writer(b), str, quote)
|
|
@@ -518,11 +548,16 @@ write_quoted_string :: proc(b: ^Builder, str: string, quote: byte = '"') -> (n:
|
|
|
/*
|
|
|
Appends a rune to the Builder and returns the number of bytes written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- r: The rune to be appended
|
|
|
- write_quote: Optional boolean flag to wrap in single-quotes (') (default is true)
|
|
|
|
|
|
+Returns:
|
|
|
+The number of bytes written
|
|
|
+
|
|
|
+NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
@@ -540,9 +575,6 @@ Output:
|
|
|
|
|
|
a'"'x
|
|
|
|
|
|
-NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
-
|
|
|
-**Returns** The number of bytes written
|
|
|
*/
|
|
|
write_encoded_rune :: proc(b: ^Builder, r: rune, write_quote := true) -> (n: int) {
|
|
|
n, _ = io.write_encoded_rune(to_writer(b), r, write_quote)
|
|
@@ -552,7 +584,7 @@ write_encoded_rune :: proc(b: ^Builder, r: rune, write_quote := true) -> (n: int
|
|
|
/*
|
|
|
Appends an escaped rune to the Builder and returns the number of bytes written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- r: The rune to be appended
|
|
|
- quote: The quote character
|
|
@@ -565,7 +597,8 @@ Appends an escaped rune to the Builder and returns the number of bytes written
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of bytes written
|
|
|
+Returns:
|
|
|
+The number of bytes written
|
|
|
*/
|
|
|
write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte, html_safe := false) -> (n: int) {
|
|
|
n, _ = io.write_escaped_rune(to_writer(b), r, quote, html_safe)
|
|
@@ -574,7 +607,7 @@ write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte, html_safe := false
|
|
|
/*
|
|
|
Writes a f64 value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- f: The f64 value to be appended
|
|
|
- fmt: The format byte
|
|
@@ -584,7 +617,8 @@ Writes a f64 value to the Builder and returns the number of characters written
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of characters written
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
*/
|
|
|
write_float :: proc(b: ^Builder, f: f64, fmt: byte, prec, bit_size: int, always_signed := false) -> (n: int) {
|
|
|
buf: [384]byte
|
|
@@ -599,7 +633,7 @@ write_float :: proc(b: ^Builder, f: f64, fmt: byte, prec, bit_size: int, always_
|
|
|
/*
|
|
|
Writes a f16 value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- f: The f16 value to be appended
|
|
|
- fmt: The format byte
|
|
@@ -607,7 +641,8 @@ Writes a f16 value to the Builder and returns the number of characters written
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of characters written
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
*/
|
|
|
write_f16 :: proc(b: ^Builder, f: f16, fmt: byte, always_signed := false) -> (n: int) {
|
|
|
buf: [384]byte
|
|
@@ -620,18 +655,23 @@ write_f16 :: proc(b: ^Builder, f: f16, fmt: byte, always_signed := false) -> (n:
|
|
|
/*
|
|
|
Writes a f32 value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- f: The f32 value to be appended
|
|
|
- fmt: The format byte
|
|
|
- always_signed: Optional boolean flag to always include the sign
|
|
|
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
+
|
|
|
+NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
+
|
|
|
Example:
|
|
|
|
|
|
import "core:fmt"
|
|
|
import "core:strings"
|
|
|
|
|
|
- strings_write_f32_example :: proc() {
|
|
|
+ write_f32_example :: proc() {
|
|
|
builder := strings.builder_make()
|
|
|
strings.write_f32(&builder, 3.14159, 'f') // 6
|
|
|
strings.write_string(&builder, " - ") // 3
|
|
@@ -643,9 +683,6 @@ Output:
|
|
|
|
|
|
3.14159012 - -1.23000003e-01
|
|
|
|
|
|
-NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
-
|
|
|
-**Returns** The number of characters written
|
|
|
*/
|
|
|
write_f32 :: proc(b: ^Builder, f: f32, fmt: byte, always_signed := false) -> (n: int) {
|
|
|
buf: [384]byte
|
|
@@ -658,7 +695,7 @@ write_f32 :: proc(b: ^Builder, f: f32, fmt: byte, always_signed := false) -> (n:
|
|
|
/*
|
|
|
Writes a f32 value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- f: The f32 value to be appended
|
|
|
- fmt: The format byte
|
|
@@ -666,7 +703,8 @@ Writes a f32 value to the Builder and returns the number of characters written
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of characters written
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
*/
|
|
|
write_f64 :: proc(b: ^Builder, f: f64, fmt: byte, always_signed := false) -> (n: int) {
|
|
|
buf: [384]byte
|
|
@@ -679,14 +717,15 @@ write_f64 :: proc(b: ^Builder, f: f64, fmt: byte, always_signed := false) -> (n:
|
|
|
/*
|
|
|
Writes a u64 value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- i: The u64 value to be appended
|
|
|
- base: The optional base for the numeric representation
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of characters written
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
*/
|
|
|
write_u64 :: proc(b: ^Builder, i: u64, base: int = 10) -> (n: int) {
|
|
|
buf: [32]byte
|
|
@@ -696,14 +735,15 @@ write_u64 :: proc(b: ^Builder, i: u64, base: int = 10) -> (n: int) {
|
|
|
/*
|
|
|
Writes a i64 value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- i: The i64 value to be appended
|
|
|
- base: The optional base for the numeric representation
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of characters written
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
*/
|
|
|
write_i64 :: proc(b: ^Builder, i: i64, base: int = 10) -> (n: int) {
|
|
|
buf: [32]byte
|
|
@@ -713,14 +753,15 @@ write_i64 :: proc(b: ^Builder, i: i64, base: int = 10) -> (n: int) {
|
|
|
/*
|
|
|
Writes a uint value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- i: The uint value to be appended
|
|
|
- base: The optional base for the numeric representation
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of characters written
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
*/
|
|
|
write_uint :: proc(b: ^Builder, i: uint, base: int = 10) -> (n: int) {
|
|
|
return write_u64(b, u64(i), base)
|
|
@@ -728,14 +769,15 @@ write_uint :: proc(b: ^Builder, i: uint, base: int = 10) -> (n: int) {
|
|
|
/*
|
|
|
Writes a int value to the Builder and returns the number of characters written
|
|
|
|
|
|
-**Inputs**
|
|
|
+Inputs:
|
|
|
- b: A pointer to the Builder
|
|
|
- i: The int value to be appended
|
|
|
- base: The optional base for the numeric representation
|
|
|
|
|
|
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
|
|
|
|
|
|
-**Returns** The number of characters written
|
|
|
+Returns:
|
|
|
+The number of characters written
|
|
|
*/
|
|
|
write_int :: proc(b: ^Builder, i: int, base: int = 10) -> (n: int) {
|
|
|
return write_i64(b, i64(i), base)
|