]>
Commit | Line | Data |
---|---|---|
04454e1e | 1 | /// True values are `y`, `yes`, `t`, `true`, `on`, and `1`. |
923072b8 | 2 | pub(crate) const TRUE_LITERALS: [&str; 6] = ["y", "yes", "t", "true", "on", "1"]; |
04454e1e FG |
3 | |
4 | /// False values are `n`, `no`, `f`, `false`, `off`, and `0`. | |
923072b8 | 5 | pub(crate) const FALSE_LITERALS: [&str; 6] = ["n", "no", "f", "false", "off", "0"]; |
04454e1e FG |
6 | |
7 | /// Converts a string literal representation of truth to true or false. | |
8 | /// | |
9 | /// `false` values are `n`, `no`, `f`, `false`, `off`, and `0` (case insensitive). | |
10 | /// | |
11 | /// Any other value will be considered as `true`. | |
923072b8 | 12 | pub(crate) fn str_to_bool(val: impl AsRef<str>) -> Option<bool> { |
04454e1e | 13 | let pat: &str = &val.as_ref().to_lowercase(); |
923072b8 FG |
14 | if TRUE_LITERALS.contains(&pat) { |
15 | Some(true) | |
16 | } else if FALSE_LITERALS.contains(&pat) { | |
17 | Some(false) | |
18 | } else { | |
19 | None | |
20 | } | |
04454e1e | 21 | } |