This commit is contained in:
Stephen Chung
2022-08-24 21:00:08 +08:00
7 changed files with 57 additions and 1 deletions

View File

@@ -30,6 +30,11 @@ pub mod array_functions {
pub fn len(array: &mut Array) -> INT {
array.len() as INT
}
/// Return true if the array is empty.
#[rhai_fn(name = "is_empty", get = "is_empty", pure)]
pub fn is_empty(array: &mut Array) -> bool {
array.len() == 0
}
/// Get a copy of the element at the `index` position in the array.
///
/// * If `index` < 0, position counts from the end of the array (`-1` is the last element).

View File

@@ -140,6 +140,11 @@ pub mod blob_functions {
pub fn len(blob: &mut Blob) -> INT {
blob.len() as INT
}
/// Return true if the blob is empty.
#[rhai_fn(name = "is_empty", get = "is_empty", pure)]
pub fn is_empty(blob: &mut Blob) -> bool {
blob.len() == 0
}
/// 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

@@ -666,6 +666,11 @@ mod range_functions {
let _ = range;
true
}
/// Returns true if the range contains no items.
#[rhai_fn(get = "is_empty", name = "is_empty", pure)]
pub fn is_empty_exclusive(range: &mut ExclusiveRange) -> bool {
range.is_empty()
}
/// Return the start of the inclusive range.
#[rhai_fn(get = "start", name = "start", pure)]
pub fn start_inclusive(range: &mut InclusiveRange) -> INT {
@@ -688,4 +693,9 @@ mod range_functions {
let _ = range;
false
}
/// Returns true if the range contains no items.
#[rhai_fn(get = "is_empty", name = "is_empty", pure)]
pub fn is_empty_inclusive(range: &mut InclusiveRange) -> bool {
range.is_empty()
}
}

View File

@@ -25,7 +25,11 @@ mod map_functions {
pub fn len(map: &mut Map) -> INT {
map.len() as INT
}
/// Return true if the map is empty.
#[rhai_fn(name = "is_empty", get = "is_empty", pure)]
pub fn is_empty(map: &mut Map) -> bool {
map.len() == 0
}
/// 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

@@ -163,6 +163,11 @@ mod string_functions {
string.chars().count() as INT
}
}
/// Return true if the string is empty.
#[rhai_fn(name = "is_empty", get = "is_empty")]
pub fn is_empty(string: &str) -> bool {
string.len() == 0
}
/// Return the length of the string, in number of bytes used to store it in UTF-8 encoding.
///
/// # Example