#[macro_export]
macro_rules! cfor {
($init: stmt; $cond: expr; $step: expr; $body: block) => {
{
let mut first = true;
$init;
while {
if first {
first = false
} else {
$step
}
$cond
} $body
}
}
}
pub const PF_TABLE_NAME_SIZE: usize = 32;
pub const PF_RULE_LABEL_SIZE: usize = 64;
pub const MAXPATHLEN: usize = 1024;
pub const IFNAMSIZ: usize = 16;
pub const IF_NAMESIZE: usize = 16;
pub const AI_NUMERICHOST: libc::c_int = 0x00000004;
pub(crate)
fn sanitize_str(st: &str) -> String
{
let mut out = String::with_capacity(st.len());
for c in st.chars()
{
if c.is_ascii_alphanumeric() == true ||
c.is_ascii_punctuation() == true ||
c == ' '
{
out.push(c);
}
else
{
let mut buf = [0_u8; 4];
c.encode_utf8(&mut buf);
let formatted: String =
buf[0..c.len_utf8()].into_iter()
.map(|c| format!("\\x{:02x}", c))
.collect();
out.push_str(&formatted);
}
}
return out;
}