Skip to content

Commit

Permalink
Merge branch '2.0.x' into 2.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Dec 20, 2018
2 parents 210d1f6 + 8d0ad03 commit 51d3626
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public StringSequence subSequence(int start, int end) {
if (subSequenceEnd > this.end) {
throw new StringIndexOutOfBoundsException(end);
}
if (start == 0 && subSequenceEnd == this.end) {
return this;
}
return new StringSequence(this.source, subSequenceStart, subSequenceEnd);
}

Expand Down Expand Up @@ -100,10 +103,18 @@ public boolean startsWith(CharSequence prefix) {
}

public boolean startsWith(CharSequence prefix, int offset) {
if (length() - prefix.length() - offset < 0) {
int prefixLength = prefix.length();
if (length() - prefixLength - offset < 0) {
return false;
}
return subSequence(offset, offset + prefix.length()).equals(prefix);
int prefixOffset = 0;
int sourceOffset = offset;
while (prefixLength-- != 0) {
if (charAt(sourceOffset++) != prefix.charAt(prefixOffset++)) {
return false;
}
}
return true;
}

@Override
Expand Down

0 comments on commit 51d3626

Please sign in to comment.