Fix pad functions.
This commit is contained in:
parent
d6a08be223
commit
52ef223f83
@ -41,12 +41,14 @@ fn pad<T: Variant + Clone>(engine: &Engine, args: &mut [&mut Dynamic]) -> FuncRe
|
||||
}
|
||||
}
|
||||
|
||||
if len >= 0 {
|
||||
if len > 0 {
|
||||
let item = args[2].clone();
|
||||
let list = args[0].downcast_mut::<Array>().unwrap();
|
||||
|
||||
if len as usize > list.len() {
|
||||
list.resize(len as usize, item);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -242,29 +242,31 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
|
||||
}
|
||||
}
|
||||
|
||||
if len > 0 {
|
||||
let ch = *args[2].downcast_ref::< char>().unwrap();
|
||||
let s = args[0].downcast_mut::<ImmutableString>().unwrap();
|
||||
|
||||
let orig_len = s.chars().count();
|
||||
|
||||
if orig_len < len as usize {
|
||||
if len as usize > orig_len {
|
||||
let p = s.make_mut();
|
||||
|
||||
for _ in 0..(len as usize - orig_len) {
|
||||
p.push(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if engine.max_string_size > 0 && s.len() > engine.max_string_size {
|
||||
Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
return Err(Box::new(EvalAltResult::ErrorDataTooLarge(
|
||||
"Length of string".to_string(),
|
||||
engine.max_string_size,
|
||||
s.len(),
|
||||
Position::none(),
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
lib.set_fn_3_mut(
|
||||
|
Loading…
Reference in New Issue
Block a user