1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![allow(missing_docs)]
use std;
use sys;
#[derive(Copy, Clone, PartialEq, PartialOrd)]
pub struct Language {
raw: sys::hb_language_t,
}
impl Language {
pub fn from_string(lang: &str) -> Self {
Language {
raw: unsafe {
sys::hb_language_from_string(
lang.as_ptr() as *const std::os::raw::c_char,
lang.len() as std::os::raw::c_int,
)
},
}
}
pub fn to_string(&self) -> &str {
unsafe { std::ffi::CStr::from_ptr(sys::hb_language_to_string(self.raw)) }
.to_str()
.unwrap()
}
pub unsafe fn from_raw(raw: sys::hb_language_t) -> Self {
Language { raw }
}
pub fn as_raw(self) -> sys::hb_language_t {
self.raw
}
pub fn get_process_default() -> Self {
Language {
raw: unsafe { sys::hb_language_get_default() },
}
}
pub fn is_valid(self) -> bool {
!self.raw.is_null()
}
}
impl std::fmt::Debug for Language {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
fmt.write_str(self.to_string())
}
}
#[cfg(test)]
mod tests {
use super::Language;
#[test]
fn test_lookup() {
let en = Language::from_string("en_US");
assert!(en.is_valid());
}
}