summaryrefslogtreecommitdiffstats
path: root/vendor/clap/src/util/str_to_bool.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/clap/src/util/str_to_bool.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/clap/src/util/str_to_bool.rs')
-rw-r--r--vendor/clap/src/util/str_to_bool.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/vendor/clap/src/util/str_to_bool.rs b/vendor/clap/src/util/str_to_bool.rs
new file mode 100644
index 000000000..1fbdc7531
--- /dev/null
+++ b/vendor/clap/src/util/str_to_bool.rs
@@ -0,0 +1,21 @@
+/// True values are `y`, `yes`, `t`, `true`, `on`, and `1`.
+pub(crate) const TRUE_LITERALS: [&str; 6] = ["y", "yes", "t", "true", "on", "1"];
+
+/// False values are `n`, `no`, `f`, `false`, `off`, and `0`.
+pub(crate) const FALSE_LITERALS: [&str; 6] = ["n", "no", "f", "false", "off", "0"];
+
+/// Converts a string literal representation of truth to true or false.
+///
+/// `false` values are `n`, `no`, `f`, `false`, `off`, and `0` (case insensitive).
+///
+/// Any other value will be considered as `true`.
+pub(crate) fn str_to_bool(val: impl AsRef<str>) -> Option<bool> {
+ let pat: &str = &val.as_ref().to_lowercase();
+ if TRUE_LITERALS.contains(&pat) {
+ Some(true)
+ } else if FALSE_LITERALS.contains(&pat) {
+ Some(false)
+ } else {
+ None
+ }
+}