Merge pull request #1977 from nielsbasjes/EmptyGetText

Fixed empty CodePointCharStream throwing exception on getText.
This commit is contained in:
Terence Parr 2017-10-10 12:47:00 -07:00 committed by GitHub
commit c861e09d39
2 changed files with 3 additions and 2 deletions

View File

@ -23,6 +23,7 @@ public class TestCodePointCharStream {
CodePointCharStream s = CharStreams.fromString("");
assertEquals(0, s.size());
assertEquals(0, s.index());
assertEquals("", s.toString());
}
@Test

View File

@ -151,8 +151,8 @@ public abstract class CodePointCharStream implements CharStream {
/** Return the UTF-16 encoded string for the given interval */
@Override
public String getText(Interval interval) {
int startIdx = Math.min(interval.a, size - 1);
int len = Math.min(interval.b - interval.a + 1, size);
int startIdx = Math.min(interval.a, size);
int len = Math.min(interval.b - interval.a + 1, size - startIdx);
// We know the maximum code point in byteArray is U+00FF,
// so we can treat this as if it were ISO-8859-1, aka Latin-1,