concat (string)

This commit is contained in:
Andrew Morris
2023-03-13 13:50:27 +11:00
parent d9077e8f01
commit 22eb55a915

View File

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