autofree: string.replace() test
parent
019e3b2f4a
commit
6d11caf784
|
@ -183,6 +183,11 @@ pub fn (s string) replace(rep string, with string) string {
|
||||||
// TODO PERF Allocating ints is expensive. Should be a stack array
|
// TODO PERF Allocating ints is expensive. Should be a stack array
|
||||||
// Get locations of all reps within this string
|
// Get locations of all reps within this string
|
||||||
mut idxs := []int{}
|
mut idxs := []int{}
|
||||||
|
defer {
|
||||||
|
unsafe {
|
||||||
|
idxs.free()
|
||||||
|
}
|
||||||
|
}
|
||||||
mut idx := 0
|
mut idx := 0
|
||||||
for {
|
for {
|
||||||
idx = s.index_after(rep, idx)
|
idx = s.index_after(rep, idx)
|
||||||
|
|
|
@ -61,12 +61,16 @@ fn str_inter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn str_replace() {
|
fn str_replace() {
|
||||||
s := 'hello world'
|
mut s := 'hello world'
|
||||||
|
s = s.replace('hello', 'hi')
|
||||||
|
println(s)
|
||||||
|
/*
|
||||||
r := s.replace('hello', 'hi')
|
r := s.replace('hello', 'hi')
|
||||||
cloned := s.replace('hello', 'hi').clone()
|
cloned := s.replace('hello', 'hi').clone()
|
||||||
cloned2 := r.clone()
|
cloned2 := r.clone()
|
||||||
println(s)
|
println(s)
|
||||||
println(r)
|
println(r)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reassign_str() {
|
fn reassign_str() {
|
||||||
|
@ -154,7 +158,7 @@ fn main() {
|
||||||
reassign_str()
|
reassign_str()
|
||||||
optional_str()
|
optional_str()
|
||||||
optional_return()
|
optional_return()
|
||||||
// str_replace()
|
str_replace()
|
||||||
if_cond()
|
if_cond()
|
||||||
addition_with_tmp_expr()
|
addition_with_tmp_expr()
|
||||||
println('end')
|
println('end')
|
||||||
|
|
Loading…
Reference in New Issue