Mercurial > hg > truffle
changeset 22036:f26b6524e5e0
fixes for empty sources
author | Mick Jordan <mick.jordan@oracle.com> |
---|---|
date | Thu, 23 Jul 2015 16:52:50 -0700 |
parents | 100d2d3250d5 |
children | 494b5e7094d0 |
files | truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java |
diffstat | 1 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java Fri Jul 17 15:02:05 2015 -0700 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java Thu Jul 23 16:52:50 2015 -0700 @@ -1273,6 +1273,9 @@ */ public int offsetToLine(int offset) throws IllegalArgumentException { if (offset < 0 || offset >= textLength) { + if (offset == 0 && textLength == 0) { + return 1; + } throw new IllegalArgumentException("offset out of bounds"); } int line = 1; @@ -1319,7 +1322,10 @@ * @throws IllegalArgumentException if there is no such line in the text. */ public int lineStartOffset(int line) throws IllegalArgumentException { - if (textLength == 0 || lineOutOfRange(line)) { + if (textLength == 0) { + return 0; + } + if (lineOutOfRange(line)) { throw new IllegalArgumentException("line out of bounds"); } return nlOffsets[line - 1]; @@ -1332,7 +1338,10 @@ * @throws IllegalArgumentException if there is no such line in the text. */ public int lineLength(int line) throws IllegalArgumentException { - if (textLength == 0 || lineOutOfRange(line)) { + if (textLength == 0) { + return 0; + } + if (lineOutOfRange(line)) { throw new IllegalArgumentException("line out of bounds"); } if (line == nlOffsets.length - 1 && !finalNL) {