Convert string literals
Reports double-quoted string literals that can be converted into raw string literals and raw string literals that can be converted to double-quoted string literals.
Example:
After the quick fix is applied:
There are two notes that you should take into account while converting double-quoted strings to raw strings:
According to the Go language specification, the carriage return character (
'\r'
) is discarded from the raw string values. As there is no way to show carriage return in raw strings, we discard carriage return characters when converting a double-quoted string to a raw string.The backtick character (
'`'
) cannot exist in raw string literals because there is no way to escape it. Therefore, converting double-quoted strings that contain the backtick character to raw strings is not possible and will result in a syntax error. The user can decide to undo the conversion or use some form of concatenation to preserve the backtick in a double-quoted string. For example,"`ab``"
will result in`ab``
, which is syntactically incorrect. The user can either undo the operation or change the resulting string to`ab` + "`"
.
Inspection Details | |
---|---|
Available in: | GoLand 2023.3 |
Plugin: | Go, 233.SNAPSHOT |