Skip to content

Commit 1f41012

Browse files
Merge pull request #16 from diffblue/feature/getChars
Model for String and StringBuilder getChars
2 parents c0cb228 + f97622e commit 1f41012

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/main/java/java/lang/String.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,25 @@ public int offsetByCodePoints(int index, int codePointOffset) {
10731073
* <li>{@code dstBegin+(srcEnd-srcBegin)} is larger than
10741074
* {@code dst.length}</ul>
10751075
*
1076-
* @diffblue.noSupport
1076+
* @diffblue.fullSupport
1077+
* @diffblue.untested
10771078
*/
10781079
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
1079-
CProver.notModelled();
1080-
// if (srcBegin < 0) {
1081-
// throw new StringIndexOutOfBoundsException(srcBegin);
1082-
// }
1083-
// if (srcEnd > value.length) {
1084-
// throw new StringIndexOutOfBoundsException(srcEnd);
1085-
// }
1086-
// if (srcBegin > srcEnd) {
1087-
// throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
1088-
// }
1080+
if (srcBegin < 0) {
1081+
throw new StringIndexOutOfBoundsException(srcBegin);
1082+
}
1083+
if (srcEnd > length()) {
1084+
throw new StringIndexOutOfBoundsException(srcEnd);
1085+
}
1086+
if (srcBegin > srcEnd) {
1087+
throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
1088+
}
1089+
// DIFFBLUE MODEL LIBRARY we inline System.arraycopy here so that we
1090+
// can specialize it for characters.
10891091
// System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
1092+
for(int i = 0; i < srcEnd - srcBegin; i++) {
1093+
dst[dstBegin + i] = CProverString.charAt(this, srcBegin + i);
1094+
}
10901095
}
10911096

10921097
/**

src/main/java/java/lang/StringBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,4 +662,13 @@ public String toString() {
662662
// value = (char[]) s.readObject();
663663
// }
664664

665+
// DIFFBLUE MODEL LIBRARY This should be inherited from AbstractStringBuilder
666+
/**
667+
* @diffblue.fullSupport
668+
* @diffblue.untested
669+
*/
670+
public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
671+
toString().getChars(srcBegin, srcEnd, dst, dstBegin);
672+
}
673+
665674
}

0 commit comments

Comments
 (0)