-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add Char#printable?
#11429
Add Char#printable?
#11429
Conversation
Co-authored-by: Jason Frey <[email protected]>
' '.printable?.should be_true | ||
'a'.printable?.should be_true | ||
'酒'.printable?.should be_true | ||
'\n'.printable?.should be_false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd think that the newline character is included. It's certainly visible, and printable - same as ASCII whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking similar for tab. I guess it depends what the purpose of this method is apart from what's needed in #11406
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These characters are typically considered non-printable. For example, in other programming languages:
# Python
"\n".isprintable() # => false
"\t".isprintable() # => false
" ".isprintable() # => true
# Go
unicode.IsPrint('\n') // => false
unicode.IsPrint('\t') // => false
unicode.IsPrint(' ') // => true
I think the reasoning is that white space has no visible glyph. It's just space. Hence you can't even distinguish between different white space characters. ASCII white space
is the only exception which improves usability and is totally fine because having only a single whitespace character being printable makes it unambiguous.
This definition coincides with Go's (own) definiton, by the way: https://pkg.go.dev/unicode#IsPrint |
@HertzDevil Yes, that and Python's |
This method defines whether a character is printable.
Preparation for #11406