mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-13 15:38:06 -05:00
concat (string)
This commit is contained in:
@@ -47,6 +47,7 @@ pub fn get_string_method(method: &str) -> Val {
|
||||
// "charCodeAt" => Val::Static(&CHAR_CODE_AT),
|
||||
//
|
||||
"codePointAt" => Val::Static(&CODE_POINT_AT),
|
||||
"concat" => Val::Static(&CONCAT),
|
||||
_ => Val::Undefined,
|
||||
}
|
||||
}
|
||||
@@ -96,6 +97,23 @@ static CODE_POINT_AT: NativeFunction = NativeFunction {
|
||||
},
|
||||
};
|
||||
|
||||
static CONCAT: NativeFunction = NativeFunction {
|
||||
fn_: |this: &mut Val, params: Vec<Val>| -> Val {
|
||||
match this {
|
||||
Val::String(string_data) => {
|
||||
let mut result = string_data.as_str().to_string();
|
||||
|
||||
for param in params {
|
||||
result.push_str(param.val_to_string().as_str());
|
||||
}
|
||||
|
||||
Val::String(Rc::new(result))
|
||||
}
|
||||
_ => std::panic!("Not implemented: exceptions/string indirection"),
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
fn unicode_at(bytes: &[u8], index: usize) -> Option<String> {
|
||||
match code_point_at(bytes, index) {
|
||||
Some(code_point) => Some(
|
||||
|
||||
Reference in New Issue
Block a user