Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/main/java/org/scijava/parsington/Literals.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static String parseString(final CharSequence s, final Position pos) {

boolean escaped = false;
final StringBuilder sb = new StringBuilder();
int startIndex = index;
while (true) {
if (index >= s.length()) pos.die("Unclosed string literal");
final char c = s.charAt(index);
Expand All @@ -249,6 +250,7 @@ public static String parseString(final CharSequence s, final Position pos) {
}
sb.append((char) Integer.parseInt(octal, 8));
index += octal.length();
startIndex = index;
continue;
}
switch (c) {
Expand Down Expand Up @@ -284,10 +286,20 @@ public static String parseString(final CharSequence s, final Position pos) {
default: // invalid escape
pos.die("Invalid escape sequence");
}
startIndex = index+1;
}
else if (c == '\\' && quote == '"') {
escaped = true;
if (index - startIndex > 0) {
sb.append(s, startIndex, index); // before the escape
}
startIndex = -1;
} else if (c == quote) {
if (startIndex != -1 && index - startIndex > 0) {
sb.append(s, startIndex, index); // last segment
}
break;
}
else if (c == '\\' && quote == '"') escaped = true;
else if (c == quote) break;
else sb.append(c);
index++;
}
pos.set(index + 1);
Expand Down
Loading