Skip to content

proposal: strconv: add a version of QuoteToASCII that doesn't add quotes #34145

@the80srobot

Description

@the80srobot

I'd like to propose exporting the function strconv.quoteWith.

Use case 1: strconv.QuoteWith(s, 0, true, false) to ASCII-escape a string without adding quotes. One might want to do this for terminal output or to escape filenames.

Use case 2: strconv.QuoteWith(s, '\'', false, false) to single-quote a string.

As an additional extension, consider making strconv.QuoteWith accept a func(rune)bool instead of two bool values. It would then be used like this:

Use case 1: strconv.QuoteWith(s, 0, func(r rune) bool { return !IsPrint(r) })
Use case 2: strconv.QuoteWith(s, 0, nil)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions