New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: strings: add StripSlashes like PHP stripslashes #43579
Comments
Please describe exactly what the proposed function will do. For example, please give the documentation comment that would appear in https://golang.org/pkg/strings. Thanks. |
Doesn't strconv.Unquote do the job you need? You need to attach double quotes to the string, but that is a trivial adjustment. |
https://play.golang.org/p/THD-0MyJmnW If the string contains quotation marks in the middle.It looks more difficult to handle. |
That is unfortunate, but the code is telling you the truth: That string is not a valid Go string to be unquoted, as it contains unescaped double quotes. You are asking to solve a problem that is not well defined within the Go environment. Go has distinct rules for backslashes that are context-dependent. " is legal only in a double-quoted string, while ' is legal only in a rune constant. That is why strconv.Unquote requires the quote character to be included: it defines the rules for unquoting. You are asking for a new set of rules, and so it seems unlikely to be something needed in the standard Go library. I suggest you write the code that does what you need, and use. |
PHP stripslashes is essentially PHP unquote, as far as I can tell. |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Provide a new function, like any other language, function can Un-quotes a quoted string.
Describe:
Returns a string with backslashes stripped off. (' becomes ' and so on.)
Double backslashes (\) are made into a single backslash ().
For example:
other language function like: https://www.php.net/manual/en/function.stripslashes.php
See pull request:
#43492
Relates to the proposal:
https://go-review.googlesource.com/c/go/+/281372
The text was updated successfully, but these errors were encountered: