Use tokens to speed up function name lookup.

This commit is contained in:
Stephen Chung
2022-09-25 23:03:18 +08:00
parent ece522ce2f
commit bf02d040e2
15 changed files with 417 additions and 349 deletions

View File

@@ -146,6 +146,21 @@ pub mod blob_functions {
pub fn is_empty(blob: &mut Blob) -> bool {
blob.len() == 0
}
/// Return `true` if the BLOB contains a specified byte value.
///
/// # Example
///
/// ```rhai
/// let text = "hello, world!";
///
/// print(text.contains('h')); // prints true
///
/// print(text.contains('x')); // prints false
/// ```
#[rhai_fn(name = "contains")]
pub fn contains(blob: &mut Blob, value: INT) -> bool {
blob.contains(&((value & 0x0000_00ff) as u8))
}
/// Get the byte value at the `index` position in the BLOB.
///
/// * If `index` < 0, position counts from the end of the BLOB (`-1` is the last element).

View File

@@ -668,6 +668,12 @@ mod range_functions {
pub fn is_empty_exclusive(range: &mut ExclusiveRange) -> bool {
range.is_empty()
}
/// Return `true` if the range contains a specified value.
#[rhai_fn(name = "contains")]
pub fn contains_exclusive(range: &mut ExclusiveRange, value: INT) -> bool {
range.contains(&value)
}
/// Return the start of the inclusive range.
#[rhai_fn(get = "start", name = "start", pure)]
pub fn start_inclusive(range: &mut InclusiveRange) -> INT {
@@ -695,4 +701,9 @@ mod range_functions {
pub fn is_empty_inclusive(range: &mut InclusiveRange) -> bool {
range.is_empty()
}
/// Return `true` if the range contains a specified value.
#[rhai_fn(name = "contains")]
pub fn contains_inclusive(range: &mut InclusiveRange, value: INT) -> bool {
range.contains(&value)
}
}

View File

@@ -30,6 +30,20 @@ mod map_functions {
pub fn is_empty(map: &mut Map) -> bool {
map.len() == 0
}
/// Returns `true` if the object map contains a specified property.
///
/// # Example
///
/// ```rhai
/// let m = #{a: 1, b: 2, c: 3};
///
/// print(m.contains("b")); // prints true
///
/// print(m.contains("x")); // prints false
/// ```
pub fn contains(map: &mut Map, property: &str) -> bool {
map.contains_key(property)
}
/// Get the value of the `property` in the object map and return a copy.
///
/// If `property` does not exist in the object map, `()` is returned.

View File

@@ -506,6 +506,37 @@ mod string_functions {
*character = to_lower_char(*character);
}
/// Return `true` if the string contains a specified string.
///
/// # Example
///
/// ```rhai
/// let text = "hello, world!";
///
/// print(text.contains("hello")); // prints true
///
/// print(text.contains("hey")); // prints false
/// ```
pub fn contains(string: &str, match_string: &str) -> bool {
string.contains(match_string)
}
/// Return `true` if the string contains a specified character.
///
/// # Example
///
/// ```rhai
/// let text = "hello, world!";
///
/// print(text.contains('h')); // prints true
///
/// print(text.contains('x')); // prints false
/// ```
#[rhai_fn(name = "contains")]
pub fn contains_char(string: &str, character: char) -> bool {
string.contains(character).into()
}
/// Return `true` if the string starts with a specified string.
///
/// # Example