Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions juniper/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,15 @@ fn is_source_char(c: char) -> bool {
}

fn is_name_start(c: char) -> bool {
c == '_' || ('A'..='Z').contains(&c) || ('a'..='z').contains(&c)
c == '_' || c.is_ascii_alphabetic()
}

fn is_name_cont(c: char) -> bool {
is_name_start(c) || ('0'..='9').contains(&c)
is_name_start(c) || c.is_ascii_digit()
}

fn is_number_start(c: char) -> bool {
c == '-' || ('0'..='9').contains(&c)
c == '-' || c.is_ascii_digit()
}

impl fmt::Display for LexerError {
Expand Down
13 changes: 1 addition & 12 deletions juniper/src/types/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,13 @@ use std::{
str::FromStr,
};

// Helper functions until the corresponding AsciiExt methods
// stabilise (https://github.com/rust-lang/rust/issues/39658).

fn is_ascii_alphabetic(c: char) -> bool {
('a'..='z').contains(&c) || ('A'..='Z').contains(&c)
}

fn is_ascii_digit(c: char) -> bool {
('0'..='9').contains(&c)
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Name(String);

impl Name {
pub fn is_valid(input: &str) -> bool {
for (i, c) in input.chars().enumerate() {
let is_valid = is_ascii_alphabetic(c) || c == '_' || (i > 0 && is_ascii_digit(c));
let is_valid = c.is_ascii_alphabetic() || c == '_' || (i > 0 && c.is_ascii_digit());
if !is_valid {
return false;
}
Expand Down