File tree 2 files changed +34
-12
lines changed
2 files changed +34
-12
lines changed Original file line number Diff line number Diff line change @@ -216,21 +216,21 @@ public String(char value[]) {
216
216
* characters outside the bounds of the {@code value} array
217
217
*
218
218
* @diffblue.limitedSupport
219
- * Does not throw exceptions.
220
219
* @diffblue.untested
221
220
*/
222
221
public String (char value [], int offset , int count ) {
223
- // DIFFBLUE MODEL LIBRARY This is treated internally in CBMC
224
- // if (offset < 0) {
225
- // throw new StringIndexOutOfBoundsException(offset);
226
- // }
227
- // if (count < 0) {
228
- // throw new StringIndexOutOfBoundsException(count);
229
- // }
230
- // // Note: offset or count might be near -1>>>1.
231
- // if (offset > value.length - count) {
232
- // throw new StringIndexOutOfBoundsException(offset + count);
233
- // }
222
+ if (offset < 0 ) {
223
+ throw new StringIndexOutOfBoundsException (offset );
224
+ }
225
+ if (count < 0 ) {
226
+ throw new StringIndexOutOfBoundsException (count );
227
+ }
228
+ // Note: offset or count might be near -1>>>1.
229
+ if (offset > value .length - count ) {
230
+ throw new StringIndexOutOfBoundsException (offset + count );
231
+ }
232
+ // DIFFBLUE MODEL LIBRARY Use CProverString function instead of array copy
233
+ this (CProverString .ofCharArray (value , offset , count ));
234
234
// this.value = Arrays.copyOfRange(value, offset, offset+count);
235
235
}
236
236
Original file line number Diff line number Diff line change @@ -388,4 +388,26 @@ public static StringBuffer insert(
388
388
return CProver .nondetWithoutNullForNotModelled ();
389
389
}
390
390
391
+ /**
392
+ * Converts an array of characters to a string. This uses a loop and
393
+ * therefore in test-generation the {@code count} will be limited by the
394
+ * unwind parameter.
395
+ * This assumes {@code value} is not null, its length is greater or equal to
396
+ * {@code offset + count} and {@code offset} and {@code count} are positive.
397
+ *
398
+ * @param value Array of characters which is the source to copy from
399
+ * @param offset Index in {@code value} of the first character to copy
400
+ * @param count Number of characters to copy
401
+ * @return The created String
402
+ */
403
+ public static String ofCharArray (char value [], int offset , int count ) {
404
+ org .cprover .CProver .assume (value != null );
405
+ org .cprover .CProver .assume (value .length - count >= offset
406
+ && offset >= 0 && count >= 0 );
407
+ StringBuilder builder = new StringBuilder ();
408
+ for (int i = 0 ; i < count ; i ++) {
409
+ builder .append (value [offset + i ]);
410
+ }
411
+ return builder .toString ();
412
+ }
391
413
}
You can’t perform that action at this time.
0 commit comments