mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
Add bindings for String.from_char_code
This commit is contained in:
parent
aa735d221a
commit
fd5958b51b
@ -2940,6 +2940,34 @@ extern "C" {
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
|
||||
pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
|
||||
|
||||
/// The static String.fromCharCode() method returns a string created from
|
||||
/// the specified sequence of UTF-16 code units.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
|
||||
/// with different arities.
|
||||
#[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
|
||||
pub fn from_char_code1(a: f64) -> JsString;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
|
||||
#[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
|
||||
pub fn from_char_code2(a: f64, b: f64) -> JsString;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
|
||||
#[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
|
||||
pub fn from_char_code3(a: f64, b: f64, c: f64) -> JsString;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
|
||||
#[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
|
||||
pub fn from_char_code4(a: f64, b: f64, c: f64, d: f64) -> JsString;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
|
||||
#[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
|
||||
pub fn from_char_code5(a: f64, b: f64, c: f64, d: f64, e: f64) -> JsString;
|
||||
|
||||
/// The `includes()` method determines whether one string may be found
|
||||
/// within another string, returning true or false as appropriate.
|
||||
///
|
||||
|
@ -58,6 +58,19 @@ fn ends_with() {
|
||||
assert_eq!(js.ends_with("to be", 19), true);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn from_char_code() {
|
||||
let s = "½+¾=";
|
||||
let codes : Vec<f64> = s.chars()
|
||||
.map(|char| char as u32 as f64)
|
||||
.collect();
|
||||
|
||||
assert_eq!(JsString::from_char_code1(codes[0]), "½");
|
||||
assert_eq!(JsString::from_char_code2(codes[0], codes[1]), "½+");
|
||||
assert_eq!(JsString::from_char_code3(codes[0], codes[1], codes[2]), "½+¾");
|
||||
assert_eq!(JsString::from_char_code4(codes[0], codes[1], codes[2], codes[3]), "½+¾=");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn includes() {
|
||||
let str = JsString::from("Blue Whale");
|
||||
|
Loading…
x
Reference in New Issue
Block a user