mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
string: make replace() clone for now; parser: comptime method
This commit is contained in:
@ -156,7 +156,7 @@ pub fn (s string) replace_once(rep, with string) string {
|
||||
|
||||
pub fn (s string) replace(rep, with string) string {
|
||||
if s.len == 0 || rep.len == 0 {
|
||||
return s
|
||||
return s.clone()
|
||||
}
|
||||
// TODO PERF Allocating ints is expensive. Should be a stack array
|
||||
// Get locations of all reps within this string
|
||||
@ -172,7 +172,7 @@ pub fn (s string) replace(rep, with string) string {
|
||||
}
|
||||
// Dont change the string if there's nothing to replace
|
||||
if idxs.len == 0 {
|
||||
return s
|
||||
return s.clone()
|
||||
}
|
||||
// Now we know the number of replacements we need to do and we can calc the len of the new string
|
||||
new_len := s.len + idxs.len * (with.len - rep.len)
|
||||
@ -1229,7 +1229,7 @@ pub fn (s string) all_after_last(dot string) string {
|
||||
return s.right(pos + dot.len)
|
||||
}
|
||||
|
||||
pub fn (s string) after(dot string) string {
|
||||
pub fn (s string) after(dot string) string {
|
||||
return s.all_after_last(dot)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user