Skip to content

-.1 is not recognized with allow_negative_numbers(true) #5837

Answered by epage
cakebaker asked this question in Q&A
Discussion options

You must be logged in to vote

Our "is number" check is at

clap/clap_lex/src/lib.rs

Lines 492 to 522 in 5babafd

fn is_number(arg: &str) -> bool {
// Return true if this looks like an integer or a float where it's all
// digits plus an optional single dot after some digits.
//
// For floats allow forms such as `1.`, `1.2`, `1.2e10`, etc.
let mut seen_dot = false;
let mut position_of_e = None;
for (i, c) in arg.as_bytes().iter().enumerate() {
match c {
// Digits are always valid
b'0'..=b'9' => {}
// Allow a `.`, but only one, only if it comes before an
// optional exponent, and only if it's not the first character.
b'.' if !seen_dot && posi…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cakebaker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants