icu_experimental::transliterate

Struct 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(), &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, 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, NC>( &'a self, properties_provider: &'a PP, normalizer_provider: &'a NP, casemap_provider: &'a NC, ) -> Result<RuleCollectionProvider<'a, PP, NP, NC>, DataError>
where PP: ?Sized + DataProvider<PropertyBinaryAlphabeticV1> + DataProvider<PropertyBinaryAsciiHexDigitV1> + DataProvider<PropertyBinaryBidiControlV1> + DataProvider<PropertyBinaryBidiMirroredV1> + DataProvider<PropertyBinaryCasedV1> + DataProvider<PropertyBinaryCaseIgnorableV1> + DataProvider<PropertyBinaryChangesWhenCasefoldedV1> + DataProvider<PropertyBinaryChangesWhenCasemappedV1> + DataProvider<PropertyBinaryChangesWhenLowercasedV1> + DataProvider<PropertyBinaryChangesWhenNfkcCasefoldedV1> + DataProvider<PropertyBinaryChangesWhenTitlecasedV1> + DataProvider<PropertyBinaryChangesWhenUppercasedV1> + DataProvider<PropertyBinaryDashV1> + DataProvider<PropertyBinaryDefaultIgnorableCodePointV1> + DataProvider<PropertyBinaryDeprecatedV1> + DataProvider<PropertyBinaryDiacriticV1> + DataProvider<PropertyBinaryEmojiComponentV1> + DataProvider<PropertyBinaryEmojiModifierBaseV1> + DataProvider<PropertyBinaryEmojiModifierV1> + DataProvider<PropertyBinaryEmojiPresentationV1> + DataProvider<PropertyBinaryEmojiV1> + DataProvider<PropertyBinaryExtendedPictographicV1> + DataProvider<PropertyBinaryExtenderV1> + DataProvider<PropertyBinaryGraphemeBaseV1> + DataProvider<PropertyBinaryGraphemeExtendV1> + DataProvider<PropertyBinaryHexDigitV1> + DataProvider<PropertyBinaryIdContinueV1> + DataProvider<PropertyBinaryIdeographicV1> + DataProvider<PropertyBinaryIdsBinaryOperatorV1> + DataProvider<PropertyBinaryIdStartV1> + DataProvider<PropertyBinaryIdsTrinaryOperatorV1> + DataProvider<PropertyBinaryJoinControlV1> + DataProvider<PropertyBinaryLogicalOrderExceptionV1> + DataProvider<PropertyBinaryLowercaseV1> + DataProvider<PropertyBinaryMathV1> + DataProvider<PropertyBinaryNoncharacterCodePointV1> + DataProvider<PropertyBinaryPatternSyntaxV1> + DataProvider<PropertyBinaryPatternWhiteSpaceV1> + DataProvider<PropertyBinaryQuotationMarkV1> + DataProvider<PropertyBinaryRadicalV1> + DataProvider<PropertyBinaryRegionalIndicatorV1> + DataProvider<PropertyBinarySentenceTerminalV1> + DataProvider<PropertyBinarySoftDottedV1> + DataProvider<PropertyBinaryTerminalPunctuationV1> + DataProvider<PropertyBinaryUnifiedIdeographV1> + DataProvider<PropertyBinaryUppercaseV1> + DataProvider<PropertyBinaryVariationSelectorV1> + DataProvider<PropertyBinaryWhiteSpaceV1> + DataProvider<PropertyBinaryXidContinueV1> + DataProvider<PropertyBinaryXidStartV1> + DataProvider<PropertyEnumCanonicalCombiningClassV1> + DataProvider<PropertyEnumGeneralCategoryV1> + DataProvider<PropertyEnumGraphemeClusterBreakV1> + DataProvider<PropertyEnumScriptV1> + DataProvider<PropertyEnumSentenceBreakV1> + DataProvider<PropertyEnumWordBreakV1> + DataProvider<PropertyNameParseCanonicalCombiningClassV1> + DataProvider<PropertyNameParseGeneralCategoryMaskV1> + DataProvider<PropertyNameParseGraphemeClusterBreakV1> + DataProvider<PropertyNameParseScriptV1> + DataProvider<PropertyNameParseSentenceBreakV1> + DataProvider<PropertyNameParseWordBreakV1> + DataProvider<PropertyScriptWithExtensionsV1>, NP: ?Sized + DataProvider<NormalizerNfdDataV1> + DataProvider<NormalizerNfkdDataV1> + DataProvider<NormalizerNfdTablesV1> + DataProvider<NormalizerNfkdTablesV1> + DataProvider<NormalizerNfcV1>, NC: ?Sized + DataProvider<CaseMapV1>,

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,