Skip to content

Commit d5943b6

Browse files
Add FFI property try_from_str (#7367)
#7357
1 parent 5180c17 commit d5943b6

File tree

118 files changed

+1452
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1452
-62
lines changed

components/properties/src/names.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
151151
/// ```
152152
#[inline]
153153
pub fn get_strict_u16(self, name: &str) -> Option<u16> {
154+
self.get_strict_u16_utf8(name.as_bytes())
155+
}
156+
157+
#[doc(hidden)]
158+
pub fn get_strict_u16_utf8(self, name: &[u8]) -> Option<u16> {
154159
get_strict_u16(self.map, name)
155160
}
156161

@@ -177,7 +182,12 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
177182
/// ```
178183
#[inline]
179184
pub fn get_strict(self, name: &str) -> Option<T> {
180-
T::try_from_u32(self.get_strict_u16(name)? as u32).ok()
185+
self.get_strict_utf8(name.as_bytes())
186+
}
187+
188+
#[doc(hidden)]
189+
pub fn get_strict_utf8(self, name: &[u8]) -> Option<T> {
190+
T::try_from_u32(self.get_strict_u16_utf8(name)? as u32).ok()
181191
}
182192

183193
/// Get the property value as a u16, doing a loose search looking for
@@ -207,6 +217,11 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
207217
/// ```
208218
#[inline]
209219
pub fn get_loose_u16(self, name: &str) -> Option<u16> {
220+
self.get_loose_u16_utf8(name.as_bytes())
221+
}
222+
223+
#[doc(hidden)]
224+
pub fn get_loose_u16_utf8(self, name: &[u8]) -> Option<u16> {
210225
get_loose_u16(self.map, name)
211226
}
212227

@@ -237,7 +252,12 @@ impl<T: TrieValue> PropertyParserBorrowed<'_, T> {
237252
/// ```
238253
#[inline]
239254
pub fn get_loose(self, name: &str) -> Option<T> {
240-
T::try_from_u32(self.get_loose_u16(name)? as u32).ok()
255+
self.get_loose_utf8(name.as_bytes())
256+
}
257+
258+
#[doc(hidden)]
259+
pub fn get_loose_utf8(self, name: &[u8]) -> Option<T> {
260+
T::try_from_u32(self.get_loose_u16_utf8(name)? as u32).ok()
241261
}
242262
}
243263

@@ -278,12 +298,12 @@ impl<T: TrieValue> PropertyParserBorrowed<'static, T> {
278298
}
279299

280300
/// Avoid monomorphizing multiple copies of this function
281-
fn get_strict_u16(payload: &PropertyValueNameToEnumMap<'_>, name: &str) -> Option<u16> {
301+
fn get_strict_u16(payload: &PropertyValueNameToEnumMap<'_>, name: &[u8]) -> Option<u16> {
282302
payload.map.get(name).and_then(|i| i.try_into().ok())
283303
}
284304

285305
/// Avoid monomorphizing multiple copies of this function
286-
fn get_loose_u16(payload: &PropertyValueNameToEnumMap<'_>, name: &str) -> Option<u16> {
306+
fn get_loose_u16(payload: &PropertyValueNameToEnumMap<'_>, name: &[u8]) -> Option<u16> {
287307
fn recurse(mut cursor: ZeroTrieSimpleAsciiCursor, mut rest: &[u8]) -> Option<usize> {
288308
if cursor.is_empty() {
289309
return None;
@@ -326,7 +346,7 @@ fn get_loose_u16(payload: &PropertyValueNameToEnumMap<'_>, name: &str) -> Option
326346
recurse(cursor, rest).or_else(|| recurse(other_case_cursor, rest))
327347
}
328348

329-
recurse(payload.map.cursor(), name.as_bytes()).and_then(|i| i.try_into().ok())
349+
recurse(payload.map.cursor(), name).and_then(|i| i.try_into().ok())
330350
}
331351

332352
/// A struct capable of looking up a property name from a value
@@ -726,7 +746,12 @@ pub trait NamedEnumeratedProperty: ParseableEnumeratedProperty {
726746
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
727747
#[cfg(feature = "compiled_data")]
728748
fn try_from_str(s: &str) -> Option<Self> {
729-
PropertyParser::new().get_loose(s)
749+
Self::try_from_utf8(s.as_bytes())
750+
}
751+
#[cfg(feature = "compiled_data")]
752+
#[doc(hidden)]
753+
fn try_from_utf8(s: &[u8]) -> Option<Self> {
754+
PropertyParser::new().get_loose_utf8(s)
730755
}
731756
/// Convenience method for `PropertyNamesLong::new().get(*self).unwrap()`
732757
///

ffi/capi/bindings/c/BidiClass.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/CanonicalCombiningClass.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/EastAsianWidth.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/GeneralCategory.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/GraphemeClusterBreak.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/HangulSyllableType.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/IndicConjunctBreak.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/IndicSyllabicCategory.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/c/JoiningGroup.h

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)