Skip to content

has_next* methods corresponding to each next* method #3

Description

@hxtk

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.

Activity

  1. hxtk commented on Feb 5, 2018

    @hxtk
    OwnerAuthor

    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.

  2. hxtk commented on Feb 5, 2018

    @hxtk
    OwnerAuthor

    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.

  3. hxtk commented on Feb 5, 2018

    @hxtk
    OwnerAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions