#[cfg(feature = "std")]
extern crate std;
#[cfg_attr(not(feature = "std"), allow(unused_imports))]
use crate::ffi;
#[cfg(feature = "std")]
use std::string::String;
pub struct Idna {}
impl Idna {
#[must_use]
#[cfg(feature = "std")]
pub fn unicode(input: &str) -> String {
unsafe { ffi::ada_idna_to_unicode(input.as_ptr().cast(), input.len()) }.to_string()
}
#[must_use]
#[cfg(feature = "std")]
pub fn ascii(input: &str) -> String {
unsafe { ffi::ada_idna_to_ascii(input.as_ptr().cast(), input.len()) }.to_string()
}
}
#[cfg(test)]
mod tests {
#[cfg_attr(not(feature = "std"), allow(unused_imports))]
use crate::idna::*;
#[test]
fn unicode_should_work() {
#[cfg(feature = "std")]
assert_eq!(Idna::unicode("xn--meagefactory-m9a.ca"), "meßagefactory.ca");
}
#[test]
fn ascii_should_work() {
#[cfg(feature = "std")]
assert_eq!(Idna::ascii("meßagefactory.ca"), "xn--meagefactory-m9a.ca");
}
}