Use this when validating from a stream, as it may be that the stream stopped in the middle of a codepoint, hence state passed in as an arg, so it can be tested in a loop and also after the loop has finished.
From https://stackoverflow.com/a/22135005/101258