Method
_pad
(
&self,
width: isize,
fillchar: OptionalArg<PyStrRef>,
pad: fn(&Wtf8, usize, CodePoint, usize) -> Wtf8Buf,
vm: &VirtualMachine,
)
Source from the content-addressed store, hash-verified
| 1294 | |
| 1295 | #[inline] |
| 1296 | fn _pad( |
| 1297 | &self, |
| 1298 | width: isize, |
| 1299 | fillchar: OptionalArg<PyStrRef>, |
| 1300 | pad: fn(&Wtf8, usize, CodePoint, usize) -> Wtf8Buf, |
| 1301 | vm: &VirtualMachine, |
| 1302 | ) -> PyResult<Wtf8Buf> { |
| 1303 | let fillchar = fillchar.map_or(Ok(' '.into()), |ref s| { |
| 1304 | s.as_wtf8().code_points().exactly_one().map_err(|_| { |
| 1305 | vm.new_type_error("The fill character must be exactly one character long") |
| 1306 | }) |
| 1307 | })?; |
| 1308 | Ok(if self.len() as isize >= width { |
| 1309 | self.as_wtf8().to_owned() |
| 1310 | } else { |
| 1311 | pad(self.as_wtf8(), width as usize, fillchar, self.len()) |
| 1312 | }) |
| 1313 | } |
| 1314 | |
| 1315 | #[pymethod] |
| 1316 | fn center( |
Tested by
no test coverage detected