Debian Codegraph @

src/property.rs

raw symbols SCIP
1 /// The type of a property name table.
2 ///
3 /// A property name table is a sequence of sorted tuples, where the first
4 /// value in each tuple is a normalized property name and the second value of
5 /// each tuple is the corresponding canonical property name.
6 pub type PropertyTablerust-analyzer cargo ucd-util 0.2.2 property/PropertyTable# = &'static [(&'static str, &'static str)];
7
8 /// Find the canonical property name for the given normalized property name.
9 ///
10 /// If no such property exists, then `None` is returned.
11 ///
12 /// The normalized property name must have been normalized according to
13 /// UAX44 LM3, which can be done using `symbolic_name_normalize`.
14 pub fn canonical_property_namerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_name().(
15 property_table: PropertyTablerust-analyzer cargo ucd-util 0.2.2 property/PropertyTable#,
16 normalized_property_name: &str,
17 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'static str> {
18 property_table
19 .binary_search_by_keyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]binary_search_by_key().(&normalized_property_name, |&(n, _)| n)
20 .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
21 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| property_table[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..1)
22 }
23
24 /// Type of a property value table.
25 ///
26 /// A property value table maps property names to a mapping of property values,
27 /// where the mapping of property values is represented by a sequence of
28 /// tuples. The first element of each tuple is a normalized property value
29 /// while the second element of each tuple is the corresponding canonical
30 /// property value.
31 ///
32 /// Note that a property value table only includes values for properties that
33 /// are catalogs, enumerations or binary properties. Properties that have
34 /// string values (such as case or decomposition mappings), numeric values
35 /// or are miscellaneous are not represented in this table.
36 pub type PropertyValueTablerust-analyzer cargo ucd-util 0.2.2 property/PropertyValueTable# = &'static [(&'static str, PropertyValuesrust-analyzer cargo ucd-util 0.2.2 property/PropertyValues#)];
37
38 /// A mapping of property values for a specific property.
39 ///
40 /// The first element of each tuple is a normalized property value while the
41 /// second element of each tuple is the corresponding canonical property
42 /// value.
43 pub type PropertyValuesrust-analyzer cargo ucd-util 0.2.2 property/PropertyValues# = &'static [(&'static str, &'static str)];
44
45 /// Find the set of possible property values for a given property.
46 ///
47 /// The set returned is a mapping expressed as a sorted list of tuples.
48 /// The first element of each tuple is a normalized property value while the
49 /// second element of each tuple is the corresponding canonical property
50 /// value.
51 ///
52 /// If no such property exists, then `None` is returned.
53 ///
54 /// The given property name must be in its canonical form, which can be
55 /// found using `canonical_property_name`.
56 pub fn property_valuesrust-analyzer cargo ucd-util 0.2.2 property/property_values().(
57 property_value_table: PropertyValueTablerust-analyzer cargo ucd-util 0.2.2 property/PropertyValueTable#,
58 canonical_property_name: &str,
59 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<PropertyValuesrust-analyzer cargo ucd-util 0.2.2 property/PropertyValues#> {
60 property_value_table
61 .binary_search_by_keyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]binary_search_by_key().(&canonical_property_name, |&(n, _)| n)
62 .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
63 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|i| property_value_table[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..1)
64 }
65
66 /// Find the canonical property value for the given normalized property
67 /// value.
68 ///
69 /// The given property values should correspond to the values for the property
70 /// under question, which can be found using `property_values`.
71 ///
72 /// If no such property value exists, then `None` is returned.
73 ///
74 /// The normalized property value must have been normalized according to
75 /// UAX44 LM3, which can be done using `symbolic_name_normalize`.
76 pub fn canonical_property_valuerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_value().(
77 property_values: PropertyValuesrust-analyzer cargo ucd-util 0.2.2 property/PropertyValues#,
78 normalized_property_value: &str,
79 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'static str> {
80 // This is cute. The types line up, so why not?
81 canonical_property_namerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_name().(property_values, normalized_property_value)
82 }
83
84 #[cfg(test)]
85 mod testsrust-analyzer cargo ucd-util 0.2.2 property/tests/ {
86 use craterust-analyzer cargo ucd-util 0.2.2 crate/::unicode_tablesrust-analyzer cargo ucd-util 0.2.2 unicode_tables/::property_namesrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_names/::PROPERTY_NAMESrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_names/PROPERTY_NAMES.;
87 use craterust-analyzer cargo ucd-util 0.2.2 crate/::unicode_tablesrust-analyzer cargo ucd-util 0.2.2 unicode_tables/::property_valuesrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_values/::PROPERTY_VALUESrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_values/PROPERTY_VALUES.;
88
89 use superrust-analyzer cargo ucd-util 0.2.2 property/::{
90 canonical_property_namerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_name()., canonical_property_valuerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_value()., property_valuesrust-analyzer cargo ucd-util 0.2.2 property/property_values().,
91 };
92
93 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
94 fn canonical_property_name_1rust-analyzer cargo ucd-util 0.2.2 property/tests/canonical_property_name_1().() {
95 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
96 canonical_property_namerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_name().(PROPERTY_NAMESrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_names/PROPERTY_NAMES., "gc"),
97 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("General_Category")
98 );
99 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
100 canonical_property_namerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_name().(PROPERTY_NAMESrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_names/PROPERTY_NAMES., "generalcategory"),
101 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("General_Category")
102 );
103 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(canonical_property_namerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_name().(PROPERTY_NAMESrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_names/PROPERTY_NAMES., "g c"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
104 }
105
106 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
107 fn property_values_1rust-analyzer cargo ucd-util 0.2.2 property/tests/property_values_1().() {
108 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
109 property_valuesrust-analyzer cargo ucd-util 0.2.2 property/property_values().(PROPERTY_VALUESrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_values/PROPERTY_VALUES., "White_Space"),
110 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(
111 &[
112 ("f", "No"),
113 ("false", "No"),
114 ("n", "No"),
115 ("no", "No"),
116 ("t", "Yes"),
117 ("true", "Yes"),
118 ("y", "Yes"),
119 ("yes", "Yes"),
120 ][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().
121 )
122 );
123 }
124
125 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
126 fn canonical_property_value_1rust-analyzer cargo ucd-util 0.2.2 property/tests/canonical_property_value_1().() {
127 let values = property_valuesrust-analyzer cargo ucd-util 0.2.2 property/property_values().(PROPERTY_VALUESrust-analyzer cargo ucd-util 0.2.2 unicode_tables/property_values/PROPERTY_VALUES., "White_Space").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
128 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(canonical_property_valuerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_value().(values, "false"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("No"));
129 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(canonical_property_valuerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_value().(values, "t"), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("Yes"));
130 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(canonical_property_valuerust-analyzer cargo ucd-util 0.2.2 property/canonical_property_value().(values, "F"), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
131 }
132 }