brigadier icon indicating copy to clipboard operation
brigadier copied to clipboard

Add isNext(char) and isNext(Predicate<Character>) methods to ImmutableStringReader and StringReader

Open ErrorCraft opened this issue 4 years ago • 5 comments

I see myself and other people use reader.canRead() && reader.peek() == c (or !reader.canRead() || reader.peek() != c) all the time. This is very tedious to do, so this adds the isAt(char) method to the ImmutableStringReader interface and StringReader class.

ErrorCraft avatar Jul 25 '21 22:07 ErrorCraft

CLA assistant check
All CLA requirements met.

ghost avatar Jul 25 '21 22:07 ghost

I feel like isAt isn't the best name for this (at makes me think of an index, not a character); maybe nextIs or something like that would be better?

Pokechu22 avatar Jul 25 '21 22:07 Pokechu22

Ah yeah, maybe something like isNext to be more consistent with the other method names like canRead? (It also reads a bit better imo)

ErrorCraft avatar Jul 27 '21 15:07 ErrorCraft

Changed the method name to isNext. I was also thinking of adding an isNext method that accepts a Predicate<Character> as a parameter to be able to check for more than one character. For example canRead() && Character.isWhitespace(peek()) in the skipWhitespace method would become isNext(Character::isWhitespace).

ErrorCraft avatar Jul 29 '21 14:07 ErrorCraft

Closing and reopening to rerun checks.

peterix avatar Oct 26 '22 16:10 peterix