Skip to content

Commit e5624f0

Browse files
authored
Merge pull request #5838 from cakebaker/support_uppercase_e_in_scientific_notation
fix(lex): allow `E` in scientific notation
2 parents 5babafd + c8095c0 commit e5624f0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

clap_lex/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,9 @@ fn is_number(arg: &str) -> bool {
505505
// optional exponent, and only if it's not the first character.
506506
b'.' if !seen_dot && position_of_e.is_none() && i > 0 => seen_dot = true,
507507

508-
// Allow an exponent `e` but only at most one after the first
508+
// Allow an exponent `e`/`E` but only at most one after the first
509509
// character.
510-
b'e' if position_of_e.is_none() && i > 0 => position_of_e = Some(i),
510+
b'e' | b'E' if position_of_e.is_none() && i > 0 => position_of_e = Some(i),
511511

512512
_ => return false,
513513
}

clap_lex/tests/testsuite/parsed.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn to_short() {
120120

121121
#[test]
122122
fn is_negative_number() {
123-
for number in ["-10.0", "-1", "-100", "-3.5", "-1e10", "-1.3e10"] {
123+
for number in ["-10.0", "-1", "-100", "-3.5", "-1e10", "-1.3e10", "-1E10"] {
124124
let raw = clap_lex::RawArgs::new(["bin", number]);
125125
let mut cursor = raw.cursor();
126126
assert_eq!(raw.next_os(&mut cursor), Some(OsStr::new("bin")));
@@ -142,7 +142,9 @@ fn is_positive_number() {
142142

143143
#[test]
144144
fn is_not_number() {
145-
for number in ["--10.0", "-..", "-2..", "-e", "-1e", "-1e10.2", "-.2"] {
145+
for number in [
146+
"--10.0", "-..", "-2..", "-e", "-1e", "-1e10.2", "-.2", "-E", "-1E", "-1E10.2",
147+
] {
146148
let raw = clap_lex::RawArgs::new(["bin", number]);
147149
let mut cursor = raw.cursor();
148150
assert_eq!(raw.next_os(&mut cursor), Some(OsStr::new("bin")));

0 commit comments

Comments
 (0)