diff options
author | CreepySkeleton <50968528+CreepySkeleton@users.noreply.github.com> | 2019-05-24 07:44:28 +0300 |
---|---|---|
committer | David Tolnay <dtolnay@gmail.com> | 2019-05-23 21:44:28 -0700 |
commit | a5227dab205915d45bc1f1b90ea7a3fe996346a4 (patch) | |
tree | 8b87cc8066743891f10ef37df88c0f0809f6c4cf /src/runtime.rs | |
parent | 57038ba5e418deb3fec0f83ae5ad0bf7e0d3d611 (diff) | |
download | platform_external_rust_crates_quote-a5227dab205915d45bc1f1b90ea7a3fe996346a4.tar.gz platform_external_rust_crates_quote-a5227dab205915d45bc1f1b90ea7a3fe996346a4.tar.bz2 platform_external_rust_crates_quote-a5227dab205915d45bc1f1b90ea7a3fe996346a4.zip |
Simplify is_ident function (#104)
It's a way over-complicated
Diffstat (limited to 'src/runtime.rs')
-rw-r--r-- | src/runtime.rs | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/src/runtime.rs b/src/runtime.rs index 715a877..75337c9 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -10,21 +10,10 @@ fn is_ident_continue(c: u8) -> bool { } fn is_ident(token: &str) -> bool { - if token.bytes().all(|digit| digit >= b'0' && digit <= b'9') { - return false; - } - - let mut bytes = token.bytes(); - let first = bytes.next().unwrap(); - if !is_ident_start(first) { - return false; - } - for ch in bytes { - if !is_ident_continue(ch) { - return false; - } - } - true + let mut iter = token.bytes(); + let first_ok = iter.next().map(is_ident_start).unwrap_or(false); + + first_ok && iter.all(is_ident_continue) } pub fn parse(tokens: &mut TokenStream, span: Span, s: &str) { |