multiply strings by float

This commit is contained in:
Schrottkatze 2021-12-16 09:03:40 +01:00
parent c789285e6a
commit 1f59a4a874
3 changed files with 16 additions and 1 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target
.vscode/

1
sm-test-files/hello.sm Normal file
View file

@ -0,0 +1 @@
fuck java

View file

@ -1,5 +1,18 @@
use std::env;
use std::fs;
fn main() {
println!("Hello, world!, {:#?}", env::args());
let args: Vec<String> = env::args().collect();
let file = fs::read_to_string(&args[1]).expect("Couldnt read file:");
println!("{:?}", multiply_strings(file, 3.5));
}
fn multiply_strings(str: String, multiplier: f32) -> String {
let mut r: String = String::from(str);
let mult_float = multiplier - (multiplier as i32) as f32;
let slice = &r.clone()[0..(r.len() as f32 * mult_float) as usize];
r = r.repeat(multiplier as usize);
r += slice;
r
}