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
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,13 @@ public UTF8String substring(final int start, final int until) {
}

int j = i;
while (i < numBytes && c < until) {
i += numBytesForFirstByte(getByte(i));
c += 1;
if (until == Integer.MAX_VALUE) {
i = numBytes;
} else {
while (i < numBytes && c < until) {
i += numBytesForFirstByte(getByte(i));
c += 1;
}
}

if (i > j) {
Expand All @@ -663,9 +667,8 @@ public UTF8String substringSQL(int pos, int length) {
// refers to element i-1 in the sequence. If a start index i is less than 0, it refers
// to the -ith element before the end of the sequence. If a start index i is 0, it
// refers to the first element.
int len = numChars();
// `len + pos` does not overflow as `len >= 0`.
int start = (pos > 0) ? pos -1 : ((pos < 0) ? len + pos : 0);
int start = (pos > 0) ? pos -1 : ((pos < 0) ? numChars() + pos : 0);

int end;
if ((long) start + length > Integer.MAX_VALUE) {
Expand Down