aboutsummaryrefslogtreecommitdiff
path: root/core/strings
diff options
context:
space:
mode:
authorJon Lipstate <Jon@Lipstate.com>2023-03-28 10:24:41 -0700
committerJon Lipstate <Jon@Lipstate.com>2023-03-28 10:24:41 -0700
commit203ae32b797b758cf98c49db18752cee02c1c7e7 (patch)
treef209f4f78963af85c40bcfad139d9750b5452c94 /core/strings
parent937e5de1d8676c8ae25a8e4b52d2272277aad396 (diff)
pr pickups
Diffstat (limited to 'core/strings')
-rw-r--r--core/strings/builder.odin30
-rw-r--r--core/strings/strings.odin10
2 files changed, 28 insertions, 12 deletions
diff --git a/core/strings/builder.odin b/core/strings/builder.odin
index eb78551bd..15bda1b2d 100644
--- a/core/strings/builder.odin
+++ b/core/strings/builder.odin
@@ -148,8 +148,7 @@ _builder_stream_vtable_obj := io.Stream_VTable{
},
impl_destroy = proc(s: io.Stream) -> io.Error {
b := (^Builder)(s.stream_data)
- delete(b.buf)
- b.buf=nil
+ builder_destroy(b)
return .None
},
}
@@ -179,7 +178,7 @@ to_writer :: proc(b: ^Builder) -> io.Writer {
return io.to_writer(to_stream(b))
}
/*
-Deletes and clears the Builder byte buffer content
+Deletes the Builder byte buffer content
**Inputs**
- b: A pointer to the Builder
@@ -501,12 +500,12 @@ Example:
strings.write_quoted_string(&builder, "a") // 3
strings.write_quoted_string(&builder, "bc", '\'') // 4
strings.write_quoted_string(&builder, "xyz") // 5
- fmt.println(strings.to_string(builder)) // -> "a"'bc'xyz"
+ fmt.println(strings.to_string(builder))
}
Output:
- "a"'bc'xyz"
+ "a"'bc'"xyz"
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -517,12 +516,29 @@ write_quoted_string :: proc(b: ^Builder, str: string, quote: byte = '"') -> (n:
return
}
/*
-Appends an encoded rune to the Builder and returns the number of bytes written
+Appends a rune to the Builder and returns the number of bytes written
**Inputs**
- b: A pointer to the Builder
- r: The rune to be appended
-- write_quote: Optional boolean flag to write the quote character (default is true)
+- write_quote: Optional boolean flag to wrap in single-quotes (') (default is true)
+
+Example:
+
+ import "core:fmt"
+ import "core:strings"
+
+ write_encoded_rune_example :: proc() {
+ builder := strings.builder_make()
+ strings.write_encoded_rune(&builder, 'a', false) // 1
+ strings.write_encoded_rune(&builder, '\"', true) // 3
+ strings.write_encoded_rune(&builder, 'x', false) // 1
+ fmt.println(strings.to_string(builder))
+ }
+
+Output:
+
+ a'"'x
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
diff --git a/core/strings/strings.odin b/core/strings/strings.odin
index 36b244d27..118faadab 100644
--- a/core/strings/strings.odin
+++ b/core/strings/strings.odin
@@ -2078,7 +2078,7 @@ is_null :: proc(r: rune) -> bool {
return r == 0x0000
}
/*
-Finds the index of the first rune in the string s for which the procedure p returns the same value as truth
+Find the index of the first rune r in string s for which procedure p returns the same as truth, or -1 if no such rune appears.
**Inputs**
- s: The input string
@@ -2777,7 +2777,7 @@ Centers the input string within a field of specified length by adding pad string
**Inputs**
- str: The input string
-- length: The desired length of the centered string
+- length: The desired length of the centered string, in runes
- pad: The string used for padding on both sides
- allocator: (default is context.allocator)
@@ -2876,8 +2876,8 @@ Writes a given pad string a specified number of times to an io.Writer
**Inputs**
- w: The io.Writer to write the pad string to
- pad: The pad string to be written
-- pad_len: The length of the pad string
-- remains: The number of times to write the pad string
+- pad_len: The length of the pad string, in runes
+- remains: The number of times to write the pad string, in runes
*/
@private
write_pad_string :: proc(w: io.Writer, pad: string, pad_len, remains: int) {
@@ -2956,7 +2956,7 @@ fields :: proc(s: string, allocator := context.allocator) -> []string #no_bounds
return a
}
/*
-Splits a string into a slice of substrings at each run of unicode code points `ch` satisfying the predicate f(ch)
+Splits a string into a slice of substrings at each run of unicode code points `r` satisfying the predicate f(r)
*Allocates Using Provided Allocator*