skiprope
skiprope copied to clipboard
Add `io.WriterTo` methods
There should be THREE io.WriterTo methods:
WriteTo(w io.Writer) (n int64, err error)WriteToSubstr(w io.Writer, pointA, pointB int) error
The latter is essentially SubstrBytes but writing it to a io.Writer
Can I get this one? -- wondering what's the reason to do that.
Be my guest
the reason you'd do that is because SubstrBytes creates and allocates a []byte. In applications where you'd have heavy writes to a string, you probably already have a []byte pool in stand by, already preallocated and ready to be used. Typically this comes in a bytes.Buffer. So might as well implement it as the io interfaces
@chewxy Sorry, it isn't clear to me what WriteTo and WriteToSubstr should do. Would you mind to give me directions?
WriteTo is like fmt.Fprintf. It writes from char 0 to char n to io.Writer that is passed in. WriteToSubstr is like WriteTo but instead of writing from 0 to n , the user passes in the range