icu_properties::script

Struct ScriptWithExtensionsBorrowed

Source
pub struct ScriptWithExtensionsBorrowed<'a> { /* private fields */ }
Expand description

A borrowed wrapper around script extension data, returned by ScriptWithExtensions::as_borrowed(). More efficient to query.

Implementations§

Source§

impl<'a> ScriptWithExtensionsBorrowed<'a>

Source

pub fn get_script_val(self, code_point: u32) -> Script

Returns the Script property value for this code point.

§Examples
use icu::properties::{script, Script};

let swe = script::script_with_extensions();

// U+0640 ARABIC TATWEEL
assert_eq!(swe.get_script_val(0x0640), Script::Common); // main Script value
assert_ne!(swe.get_script_val(0x0640), Script::Arabic);
assert_ne!(swe.get_script_val(0x0640), Script::Syriac);
assert_ne!(swe.get_script_val(0x0640), Script::Thaana);

// U+0650 ARABIC KASRA
assert_eq!(swe.get_script_val(0x0650), Script::Inherited); // main Script value
assert_ne!(swe.get_script_val(0x0650), Script::Arabic);
assert_ne!(swe.get_script_val(0x0650), Script::Syriac);
assert_ne!(swe.get_script_val(0x0650), Script::Thaana);

// U+0660 ARABIC-INDIC DIGIT ZERO
assert_ne!(swe.get_script_val(0x0660), Script::Common);
assert_eq!(swe.get_script_val(0x0660), Script::Arabic); // main Script value
assert_ne!(swe.get_script_val(0x0660), Script::Syriac);
assert_ne!(swe.get_script_val(0x0660), Script::Thaana);

// U+FDF2 ARABIC LIGATURE ALLAH ISOLATED FORM
assert_ne!(swe.get_script_val(0xFDF2), Script::Common);
assert_eq!(swe.get_script_val(0xFDF2), Script::Arabic); // main Script value
assert_ne!(swe.get_script_val(0xFDF2), Script::Syriac);
assert_ne!(swe.get_script_val(0xFDF2), Script::Thaana);
Source

pub fn get_script_extensions_val( self, code_point: u32, ) -> ScriptExtensionsSet<'a>

Return the Script_Extensions property value for this code point.

If code_point has Script_Extensions, then return the Script codes in the Script_Extensions. In this case, the Script property value (normally Common or Inherited) is not included in the ScriptExtensionsSet.

If c does not have Script_Extensions, then the one Script code is put into the ScriptExtensionsSet and also returned.

If c is not a valid code point, then return an empty ScriptExtensionsSet.

§Examples
use icu::properties::{script, Script};

let swe = script::script_with_extensions();

assert_eq!(
    swe.get_script_extensions_val('𐓐' as u32) // U+104D0 OSAGE CAPITAL LETTER KHA
        .iter()
        .collect::<Vec<Script>>(),
    vec![Script::Osage]
);
assert_eq!(
    swe.get_script_extensions_val('🥳' as u32) // U+1F973 FACE WITH PARTY HORN AND PARTY HAT
        .iter()
        .collect::<Vec<Script>>(),
    vec![Script::Common]
);
assert_eq!(
    swe.get_script_extensions_val(0x200D) // ZERO WIDTH JOINER
        .iter()
        .collect::<Vec<Script>>(),
    vec![Script::Inherited]
);
assert_eq!(
    swe.get_script_extensions_val('௫' as u32) // U+0BEB TAMIL DIGIT FIVE
        .iter()
        .collect::<Vec<Script>>(),
    vec![Script::Tamil, Script::Grantha]
);
Source

pub fn has_script(self, code_point: u32, script: Script) -> bool

Returns whether script is contained in the Script_Extensions property value if the code_point has Script_Extensions, otherwise if the code point does not have Script_Extensions then returns whether the Script property value matches.

Some characters are commonly used in multiple scripts. For more information, see UAX #24: http://www.unicode.org/reports/tr24/.

§Examples
use icu::properties::{script, Script};

let swe = script::script_with_extensions();

// U+0650 ARABIC KASRA
assert!(!swe.has_script(0x0650, Script::Inherited)); // main Script value
assert!(swe.has_script(0x0650, Script::Arabic));
assert!(swe.has_script(0x0650, Script::Syriac));
assert!(!swe.has_script(0x0650, Script::Thaana));

// U+0660 ARABIC-INDIC DIGIT ZERO
assert!(!swe.has_script(0x0660, Script::Common)); // main Script value
assert!(swe.has_script(0x0660, Script::Arabic));
assert!(!swe.has_script(0x0660, Script::Syriac));
assert!(swe.has_script(0x0660, Script::Thaana));

// U+FDF2 ARABIC LIGATURE ALLAH ISOLATED FORM
assert!(!swe.has_script(0xFDF2, Script::Common));
assert!(swe.has_script(0xFDF2, Script::Arabic)); // main Script value
assert!(!swe.has_script(0xFDF2, Script::Syriac));
assert!(swe.has_script(0xFDF2, Script::Thaana));
Source

pub fn get_script_extensions_ranges( self, script: Script, ) -> impl Iterator<Item = RangeInclusive<u32>> + 'a

Returns all of the matching CodePointMapRanges for the given Script in which has_script will return true for all of the contained code points.

§Examples
use icu::properties::{script, Script};

let swe = script::script_with_extensions();

let syriac_script_extensions_ranges = swe.get_script_extensions_ranges(Script::Syriac);

let exp_ranges = vec![
    0x060C..=0x060C, // ARABIC COMMA
    0x061B..=0x061C, // ARABIC SEMICOLON, ARABIC LETTER MARK
    0x061F..=0x061F, // ARABIC QUESTION MARK
    0x0640..=0x0640, // ARABIC TATWEEL
    0x064B..=0x0655, // ARABIC FATHATAN..ARABIC HAMZA BELOW
    0x0670..=0x0670, // ARABIC LETTER SUPERSCRIPT ALEF
    0x0700..=0x070D, // Syriac block begins at U+0700
    0x070F..=0x074A, // Syriac block
    0x074D..=0x074F, // Syriac block ends at U+074F
    0x0860..=0x086A, // Syriac Supplement block is U+0860..=U+086F
    0x1DF8..=0x1DF8, // U+1DF8 COMBINING DOT ABOVE LEFT
    0x1DFA..=0x1DFA, // U+1DFA COMBINING DOT BELOW LEFT
];
let mut exp_ranges_iter = exp_ranges.iter();

for act_range in syriac_script_extensions_ranges {
    let exp_range = exp_ranges_iter
        .next()
        .expect("There are too many ranges returned by get_script_extensions_ranges()");
    assert_eq!(act_range.start(), exp_range.start());
    assert_eq!(act_range.end(), exp_range.end());
}
assert!(
    exp_ranges_iter.next().is_none(),
    "There are too few ranges returned by get_script_extensions_ranges()"
);
Source

pub fn get_script_extensions_set( self, script: Script, ) -> CodePointInversionList<'a>

Returns a CodePointInversionList for the given Script which represents all code points for which has_script will return true.

§Examples
use icu::properties::{script, Script};

let swe = script::script_with_extensions();

let syriac = swe.get_script_extensions_set(Script::Syriac);

assert!(!syriac.contains32(0x061E)); // ARABIC TRIPLE DOT PUNCTUATION MARK
assert!(syriac.contains32(0x061F)); // ARABIC QUESTION MARK
assert!(!syriac.contains32(0x0620)); // ARABIC LETTER KASHMIRI YEH

assert!(syriac.contains32(0x0700)); // SYRIAC END OF PARAGRAPH
assert!(syriac.contains32(0x074A)); // SYRIAC BARREKH
assert!(!syriac.contains32(0x074B)); // unassigned
assert!(syriac.contains32(0x074F)); // SYRIAC LETTER SOGDIAN FE
assert!(!syriac.contains32(0x0750)); // ARABIC LETTER BEH WITH THREE DOTS HORIZONTALLY BELOW

assert!(syriac.contains32(0x1DF8)); // COMBINING DOT ABOVE LEFT
assert!(!syriac.contains32(0x1DF9)); // COMBINING WIDE INVERTED BRIDGE BELOW
assert!(syriac.contains32(0x1DFA)); // COMBINING DOT BELOW LEFT
assert!(!syriac.contains32(0x1DFB)); // COMBINING DELETION MARK
Source§

impl ScriptWithExtensionsBorrowed<'static>

Source

pub const fn static_to_owned(self) -> ScriptWithExtensions

Cheaply converts a [ScriptWithExtensionsBorrowed<'static>] into a ScriptWithExtensions.

Note: Due to branching and indirection, using ScriptWithExtensions might inhibit some compile-time optimizations that are possible with ScriptWithExtensionsBorrowed.

Trait Implementations§

Source§

impl<'a> Clone for ScriptWithExtensionsBorrowed<'a>

Source§

fn clone(&self) -> ScriptWithExtensionsBorrowed<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ScriptWithExtensionsBorrowed<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for ScriptWithExtensionsBorrowed<'a>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T