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
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
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
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
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
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:
>
` 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
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
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