1 | /// True values are `y`, `yes`, `t`, `true`, `on`, and `1`. |
2 | pub(crate) const TRUE_LITERALS: [&str; 6] = ["y" , "yes" , "t" , "true" , "on" , "1" ]; |
3 | |
4 | /// False values are `n`, `no`, `f`, `false`, `off`, and `0`. |
5 | pub(crate) const FALSE_LITERALS: [&str; 6] = ["n" , "no" , "f" , "false" , "off" , "0" ]; |
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`. |
12 | pub(crate) fn str_to_bool(val: impl AsRef<str>) -> Option<bool> { |
13 | let pat: &str = &val.as_ref().to_lowercase(); |
14 | if TRUE_LITERALS.contains(&pat) { |
15 | Some(true) |
16 | } else if FALSE_LITERALS.contains(&pat) { |
17 | Some(false) |
18 | } else { |
19 | None |
20 | } |
21 | } |
22 | |