use crate::wifi::NetworkListResult;
pub fn split<const N: usize>(text: &str, ch: char) -> Option<[&str; N]> {
let mut count = 0;
let mut result = [""; N];
for part in text.split(ch) {
if let Some(elem) = result.get_mut(count) {
*elem = part.trim();
count += 1;
} else {
return None;
}
}
if count != N { None } else { Some(result) }
}
#[allow(dead_code)]
pub(crate) fn get_networkd_id(ssid: &str, list: &[NetworkListResult]) -> Option<usize> {
for r in list.iter() {
if r.ssid.eq(ssid) {
return Some(r.network_id);
}
}
None
}
pub fn chniese_filter(text: &str) -> String {
let mut name = text.to_string();
if text.contains("\\x") {
let mut bytes = Vec::new();
let mut chars = text.chars().peekable();
while let Some(c) = chars.next() {
if c == '\\' {
if let Some('x') = chars.peek() {
chars.next(); let hex_part: String = chars.by_ref().take(2).collect();
if hex_part.len() == 2 {
if let Ok(byte) = u8::from_str_radix(&hex_part, 16) {
bytes.push(byte);
continue;
}
}
bytes.extend("\\x".bytes());
bytes.extend(hex_part.bytes());
} else {
bytes.push(c as u8);
}
} else {
bytes.extend(c.to_string().as_bytes());
}
}
if let Ok(msg) = String::from_utf8(bytes) {
name = msg;
}
}
name
}
pub fn signal_to_level(signal: isize) -> i32 {
if signal >= -60 {
return 3;
}
if signal >= -70 {
return 2;
}
1
}
pub(crate) fn flags_is_encrypted(flags: &str) -> bool {
if flags.contains("WPA") || flags.contains("WEP") || flags.contains("PSK") {
return true;
}
false
}