Add bytes method for strings.
This commit is contained in:
parent
330d3f87af
commit
a7ff9fb24f
@ -38,6 +38,7 @@ Enhancements
|
|||||||
* More information is provided to the error variable captured by the `catch` statement in an _object map_.
|
* More information is provided to the error variable captured by the `catch` statement in an _object map_.
|
||||||
* Previously, `private` functions in an `AST` cannot be called with `call_fn` etc. This is inconvenient when trying to call a function inside a script which also serves as a loadable module exporting part (but not all) of the functions. Now, all functions (`private` or not) can be called in an `AST`. The `private` keyword is relegated to preventing a function from being exported.
|
* Previously, `private` functions in an `AST` cannot be called with `call_fn` etc. This is inconvenient when trying to call a function inside a script which also serves as a loadable module exporting part (but not all) of the functions. Now, all functions (`private` or not) can be called in an `AST`. The `private` keyword is relegated to preventing a function from being exported.
|
||||||
* `Dynamic::as_unit` just for completeness sake.
|
* `Dynamic::as_unit` just for completeness sake.
|
||||||
|
* `bytes` method added for strings to get length quickly (if the string is ASCII-only).
|
||||||
|
|
||||||
|
|
||||||
Version 0.19.13
|
Version 0.19.13
|
||||||
|
@ -12,7 +12,7 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
|||||||
// Register string iterator
|
// Register string iterator
|
||||||
lib.set_iter(
|
lib.set_iter(
|
||||||
TypeId::of::<ImmutableString>(),
|
TypeId::of::<ImmutableString>(),
|
||||||
|string: Dynamic| Box::new(string.cast::<ImmutableString>().chars().collect::<Vec<_>>().into_iter().map(Into::into))
|
|string| Box::new(string.cast::<ImmutableString>().chars().collect::<Vec<_>>().into_iter().map(Into::into))
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -42,6 +42,10 @@ mod string_functions {
|
|||||||
pub fn len(string: &str) -> INT {
|
pub fn len(string: &str) -> INT {
|
||||||
string.chars().count() as INT
|
string.chars().count() as INT
|
||||||
}
|
}
|
||||||
|
#[rhai_fn(name = "bytes", get = "bytes")]
|
||||||
|
pub fn bytes(string: &str) -> INT {
|
||||||
|
string.len() as INT
|
||||||
|
}
|
||||||
pub fn remove(string: &mut ImmutableString, sub_string: ImmutableString) {
|
pub fn remove(string: &mut ImmutableString, sub_string: ImmutableString) {
|
||||||
*string -= sub_string;
|
*string -= sub_string;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user