aboutsummaryrefslogtreecommitdiff
path: root/core/strings
diff options
context:
space:
mode:
authorJon Lipstate <Jon@Lipstate.com>2023-04-26 18:00:14 -0700
committerJon Lipstate <Jon@Lipstate.com>2023-04-26 18:00:14 -0700
commit67fa5df89c70f7da958443b4ec4cbdc3b515cffa (patch)
tree85a56aa19bee605413ff84c234677665d8293c78 /core/strings
parent023cc9ca541d7462a323147cbc056fe4303f299f (diff)
fix typo, add builder sample
Diffstat (limited to 'core/strings')
-rw-r--r--core/strings/builder.odin28
-rw-r--r--core/strings/strings.odin2
2 files changed, 28 insertions, 2 deletions
diff --git a/core/strings/builder.odin b/core/strings/builder.odin
index 90cc4ebdc..6e809c4f6 100644
--- a/core/strings/builder.odin
+++ b/core/strings/builder.odin
@@ -71,7 +71,33 @@ Returns:
builder_make_len_cap :: proc(len, cap: int, allocator := context.allocator) -> (res: Builder, err: mem.Allocator_Error) #optional_allocator_error {
return Builder{buf=make([dynamic]byte, len, cap, allocator) or_return }, nil
}
-// overload simple `builder_make_*` with or without len / cap parameters
+/*
+Produces a String Builder
+
+*Allocates Using Provided Allocator*
+
+Example:
+
+ import "core:fmt"
+ import "core:strings"
+ builder_make_example :: proc() {
+ sb := strings.builder_make() // Can also use the len, len/cap versions here
+ strings.write_byte(&sb, 'a')
+ strings.write_rune(&sb, ' ')
+ strings.write_string(&sb, "slice of ")
+ strings.write_f64(&sb, 3.14) // Also _float, _f32 etc
+ strings.write_string(&sb, "is ")
+ strings.write_int(&sb, 180) // Also _uint, _u64 etc
+ strings.write_rune(&sb,'°')
+ the_string :=strings.to_string(sb)
+ fmt.println(the_string)
+ }
+
+Output:
+
+ a slice of +3.14 is 180°
+
+*/
builder_make :: proc{
builder_make_none,
builder_make_len,
diff --git a/core/strings/strings.odin b/core/strings/strings.odin
index 39cbe3654..d9387c93e 100644
--- a/core/strings/strings.odin
+++ b/core/strings/strings.odin
@@ -263,7 +263,7 @@ compare :: proc(lhs, rhs: string) -> (result: int) {
return mem.compare(transmute([]byte)lhs, transmute([]byte)rhs)
}
/*
-Returns the byte offset of the rune `r` in the string `s`, -1 when not found
+Checks if rune `r` in the string `s`
Inputs:
- s: The input string