-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for a
\0
escape sequence.
This commit adds support for `\0` escapes in character and string literals. Since `\0` is equivalent to `\x00`, this is a direct translation to the latter escape sequence. Future builds will be able to compile using `\0` directly. Also updated the grammar specification and added a test for NUL characters.
- Loading branch information
1 parent
4dc3a97
commit 604667f
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
pub fn main() | ||
{ | ||
let all_nuls1 = "\0\x00\u0000\U00000000"; | ||
let all_nuls2 = "\U00000000\u0000\x00\0"; | ||
let all_nuls3 = "\u0000\U00000000\x00\0"; | ||
let all_nuls4 = "\x00\u0000\0\U00000000"; | ||
|
||
// sizes for two should suffice | ||
assert_eq!(all_nuls1.len(), 4); | ||
assert_eq!(all_nuls2.len(), 4); | ||
|
||
// string equality should pass between the strings | ||
assert_eq!(all_nuls1, all_nuls2); | ||
assert_eq!(all_nuls2, all_nuls3); | ||
assert_eq!(all_nuls3, all_nuls4); | ||
|
||
// all extracted characters in all_nuls are equivalent to each other | ||
for c1 in all_nuls1.iter() | ||
{ | ||
for c2 in all_nuls1.iter() | ||
{ | ||
assert_eq!(c1,c2); | ||
} | ||
} | ||
|
||
// testing equality between explicit character literals | ||
assert_eq!('\0', '\x00'); | ||
assert_eq!('\u0000', '\x00'); | ||
assert_eq!('\u0000', '\U00000000'); | ||
|
||
// NUL characters should make a difference | ||
assert!("Hello World" != "Hello \0World"); | ||
assert!("Hello World" != "Hello World\0"); | ||
} |
604667f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from alexcrichton
at DanielRosenwasser@604667f
604667f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging DanRosenwasser/rust/master = 604667f into auto
604667f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DanRosenwasser/rust/master = 604667f merged ok, testing candidate = 7dd9344
604667f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/1542
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/1545
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/651
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/651
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/1561
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/652
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/652
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/1561
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/652
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/652
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/733
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/1546
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/651
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/652
success: http://buildbot.rust-lang.org/builders/auto-bsd-64-opt/builds/1330
604667f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 7dd9344