Fixed issue with characters being removed during replace

In cases where the a character of the string that was to be replaced was found a partial match would occur.  However, the logic would place misplace the partial match in a different position in the resulting output.  In addition, some cases the result would skip some characters at the end of the stream.

This fix calculates and appends the tail of the stream based on the remaining stream buffer and the match.

Fixes #3