Struct icu_experimental::transliterate::RuleCollection

source ·
pub struct RuleCollection { /* private fields */ }
Expand description

A collection of transliteration rules.

Enabled with the compile Cargo feature.

§Example

use icu::experimental::transliterate::{RuleCollection, Transliterator};

let mut collection = RuleCollection::default();
collection.register_source(
    &"de-t-de-d0-ascii".parse().unwrap(),
    r#"
      $AE = [Ä {A \u0308}];
      $OE = [Ö {O \u0308}];
      $UE = [Ü {U \u0308}];
  
      [ä {a \u0308}] → ae;
      [ö {o \u0308}] → oe;
      [ü {u \u0308}] → ue;
  
      {$AE} [:Lowercase:] → Ae;
      {$OE} [:Lowercase:] → Oe;
      {$UE} [:Lowercase:] → Ue;

      $AE → AE;
      $OE → OE;
      $UE → UE;
  
      ::Any-ASCII;
    "#.to_string(),
    // legacy alias, doesn't actually do anything in this case
    ["de-ASCII"],
    false,
    true,
);
collection.register_source(
    &"und-t-und-latn-d0-ascii".parse().unwrap(),
    "# ... ".to_string(),
    // the previous transliterator refers to this one by the `Any-ASCII` ID,
    // so it's important that the alias is listed here.
    ["Latin-Ascii", "Any-ASCII"],
    false,
    true,
);

let t = Transliterator::try_new_unstable(&collection.as_provider(), &collection.as_provider(), &"de-t-de-d0-ascii".parse().unwrap()).unwrap();
assert_eq!(t.transliterate("Käse".into()), "Kaese");

Implementations§

source§

impl RuleCollection

source

pub fn register_source<'a>( &mut self, id: &Locale, source: String, aliases: impl IntoIterator<Item = &'a str>, reverse: bool, visible: bool, )

Add a new transliteration source to the collection.

source

pub fn register_aliases<'a>( &mut self, id: &Locale, aliases: impl IntoIterator<Item = &'a str>, )

Add transliteration ID aliases without registering a source.

source

pub fn as_provider(&self) -> RuleCollectionProvider<'_, Baked, Baked>

Returns a provider that is usable by Transliterator::try_new_unstable.

Enabled with the compiled_data Cargo feature.

source

pub fn as_provider_unstable<'a, PP, NP>( &'a self, properties_provider: &'a PP, normalizer_provider: &'a NP, ) -> Result<RuleCollectionProvider<'a, PP, NP>, DataError>
where PP: ?Sized + DataProvider<AsciiHexDigitV1Marker> + DataProvider<AlphabeticV1Marker> + DataProvider<BidiControlV1Marker> + DataProvider<BidiMirroredV1Marker> + DataProvider<CaseIgnorableV1Marker> + DataProvider<CasedV1Marker> + DataProvider<ChangesWhenCasefoldedV1Marker> + DataProvider<ChangesWhenCasemappedV1Marker> + DataProvider<ChangesWhenLowercasedV1Marker> + DataProvider<ChangesWhenNfkcCasefoldedV1Marker> + DataProvider<ChangesWhenTitlecasedV1Marker> + DataProvider<ChangesWhenUppercasedV1Marker> + DataProvider<DashV1Marker> + DataProvider<DefaultIgnorableCodePointV1Marker> + DataProvider<DeprecatedV1Marker> + DataProvider<DiacriticV1Marker> + DataProvider<EmojiV1Marker> + DataProvider<EmojiComponentV1Marker> + DataProvider<EmojiModifierV1Marker> + DataProvider<EmojiModifierBaseV1Marker> + DataProvider<EmojiPresentationV1Marker> + DataProvider<ExtendedPictographicV1Marker> + DataProvider<ExtenderV1Marker> + DataProvider<GraphemeBaseV1Marker> + DataProvider<GraphemeClusterBreakV1Marker> + DataProvider<GraphemeClusterBreakNameToValueV2Marker> + DataProvider<GraphemeExtendV1Marker> + DataProvider<HexDigitV1Marker> + DataProvider<IdsBinaryOperatorV1Marker> + DataProvider<IdsTrinaryOperatorV1Marker> + DataProvider<IdContinueV1Marker> + DataProvider<IdStartV1Marker> + DataProvider<IdeographicV1Marker> + DataProvider<JoinControlV1Marker> + DataProvider<LogicalOrderExceptionV1Marker> + DataProvider<LowercaseV1Marker> + DataProvider<MathV1Marker> + DataProvider<NoncharacterCodePointV1Marker> + DataProvider<PatternSyntaxV1Marker> + DataProvider<PatternWhiteSpaceV1Marker> + DataProvider<QuotationMarkV1Marker> + DataProvider<RadicalV1Marker> + DataProvider<RegionalIndicatorV1Marker> + DataProvider<SentenceBreakV1Marker> + DataProvider<SentenceBreakNameToValueV2Marker> + DataProvider<SentenceTerminalV1Marker> + DataProvider<SoftDottedV1Marker> + DataProvider<TerminalPunctuationV1Marker> + DataProvider<UnifiedIdeographV1Marker> + DataProvider<UppercaseV1Marker> + DataProvider<VariationSelectorV1Marker> + DataProvider<WhiteSpaceV1Marker> + DataProvider<WordBreakV1Marker> + DataProvider<WordBreakNameToValueV2Marker> + DataProvider<XidContinueV1Marker> + DataProvider<GeneralCategoryMaskNameToValueV2Marker> + DataProvider<GeneralCategoryV1Marker> + DataProvider<ScriptNameToValueV2Marker> + DataProvider<ScriptV1Marker> + DataProvider<ScriptWithExtensionsPropertyV1Marker> + DataProvider<XidStartV1Marker>, NP: ?Sized + DataProvider<CanonicalDecompositionDataV2Marker> + DataProvider<CompatibilityDecompositionDataV2Marker> + DataProvider<CanonicalDecompositionTablesV1Marker> + DataProvider<CompatibilityDecompositionTablesV1Marker> + DataProvider<CanonicalCompositionsV1Marker>,

A version of Self::as_provider that uses custom data provided by a DataProvider.

📚 Help choosing a constructor

⚠️ The bounds on provider may change over time, including in SemVer minor releases.

Trait Implementations§

source§

impl Debug for RuleCollection

source§

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

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

impl Default for RuleCollection

source§

fn default() -> RuleCollection

Returns the “default value” for a type. Read more

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.
§

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