Add append to strings.

This commit is contained in:
Stephen Chung 2020-03-08 09:19:04 +08:00
parent a264abffa4
commit daa581bac7
2 changed files with 3 additions and 0 deletions

View File

@ -777,6 +777,7 @@ The following standard functions (defined in the standard library but excluded i
* `len` - returns the number of characters (not number of bytes) in the string
* `pad` - pads the string with an character until a specified number of characters
* `append` - Adds a character or a string to the end of another string
* `clear` - empties the string
* `truncate` - cuts off the string at exactly a specified number of characters
* `contains` - checks if a certain character or sub-string occurs in the string

View File

@ -303,6 +303,8 @@ impl Engine<'_> {
self.register_fn("contains", |s: &mut String, ch: char| s.contains(ch));
self.register_fn("contains", |s: &mut String, find: String| s.contains(&find));
self.register_fn("clear", |s: &mut String| s.clear());
self.register_fn("append", |s: &mut String, ch: char| s.push(ch));
self.register_fn("append", |s: &mut String, add: String| s.push_str(&add));
self.register_fn("truncate", |s: &mut String, len: i64| {
if len >= 0 {
let chars: Vec<_> = s.chars().take(len as usize).collect();