-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make startswith work with IO objects #43055
Conversation
I suppose this should use |
I am not quite familiar with those. Where should I add them? |
Co-authored-by: Steven G. Johnson <stevenj@mit.edu>
Looks like it just needs a NEWS item, something like:
|
Personally, I think this is kind of a strange API for an But I think it is best to keep |
As @schneiderfelipe pointed out in the original issue, it's a nice complement to |
Check if an `IO` object starts with a prefix. | ||
""" | ||
function Base.startswith(io::IO, prefix::Base.Chars) | ||
mark(io) |
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.
Seems worth it to optimize the common case of an ASCII char, especially since a stream may conceivably support peek
but not mark
/reset
.
mark(io) | |
prefix isa AbstractChar && prefix ≤ '\x7f' && return peek(io) == prefix % UInt8 | |
mark(io) |
closes #40616.