-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wc_rjust() doesn't work for non-printables #54
Comments
I was thinking of a new function |
Issue #79 proposes new width() function |
See also #93 to just offer a proper rjust/etc. as part of the API |
I just want to also add that this cannot be fixed in the wcwidth() and wcswidth() functions, as they intend to exactly match function signature and behavior of the POSIX functions. The reason that C0 and C1 control characters return -1, is that the intended application, a terminal emulator especially, should handle these characters in a stream and remove them from the string before passing on to wcswidth. Especially items like So I won't really consider this a bug, but a feature request for an alternate function that simply ignores these things. Although these characters should not be sent to wcswidth, developers are free to have them silently ignored. I would suggest all control characters have width of 0 for a new function, wcwidth.width |
Firstly, this isn't a problem for me, I just wanted to let you know about it.
Using
wc_rjust()
from the readme, iftext
contains any non-printable characters, the result is longer thanlength
, which should never happen.For example,
'\n'
is non-printable:For reference, the width-naive version:
The problem is because of the math here:
If
wcswidth(text)
is negative, the max islength + 1
.The simple solution is to just add a note in the readme warning about this situation, but if you wanted, you could expand the function to raise an error:
Ultimately, it seems like the problem is using
-1
as a sentinel return value instead of raising an error, but it looks like that's inherited from the C function, so fixing that would be a lot of work.The text was updated successfully, but these errors were encountered: