Pad string to exact length even when padding string is not multiple.

This commit is contained in:
Stephen Chung 2020-10-18 22:47:58 +08:00
parent 8a17856f27
commit d68c951795
2 changed files with 8 additions and 3 deletions

View File

@ -49,7 +49,7 @@ pub type Locked<T> = RefCell<T>;
#[cfg(feature = "sync")]
pub type Locked<T> = RwLock<T>;
/// Context of a script evaluation process.
/// Context of native Rust function call.
#[derive(Debug, Copy, Clone)]
pub struct NativeCallContext<'e, 'm> {
engine: &'e Engine,

View File

@ -324,8 +324,13 @@ mod string_functions {
let p = s.make_mut();
while str_len < len as usize {
p.push_str(padding);
str_len += padding_len;
if str_len + padding_len <= len as usize {
p.push_str(padding);
str_len += padding_len;
} else {
p.extend(padding.chars().take(len as usize - str_len));
str_len = len as usize;
}
}
#[cfg(not(feature = "unchecked"))]