mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
\x00 for NUL in type string.
R=rsc DELTA=14 (9 added, 0 deleted, 5 changed) OCL=18281 CL=18281
This commit is contained in:
parent
8a1ad75644
commit
613a5c8bc6
3 changed files with 14 additions and 5 deletions
|
|
@ -119,7 +119,7 @@ func main() {
|
||||||
typedump("struct {a int8; b int8; c int8; d int8; b int32}", "struct{a int8; b int8; c int8; d int8; b int32}");
|
typedump("struct {a int8; b int8; c int8; d int8; b int32}", "struct{a int8; b int8; c int8; d int8; b int32}");
|
||||||
typedump("struct {a int8; b int8; c int8; d int8; e int8; b int32}", "struct{a int8; b int8; c int8; d int8; e int8; b int32}");
|
typedump("struct {a int8; b int8; c int8; d int8; e int8; b int32}", "struct{a int8; b int8; c int8; d int8; e int8; b int32}");
|
||||||
typedump("struct {a int8 \"hi there\"; }", "struct{a int8 \"hi there\"}");
|
typedump("struct {a int8 \"hi there\"; }", "struct{a int8 \"hi there\"}");
|
||||||
typedump("struct {a int8 \"hi \\0there\\t\\n\\\"\\\\\"; }", "struct{a int8 \"hi \\0there\\t\\n\\\"\\\\\"}");
|
typedump("struct {a int8 \"hi \\x00there\\t\\n\\\"\\\\\"; }", "struct{a int8 \"hi \\x00there\\t\\n\\\"\\\\\"}");
|
||||||
|
|
||||||
valuedump("int8", "8");
|
valuedump("int8", "8");
|
||||||
valuedump("int16", "16");
|
valuedump("int16", "16");
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ func DoubleQuote(s string) string {
|
||||||
case '\t':
|
case '\t':
|
||||||
out += `\t`;
|
out += `\t`;
|
||||||
case '\x00':
|
case '\x00':
|
||||||
out += `\0`;
|
out += `\x00`;
|
||||||
case '"':
|
case '"':
|
||||||
out += `\"`;
|
out += `\"`;
|
||||||
case '\\':
|
case '\\':
|
||||||
|
|
|
||||||
|
|
@ -453,7 +453,7 @@ func init() {
|
||||||
typename =
|
typename =
|
||||||
name '.' name
|
name '.' name
|
||||||
doublequotedstring =
|
doublequotedstring =
|
||||||
string in " "; escapes are \0 (NUL) \n \t \" \\
|
string in " "; escapes are \x00 (NUL) \n \t \" \\
|
||||||
fieldlist =
|
fieldlist =
|
||||||
[ field { [ ',' | ';' ] field } ]
|
[ field { [ ',' | ';' ] field } ]
|
||||||
field =
|
field =
|
||||||
|
|
@ -492,6 +492,10 @@ func special(c uint8) bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hex00(s string, i int) bool {
|
||||||
|
return i + 2 < len(s) && s[i] == '0' && s[i+1] == '0'
|
||||||
|
}
|
||||||
|
|
||||||
// Process backslashes. String known to be well-formed.
|
// Process backslashes. String known to be well-formed.
|
||||||
// Initial double-quote is left in, as an indication this token is a string.
|
// Initial double-quote is left in, as an indication this token is a string.
|
||||||
func unescape(s string, backslash bool) string {
|
func unescape(s string, backslash bool) string {
|
||||||
|
|
@ -509,8 +513,13 @@ func unescape(s string, backslash bool) string {
|
||||||
c = '\n';
|
c = '\n';
|
||||||
case 't':
|
case 't':
|
||||||
c = '\t';
|
c = '\t';
|
||||||
case '0': // it's not a legal go string but \0 means NUL
|
case 'x':
|
||||||
c = '\x00';
|
if hex00(s, i+1) {
|
||||||
|
i += 2;
|
||||||
|
c = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// otherwise just put an 'x'; erroneous but safe.
|
||||||
// default is correct already; \\ is \; \" is "
|
// default is correct already; \\ is \; \" is "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue