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

@@ -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