Skip to content
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

has_next* methods corresponding to each next* method #3

Open
hxtk opened this issue Feb 3, 2018 · 3 comments
Open

has_next* methods corresponding to each next* method #3

hxtk opened this issue Feb 3, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@hxtk
Copy link
Owner

hxtk commented Feb 3, 2018

The design problem associated with this is that we must be able to look ahead without consuming.

As the current version makes no guarantees about tokens that do not fit in a single input buffer, we can simply examine the buffer itself. In the future, however, it will be necessary to read multiple buffers of information without consuming them.

However, BufRead.fill_buf() will happily return the same buffer over and over again if you do not consume in between.

@hxtk
Copy link
Owner Author

hxtk commented Feb 5, 2018

So the basic algorithm is the same one we use in next() except without consuming. It seems sensible to try to export the "meat" of next into a private helper function that serves both of these.

@hxtk
Copy link
Owner Author

hxtk commented Feb 5, 2018

The first thing next() does is consume leading inputs. Using this for has_next would break the unit test for next_preserves_trailing_delim. Step one is to rewrite consume_leading_delims() to return an offset instead of performing an action.

@hxtk
Copy link
Owner Author

hxtk commented Feb 5, 2018

next_line doesn't rely on next, so it doesn't follow the new rules.

However, we can implement has_next_line as a special case: if stream has_next, stream has_next_line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant