Message122310
Alexander Belopolsky wrote:
>
> New submission from Alexander Belopolsky <belopolsky@users.sourceforge.net>:
>
>>>> 'xyz'.center(20, '\U00100140')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: The fill character must be exactly one character long
>
> str.ljust and str.rjust are similarly affected.
I don't think we should change that for the formatting methods.
See my reply on python-dev:
str.center(n) centers the string in a padded string that
is composed of n code units. Whether that operation will result
in a text that's centered visually on output is a completely
different story. The original string could contain surrogates,
it could also contain combing code points, so the visual
presentation of the result may very well not be centered at
all; it may not even appear as having the length n to the user.
Since we're not going change the semantics of those APIs,
it is OK to not support padding with non-BMP code points on
UCS-2 builds.
Supporting such cases would only cause problems:
* if the methods would pad with surrogates, the resulting
string would no longer have length n; breaking the
assumption that len(str.center(n)) == n
* if the methods would pad with half the number of surroagtes
to make sure that len(str.center(n)) == n, the resulting
output to e.g. a terminal would be further off, than what
you already have with surrogates and combining code points
in the original string. |
|
Date |
User |
Action |
Args |
2010-11-24 20:37:51 | lemburg | set | recipients:
+ lemburg, belopolsky, pitrou, eric.smith, ezio.melotti |
2010-11-24 20:37:48 | lemburg | link | issue10521 messages |
2010-11-24 20:37:48 | lemburg | create | |
|