1 // Take a look at the license at the top of the repository in the LICENSE file. 2 3 use crate::Script; 4 use glib::translate::*; 5 use glib::GString; 6 7 #[doc(alias = "PangoLanguage")] 8 pub struct Language(*mut ffi::PangoLanguage); 9 10 #[doc(hidden)] 11 impl<'a> ToGlibPtr<'a, *mut ffi::PangoLanguage> for &'a Language { 12 type Storage = &'a Language; 13 to_glib_none(&self) -> Stash<'a, *mut ffi::PangoLanguage, Self>14 fn to_glib_none(&self) -> Stash<'a, *mut ffi::PangoLanguage, Self> { 15 Stash(self.0, *self) 16 } 17 } 18 19 #[doc(hidden)] 20 impl<'a> ToGlibPtrMut<'a, *mut ffi::PangoLanguage> for Language { 21 type Storage = &'a mut Self; 22 23 #[inline] to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::PangoLanguage, Self>24 fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ffi::PangoLanguage, Self> { 25 StashMut(self.0, self) 26 } 27 } 28 29 #[doc(hidden)] 30 impl FromGlibPtrNone<*mut ffi::PangoLanguage> for Language { from_glib_none(ptr: *mut ffi::PangoLanguage) -> Self31 unsafe fn from_glib_none(ptr: *mut ffi::PangoLanguage) -> Self { 32 assert!(!ptr.is_null()); 33 Self(ptr) 34 } 35 } 36 37 #[doc(hidden)] 38 impl FromGlibPtrFull<*mut ffi::PangoLanguage> for Language { from_glib_full(ptr: *mut ffi::PangoLanguage) -> Self39 unsafe fn from_glib_full(ptr: *mut ffi::PangoLanguage) -> Self { 40 assert!(!ptr.is_null()); 41 Self(ptr) 42 } 43 } 44 45 #[doc(hidden)] 46 impl FromGlibPtrNone<*const ffi::PangoLanguage> for Language { from_glib_none(ptr: *const ffi::PangoLanguage) -> Self47 unsafe fn from_glib_none(ptr: *const ffi::PangoLanguage) -> Self { 48 assert!(!ptr.is_null()); 49 Self(ptr as *mut _) 50 } 51 } 52 53 #[doc(hidden)] 54 impl FromGlibPtrFull<*const ffi::PangoLanguage> for Language { from_glib_full(ptr: *const ffi::PangoLanguage) -> Self55 unsafe fn from_glib_full(ptr: *const ffi::PangoLanguage) -> Self { 56 assert!(!ptr.is_null()); 57 Self(ptr as *mut _) 58 } 59 } 60 61 impl Default for Language { 62 #[doc(alias = "pango_language_get_default")] default() -> Self63 fn default() -> Self { 64 unsafe { from_glib_full(ffi::pango_language_get_default()) } 65 } 66 } 67 68 impl Language { 69 #[doc(alias = "pango_language_from_string")] from_string(language: &str) -> Self70 pub fn from_string(language: &str) -> Self { 71 unsafe { from_glib_full(ffi::pango_language_from_string(language.to_glib_none().0)) } 72 } 73 74 #[doc(alias = "pango_language_to_string")] to_string(&self) -> GString75 pub fn to_string(&self) -> GString { 76 unsafe { from_glib_none(ffi::pango_language_to_string(self.to_glib_none().0)) } 77 } 78 79 #[doc(alias = "pango_language_matches")] matches(&self, range_list: &str) -> bool80 pub fn matches(&self, range_list: &str) -> bool { 81 unsafe { 82 from_glib(ffi::pango_language_matches( 83 self.to_glib_none().0, 84 range_list.to_glib_none().0, 85 )) 86 } 87 } 88 89 #[doc(alias = "pango_language_includes_script")] includes_script(&self, script: Script) -> bool90 pub fn includes_script(&self, script: Script) -> bool { 91 unsafe { 92 from_glib(ffi::pango_language_includes_script( 93 self.to_glib_none().0, 94 script.into_glib(), 95 )) 96 } 97 } 98 99 #[doc(alias = "get_scripts")] 100 #[doc(alias = "pango_language_get_scripts")] scripts(&self) -> Vec<Script>101 pub fn scripts(&self) -> Vec<Script> { 102 let mut num_scripts = 0; 103 let mut ret = Vec::new(); 104 105 unsafe { 106 let scripts: *const ffi::PangoScript = 107 ffi::pango_language_get_scripts(self.to_glib_none().0, &mut num_scripts); 108 if num_scripts > 0 { 109 for x in 0..num_scripts { 110 ret.push(from_glib( 111 *(scripts.offset(x as isize) as *const ffi::PangoScript), 112 )); 113 } 114 } 115 ret 116 } 117 } 118 119 #[doc(alias = "get_sample_string")] 120 #[doc(alias = "pango_language_get_sample_string")] sample_string(&self) -> GString121 pub fn sample_string(&self) -> GString { 122 unsafe { from_glib_none(ffi::pango_language_get_sample_string(self.to_glib_none().0)) } 123 } 124 } 125