Add str.center method
xhochy opened this issue · comments
- ✔️ pandas function
- ✔️ Python function
- ❌ C++ STL function
- ✔️ no need for a regular expression library
- ✔️ no need for a Unicode database
- ❌ cannot pre-compute output size without going over the data as some strings are wider then
width
(need no centering) and some aren't (need centering).
Pseudo-Code:
Inputs: width, fillchar
builder = StringBuilder()
for row in rows:
if utf8_len(row) >= width:
builder.append(row)
else:
n_missing = width - utf8_len(row)
left = (n_missing // 2) + (n_missing % 2)
right = (n_missing // 2)
builder.add(fillchar * left + row + fillchar * right)