Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-14 Thread 'Tim Hockin' via golang-nuts
I tried: strconv.Quote() strconv.AppendQuote() (weird that this is faster than Quote) fmt.Sprintf("%q") scanning for !IsPrint() + bytes.Buffer scanning for !IsPrint() + strings.Builder (sad that this is not faster than Buffer) scanning for !IsPrint() + string addition ``` $ go test -benchtime=5s

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-14 Thread roger peppe
On Thu, 14 Oct 2021 at 04:58, 'Tim Hockin' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Thanks for confirming. I wrote that function and erased a good bit of the > overhead. > > bytes.Buffer for the no-escapes path and strconv.Quote otherwise. > Could you not use strconv.AppendQuote

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-13 Thread 'Tim Hockin' via golang-nuts
Thanks for confirming. I wrote that function and erased a good bit of the overhead. bytes.Buffer for the no-escapes path and strconv.Quote otherwise. On Wed, Oct 13, 2021, 8:49 PM Ian Lance Taylor wrote: > On Wed, Oct 13, 2021 at 3:46 PM 'Tim Hockin' via golang-nuts > wrote: > > > > Is there

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-13 Thread Ian Lance Taylor
On Wed, Oct 13, 2021 at 3:46 PM 'Tim Hockin' via golang-nuts wrote: > > Is there any ready-built function that can tell me whether `strconv.Quote()` > would produce a different string than its input, without actually running it? > Or is there a clearly documented set of rules one could use to t

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-13 Thread 'Tim Hockin' via golang-nuts
If I find a string with a stray backslash in it (which passes IsPrint()) I still need to quote. I dug into the Quote() impl and this seems like the right path. Thanks! On Wed, Oct 13, 2021 at 4:31 PM Robert Engels wrote: > I was thinking the other way. If !IsPrint() then strconv.Quote() > > On

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-13 Thread Robert Engels
I was thinking the other way. If !IsPrint() then strconv.Quote() > On Oct 13, 2021, at 6:24 PM, Tim Hockin wrote: > >  > ` IsPrint(r) || r == '\\' || r == '"' ` passes tests. I need to build > confidence in that, though :) Thanks. > >> On Wed, Oct 13, 2021 at 4:16 PM Robert Engels wrote: >

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-13 Thread 'Tim Hockin' via golang-nuts
` IsPrint(r) || r == '\\' || r == '"' ` passes tests. I need to build confidence in that, though :) Thanks. On Wed, Oct 13, 2021 at 4:16 PM Robert Engels wrote: > A simple loop calling IsPrint is your best bet. You could then have a > custom implementation of Quote that started at a specified

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-13 Thread Robert Engels
A simple loop calling IsPrint is your best bet. You could then have a custom implementation of Quote that started at a specified index. > On Oct 13, 2021, at 5:46 PM, 'Tim Hockin' via golang-nuts > wrote: > > Is there any ready-built function that can tell me whether `strconv.Quote()` > wou

[go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-13 Thread 'Tim Hockin' via golang-nuts
Is there any ready-built function that can tell me whether `strconv.Quote()` would produce a different string than its input, without actually running it? Or is there a clearly documented set of rules one could use to test each rune in a string? I am trying to avoid allocations, and MOST of th