#![cfg_attr(any(not(unix), target_vendor = "apple", target_os = "android"), no_std)]
extern crate alloc;
use alloc::string::String;
#[cfg(target_os = "android")]
mod android;
#[cfg(target_os = "android")]
use android as provider;
#[cfg(target_vendor = "apple")]
mod apple;
#[cfg(target_vendor = "apple")]
use apple as provider;
#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))]
mod unix;
#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))]
use unix as provider;
#[cfg(all(target_family = "wasm", feature = "js", not(unix)))]
mod wasm;
#[cfg(all(target_family = "wasm", feature = "js", not(unix)))]
use wasm as provider;
#[cfg(windows)]
mod windows;
#[cfg(windows)]
use windows as provider;
#[cfg(not(any(unix, all(target_family = "wasm", feature = "js", not(unix)), windows)))]
mod provider {
pub fn get() -> impl Iterator<Item = alloc::string::String> {
core::iter::empty()
}
}
pub fn get_locale() -> Option<String> {
get_locales().next()
}
pub fn get_locales() -> impl Iterator<Item = String> {
provider::get()
}
#[cfg(test)]
mod tests {
use super::{get_locale, get_locales};
extern crate std;
#[cfg(all(target_family = "wasm", feature = "js", not(unix)))]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(all(target_family = "wasm", feature = "js", not(unix)))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[test]
fn can_obtain_locale() {
assert!(get_locale().is_some(), "no locales were returned");
let locales = get_locales();
for (i, locale) in locales.enumerate() {
assert!(!locale.is_empty(), "locale string {} was empty", i);
assert!(
!locale.ends_with('\0'),
"locale {} contained trailing NUL",
i
);
}
}
}