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
// Take a look at the license at the top of the repository in the LICENSE file.
use std::str::FromStr;
use glib::translate::*;
use crate::{Language, Script};
unsafe impl Send for Language {}
unsafe impl Sync for Language {}
impl Language {
/// Determines the scripts used to to write @self.
///
/// If nothing is known about the language tag @self,
/// or if @self is [`None`], then [`None`] is returned.
/// The list of scripts returned starts with the script that the
/// language uses most and continues to the one it uses least.
///
/// The value @num_script points at will be set to the number
/// of scripts in the returned array (or zero if [`None`] is returned).
///
/// Most languages use only one script for writing, but there are
/// some that use two (Latin and Cyrillic for example), and a few
/// use three (Japanese for example). Applications should not make
/// any assumptions on the maximum number of scripts returned
/// though, except that it is positive if the return value is not
/// [`None`], and it is a small number.
///
/// The [`includes_script()`][Self::includes_script()] function uses this
/// function internally.
///
/// Note: while the return value is declared as [`Script`][crate::Script], the
/// returned values are from the `GUnicodeScript` enumeration, which
/// may have more values. Callers need to handle unknown values.
///
/// # Returns
///
///
/// An array of [`Script`][crate::Script] values, with the number of entries in
/// the array stored in @num_scripts, or [`None`] if Pango does not have
/// any information about this particular language tag (also the case
/// if @self is [`None`]).
#[doc(alias = "get_scripts")]
#[doc(alias = "pango_language_get_scripts")]
pub fn scripts(&self) -> Vec<Script> {
let mut num_scripts = 0;
let mut ret = Vec::new();
unsafe {
let scripts: *const ffi::PangoScript = ffi::pango_language_get_scripts(
mut_override(self.to_glib_none().0),
&mut num_scripts,
);
if num_scripts > 0 {
for x in 0..num_scripts {
ret.push(from_glib(
*(scripts.offset(x as isize) as *const ffi::PangoScript),
));
}
}
ret
}
}
}
impl FromStr for Language {
type Err = std::convert::Infallible;
fn from_str(language: &str) -> Result<Self, Self::Err> {
Ok(Self::from_string(language))
}
}