Is the design of lpad wrong?

I debugged today the columns no aligning OK on displaying a table, and found that the problem boiled down to the behaviour of lpad. Say I am using lpad to pad the titles of columns to width 5.
Now consider

julia> s=“Ô
“Ô

julia> textwidth(s)
1

julia> textwidth(lpad(s,5))
4

So s is not padded enough! This is according to the specification of lpad which works in terms of
codepoints and

julia> length(s)
2

But I feel that this makes lpad not the right function for padding. My questions are:

  • Is this a known problem?
  • Could this be changed in the future?
  • Are there circumstances where you want lpad to use codepoints instead of textwidth?
2 Likes

Is “Ô be internally two symbols? An A and tilde?

You get it by typing at the repl “A\tilde<tab>”

1 Like

https://github.com/JuliaLang/julia/pull/25069

1 Like

Thanks for the pointer! I will thus use my own version

my_lpad(s,n)=" "^(n-textwidth(s))*s