From d6a9e6e46f2c2574ec0665e73b64f0d6c700557a Mon Sep 17 00:00:00 2001 From: gabrielgio Date: Fri, 25 Mar 2022 23:14:04 +0100 Subject: feat: Add extended ASCII Add more chars... --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index e8999d4..a05a1ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,8 +16,8 @@ extern { #[wasm_bindgen] -pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool) -> String { - if len == 0 ||!lower && !upper && !number && !special { +pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: bool, extended: bool) -> String { + if len == 0 || !lower && !upper && !number && !special { return "".to_string(); } @@ -25,6 +25,8 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo let mut lower_charset: Vec = String::from("abcdefghijklmnopqrstuvwxyz").chars().collect(); let mut number_charset: Vec = String::from("1234567890").chars().collect(); let mut special_charset: Vec = String::from("!@#$%^&*()+{}[]><:|+=;-.,'?_~\\/`\"").chars().collect(); + let mut extended_charset: Vec = String::from("®û´¢æ«æëàñîêáö½¬èñý¹áúóâªò×ä¸ÿ¦ù°º±¨åûïøí»§÷î¤ã¡òþ¿³óùçâüëíõôéðìö¶þ¾úý·êéãߣüèðµå¥õïà¼øäô©²¯çì").chars().collect(); + let mut result: Vec = Vec::new(); let mut rng = rand::thread_rng(); @@ -45,6 +47,10 @@ pub fn generate(len: usize, lower: bool, upper: bool, number: bool, special: boo result.append(&mut special_charset); } + if extended { + result.append(&mut extended_charset); + } + (0..len) .map(|_| { let idx = rng.gen_range(0..result.len()); -- cgit v1.2.3