diff options
| author | Kevin Butler <haqkrs@gmail.com> | 2015-11-09 21:04:31 +0000 |
|---|---|---|
| committer | Kevin Butler <haqkrs@gmail.com> | 2016-01-14 22:47:50 +0000 |
| commit | 8a2723010290077bca034cd988067c70d0a638db (patch) | |
| tree | 6cf649b81664d88deb192d55f00cbf4f3bd5ff1c | |
| parent | c12c42de0ac3f4ab50f2c138e53e6e94f8da11ec (diff) | |
| download | rust-8a2723010290077bca034cd988067c70d0a638db.tar.gz rust-8a2723010290077bca034cd988067c70d0a638db.zip | |
libsyntax: use char::is_whitespace instead of custom implementations
Fixes #29590.
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/util/parser_testing.rs | 3 | ||||
| -rw-r--r-- | src/test/run-pass/parser-unicode-whitespace.rs | 18 |
3 files changed, 20 insertions, 6 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 1402b7888dd..3e61aaff3c9 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1592,10 +1592,7 @@ impl<'a> StringReader<'a> { } pub fn is_whitespace(c: Option<char>) -> bool { - match c.unwrap_or('\x00') { // None can be null for now... it's not whitespace - ' ' | '\n' | '\t' | '\r' => true, - _ => false, - } + c.map_or(false, char::is_whitespace) } fn in_range(c: Option<char>, lo: char, hi: char) -> bool { diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index 454b925a494..74ff42b5db9 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -140,9 +140,8 @@ fn scan_for_non_ws_or_end(a : &str, idx: usize) -> usize { i } -/// Copied from lexer. pub fn is_whitespace(c: char) -> bool { - return c == ' ' || c == '\t' || c == '\r' || c == '\n'; + c.is_whitespace() } #[cfg(test)] diff --git a/src/test/run-pass/parser-unicode-whitespace.rs b/src/test/run-pass/parser-unicode-whitespace.rs new file mode 100644 index 00000000000..b45216e704d --- /dev/null +++ b/src/test/run-pass/parser-unicode-whitespace.rs @@ -0,0 +1,18 @@ +// Copyright 2015 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. + + +// Beware editing: it has numerous whitespace characters which are important +pub fn main() { + assert_eq!(4 + 7 * 2 + + +/ 3 * 2 , 4 + 7 * 2 / 3 * 2); +} |
