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

@@ -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"))]