//! \[Experimental\] This module is experimental and currently crate-private. Let us know if you //! have a use case for this! //! //! This module contains utilities for working with properties where the specific property in use //! is not known at compile time. //! //! For regex engines, [`crate::sets::load_for_ecma262_unstable()`] is a convenient API for working //! with properties at runtime tailored for the use case of ECMA262-compatible regex engines.
/// This type can represent any Unicode property. /// /// This is intended to be used in situations where the exact unicode property needed is /// only known at runtime, for example in regex engines. /// /// The values are intended to be identical to ICU4C's UProperty enum #[allow(clippy::exhaustive_structs)] // newtype #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pubstruct UnicodeProperty(pub u32);
#[allow(unused)] // experimental, may be made public later impl UnicodeProperty { /// Given a property name (long, short, or alias), returns the corresponding [`UnicodeProperty`] /// value for it provided it belongs to the [subset relevant for ECMA262 regexes][subset] /// /// Returns none if the name does not match any of the names in this subset. Performs /// strict matching of names. /// /// If using this to implement an ECMA262-compliant regex engine, please note these caveats: /// /// - This only returns binary and enumerated properties, as well as [`Self::ScriptExtensions`]. /// Lookup can be performed sufficiently with [`Self::load_ecma262_binary_property_unstable()`], /// [`maps::load_general_category()`], [`maps::load_script()`] and [`script::load_script_with_extensions_unstable()`]. /// - This does not handle the `Any`, `Assigned`, or `ASCII` pseudoproperties, since they are not /// defined as properties. /// - `Any` can be expressed as the range `[\u{0}-\u{10FFFF}]` /// - `Assigned` can be expressed as the inverse of the set `gc=Cn` (i.e., `\P{gc=Cn}`). /// - `ASCII` can be expressed as the range `[\u{0}-\u{7F}]` /// - ECMA262 regexes transparently allow `General_Category_Mask` values for `GeneralCategory`. /// This method does not return [`Self::GeneralCategoryMask`], and instead relies on the caller to use mask-related lookup /// functions where necessary. /// - ECMA262 regexes allow treating `General_Category` (and `gcm`) values as binary properties, /// e.g. you can do things like `\p{Lu}` as shortform for `\p{gc=Lu}`. This method does not do so /// since these are property values, not properties, but you can use /// [`GeneralCategory::get_name_to_enum_mapper()`] or [`GeneralCategoryGroup::get_name_to_enum_mapper()`] /// to handle this. /// /// /// [subset]: https://tc39.es/ecma262/#table-nonbinary-unicode-properties pubfn parse_ecma262_name(name: &str) -> Option<Self> { let prop = match name { "General_Category" | "gc" => Self::GeneralCategory, "Script" | "sc" => Self::Script, "Script_Extensions" | "scx" => Self::ScriptExtensions, "ASCII_Hex_Digit" | "AHex" => Self::AsciiHexDigit, "Alphabetic" | "Alpha" => Self::Alphabetic, "Bidi_Control" | "Bidi_C" => Self::BidiControl, "Bidi_Mirrored" | "Bidi_M" => Self::BidiMirrored, "Case_Ignorable" | "CI" => Self::CaseIgnorable, "Cased" => Self::Cased, "Changes_When_Casefolded" | "CWCF" => Self::ChangesWhenCasefolded, "Changes_When_Casemapped" | "CWCM" => Self::ChangesWhenCasemapped, "Changes_When_Lowercased" | "CWL" => Self::ChangesWhenLowercased, "Changes_When_NFKC_Casefolded" | "CWKCF" => Self::ChangesWhenNfkcCasefolded, "Changes_When_Titlecased" | "CWT" => Self::ChangesWhenTitlecased, "Changes_When_Uppercased" | "CWU" => Self::ChangesWhenUppercased, "Dash" => Self::Dash, "Default_Ignorable_Code_Point" | "DI" => Self::DefaultIgnorableCodePoint, "Deprecated" | "Dep" => Self::Deprecated, "Diacritic" | "Dia" => Self::Diacritic, "Emoji" => Self::Emoji, "Emoji_Component" | "EComp" => Self::EmojiComponent, "Emoji_Modifier" | "EMod" => Self::EmojiModifier, "Emoji_Modifier_Base" | "EBase" => Self::EmojiModifierBase, "Emoji_Presentation" | "EPres" => Self::EmojiPresentation, "Extended_Pictographic" | "ExtPict" => Self::ExtendedPictographic, "Extender" | "Ext" => Self::Extender, "Grapheme_Base" | "Gr_Base" => Self::GraphemeBase, "Grapheme_Extend" | "Gr_Ext" => Self::GraphemeExtend, "Hex_Digit" | "Hex" => Self::HexDigit, "IDS_Binary_Operator" | "IDSB" => Self::IdsBinaryOperator, "IDS_Trinary_Operator" | "IDST" => Self::IdsTrinaryOperator, "ID_Continue" | "IDC" => Self::IdContinue, "ID_Start" | "IDS" => Self::IdStart, "Ideographic" | "Ideo" => Self::Ideographic, "Join_Control" | "Join_C" => Self::JoinControl, "Logical_Order_Exception" | "LOE" => Self::LogicalOrderException, "Lowercase" | "Lower" => Self::Lowercase, "Math" => Self::Math, "Noncharacter_Code_Point" | "NChar" => Self::NoncharacterCodePoint, "Pattern_Syntax" | "Pat_Syn" => Self::PatternSyntax, "Pattern_White_Space" | "Pat_WS" => Self::PatternWhiteSpace, "Quotation_Mark" | "QMark" => Self::QuotationMark, "Radical" => Self::Radical, "Regional_Indicator" | "RI" => Self::RegionalIndicator, "Sentence_Terminal" | "STerm" => Self::SentenceTerminal, "Soft_Dotted" | "SD" => Self::SoftDotted, "Terminal_Punctuation" | "Term" => Self::TerminalPunctuation, "Unified_Ideograph" | "UIdeo" => Self::UnifiedIdeograph, "Uppercase" | "Upper" => Self::Uppercase, "Variation_Selector" | "VS" => Self::VariationSelector, "White_Space" | "space" => Self::WhiteSpace, "XID_Continue" | "XIDC" => Self::XidContinue, "XID_Start" | "XIDS" => Self::XidStart,
_ => return None,
};
Some(prop)
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.