Was wanting to try using StrBuf as a backing model for a textedit, until I noticed there's no good way to remove a chunk from the strbuf.
There's an insert(int index, Obj x) which presumably does the right thing in growing the buf and copying everything after index to the proper spot. But the only remove does a single character. So to remove an n-character block, you have to call remove n times, meaning everything subsequent to index gets copied n times. Instead of copying it once, to where it should end up.
You could do it yourself, with set(index, char) -- except there's no means of setting the size of the strbuf after you move everything down. size maybe should be a field with get/set, like in List, instead of being a method. But the biggest issue is the lack of a remove(range) method.
While I'm looking at StrBuf, seems like a slice method that returns a sub-string of the buffer, would be nice too.
brianThu 30 Apr 2009
Promoted to ticket #559 and assigned to brian
Good idea, I will add removeRange with consistent semantics to sys::List.removeRange.
I am not sure about slice though. If we did it seems like it should return a StrBuf, not a Str. You can always do this if you want a Str:
KevinKelley Thu 30 Apr 2009
Was wanting to try using StrBuf as a backing model for a textedit, until I noticed there's no good way to remove a chunk from the strbuf.
There's an
insert(int index, Obj x)
which presumably does the right thing in growing the buf and copying everything afterindex
to the proper spot. But the onlyremove
does a single character. So to remove ann
-character block, you have to call removen
times, meaning everything subsequent toindex
gets copiedn
times. Instead of copying it once, to where it should end up.You could do it yourself, with
set(index, char)
-- except there's no means of setting the size of the strbuf after you move everything down.size
maybe should be a field with get/set, like in List, instead of being a method. But the biggest issue is the lack of aremove(range)
method.While I'm looking at StrBuf, seems like a
slice
method that returns a sub-string of the buffer, would be nice too.brian Thu 30 Apr 2009
Promoted to ticket #559 and assigned to brian
Good idea, I will add
removeRange
with consistent semantics tosys::List.removeRange
.I am not sure about
slice
though. If we did it seems like it should return aStrBuf
, not aStr
. You can always do this if you want aStr
:brian Thu 30 Apr 2009
Ticket resolved in 1.0.42
Added StrBuf.removeRange