diff options
Diffstat (limited to 'vendor/clap_lex')
-rw-r--r-- | vendor/clap_lex/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/clap_lex/Cargo.toml | 4 | ||||
-rw-r--r-- | vendor/clap_lex/README.md | 8 | ||||
-rw-r--r-- | vendor/clap_lex/src/lib.rs | 46 |
4 files changed, 48 insertions, 12 deletions
diff --git a/vendor/clap_lex/.cargo-checksum.json b/vendor/clap_lex/.cargo-checksum.json index 25c2e4c4a..d154bda49 100644 --- a/vendor/clap_lex/.cargo-checksum.json +++ b/vendor/clap_lex/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"b0a0a9111e2a86bb007b835e8480b5d132b0291699156adc9ed2fd2967e3da43","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"0d687e1f07b58fe68bda74668ff6326125e5e5efa184cce755cd84ac535b7058","README.md":"cf2d9c398038ce33c6ee39aac0aff84c550e041a4b5a79dc9c95258e2f416e3a","src/ext.rs":"f16c249c340d3c42aa566f2ff279878f807cbc74f17de19dc388f8ab352f8f1d","src/lib.rs":"db7106a744428be0915f94f4c053d04c5dd5332a1f8f57ca54a5aa7d566bae47"},"package":"2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"}
\ No newline at end of file +{"files":{"Cargo.toml":"84a1a0e3c1e608ba7f120659c895dda038d727d654f3f454b1ab6d516c3a8e3e","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"0d687e1f07b58fe68bda74668ff6326125e5e5efa184cce755cd84ac535b7058","README.md":"27a4b2cc30f5cf707c0d1c8a5e115ab695e750e44b70b51191413021237abfee","src/ext.rs":"f16c249c340d3c42aa566f2ff279878f807cbc74f17de19dc388f8ab352f8f1d","src/lib.rs":"c9996067be89f93bd7da29d64b4565c472de25ae5e1e2b40a4d05b9639f07237"},"package":"702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"}
\ No newline at end of file diff --git a/vendor/clap_lex/Cargo.toml b/vendor/clap_lex/Cargo.toml index 8b2791423..a1680fbfe 100644 --- a/vendor/clap_lex/Cargo.toml +++ b/vendor/clap_lex/Cargo.toml @@ -11,9 +11,9 @@ [package] edition = "2021" -rust-version = "1.64.0" +rust-version = "1.70.0" name = "clap_lex" -version = "0.5.0" +version = "0.6.0" include = [ "build.rs", "src/**/*", diff --git a/vendor/clap_lex/README.md b/vendor/clap_lex/README.md index 5d97fc4d3..17a40c38d 100644 --- a/vendor/clap_lex/README.md +++ b/vendor/clap_lex/README.md @@ -5,15 +5,15 @@ [![Crates.io](https://img.shields.io/crates/v/clap_lex?style=flat-square)](https://crates.io/crates/clap_lex) [![Crates.io](https://img.shields.io/crates/d/clap_lex?style=flat-square)](https://crates.io/crates/clap_lex) -[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_lex-v0.5.0/LICENSE-APACHE) -[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_lex-v0.5.0/LICENSE-MIT) +[![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_lex-v0.6.0/LICENSE-APACHE) +[![License](https://img.shields.io/badge/license-MIT-blue?style=flat-square)](https://github.com/clap-rs/clap/blob/clap_lex-v0.6.0/LICENSE-MIT) Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT). 1. [About](#about) 2. [API Reference](https://docs.rs/clap_lex) 3. [Questions & Discussions](https://github.com/clap-rs/clap/discussions) -4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_lex-v0.5.0/clap_lex/CONTRIBUTING.md) -5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_lex-v0.5.0/README.md#sponsors) +4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_lex-v0.6.0/clap_lex/CONTRIBUTING.md) +5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_lex-v0.6.0/README.md#sponsors) ## About diff --git a/vendor/clap_lex/src/lib.rs b/vendor/clap_lex/src/lib.rs index d519a10c5..581595a2c 100644 --- a/vendor/clap_lex/src/lib.rs +++ b/vendor/clap_lex/src/lib.rs @@ -300,10 +300,14 @@ impl<'s> ParsedArg<'s> { self.inner == "--" } - /// Does the argument look like a number - pub fn is_number(&self) -> bool { + /// Does the argument look like a negative number? + /// + /// This won't parse the number in full but attempts to see if this looks + /// like something along the lines of `-3`, `-0.3`, or `-33.03` + pub fn is_negative_number(&self) -> bool { self.to_value() - .map(|s| s.parse::<f64>().is_ok()) + .ok() + .and_then(|s| Some(is_number(s.strip_prefix('-')?))) .unwrap_or_default() } @@ -408,8 +412,8 @@ impl<'s> ShortFlags<'s> { /// Does the short flag look like a number /// /// Ideally call this before doing any iterator - pub fn is_number(&self) -> bool { - self.invalid_suffix.is_none() && self.utf8_prefix.as_str().parse::<f64>().is_ok() + pub fn is_negative_number(&self) -> bool { + self.invalid_suffix.is_none() && is_number(self.utf8_prefix.as_str()) } /// Advance the iterator, returning the next short flag on success @@ -466,3 +470,35 @@ fn split_nonutf8_once(b: &OsStr) -> (&str, Option<&OsStr>) { } } } + +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 && position_of_e.is_none() && i > 0 => seen_dot = true, + + // Allow an exponent `e` but only at most one after the first + // character. + b'e' if position_of_e.is_none() && i > 0 => position_of_e = Some(i), + + _ => return false, + } + } + + // Disallow `-1e` which isn't a valid float since it doesn't actually have + // an exponent. + match position_of_e { + Some(i) => i != arg.len() - 1, + None => true, + } +} |