@@ -3884,6 +3884,44 @@ public char[] toCharArray() {
3884
3884
return result ;
3885
3885
}
3886
3886
3887
+ /**
3888
+ * Helper function for the {@code format} function.
3889
+ * Serialize potential String.format argument to a String.
3890
+ * The returned String is never null.
3891
+ */
3892
+ static String cproverFormatArgument (Object obj ) {
3893
+ if (obj == null ) return "null" ;
3894
+ if (obj instanceof String ) return (String ) obj ;
3895
+
3896
+ // All primitive types are cast to a long
3897
+ long longValue = 0 ;
3898
+ if (obj instanceof Integer ) {
3899
+ longValue = (Integer ) obj ;
3900
+ } else if (obj instanceof Long ) {
3901
+ longValue = (Long ) obj ;
3902
+ } else if (obj instanceof Float ) {
3903
+ longValue = (long ) ((Float ) obj ).doubleValue ();
3904
+ } else if (obj instanceof Double ) {
3905
+ longValue = (long ) ((Double ) obj ).doubleValue ();
3906
+ } else if (obj instanceof Character ) {
3907
+ char charValue = (Character ) obj ;
3908
+ longValue = (long ) charValue ;
3909
+ } else if (obj instanceof Byte ) {
3910
+ byte byteValue = ((Byte ) obj );
3911
+ longValue = (long ) byteValue ;
3912
+ } else if (obj instanceof Boolean ) {
3913
+ longValue = ((Boolean ) obj ) ? 1 : 0 ;
3914
+ }
3915
+
3916
+ // The long value is encoded using a string of 4 characters
3917
+ StringBuilder builder = new StringBuilder ();
3918
+ builder .append ((char ) (longValue >> 48 & 0xFFFF ));
3919
+ builder .append ((char ) (longValue >> 32 & 0xFFFF ));
3920
+ builder .append ((char ) (longValue >> 16 & 0xFFFF ));
3921
+ builder .append ((char ) (longValue & 0xFFFF ));
3922
+ return builder .toString ();
3923
+ }
3924
+
3887
3925
/**
3888
3926
* Returns a formatted string using the specified format string and
3889
3927
* arguments.
@@ -3946,9 +3984,23 @@ public char[] toCharArray() {
3946
3984
* @diffblue.untested
3947
3985
*/
3948
3986
public static String format (String format , Object ... args ) {
3949
- // DIFFBLUE MODEL LIBRARY This is treated internally in CBMC
3950
- return CProver .nondetWithoutNullForNotModelled ();
3951
3987
// return new Formatter().format(format, args).toString();
3988
+ // DIFFBLUE MODEL LIBRARY
3989
+ if (args .length > 10 ) {
3990
+ return CProver .nondetWithoutNull ("" );
3991
+ }
3992
+ String arg0 = args .length > 0 ? cproverFormatArgument (args [0 ]) : "" ;
3993
+ String arg1 = args .length > 1 ? cproverFormatArgument (args [1 ]) : "" ;
3994
+ String arg2 = args .length > 2 ? cproverFormatArgument (args [2 ]) : "" ;
3995
+ String arg3 = args .length > 3 ? cproverFormatArgument (args [3 ]) : "" ;
3996
+ String arg4 = args .length > 4 ? cproverFormatArgument (args [4 ]) : "" ;
3997
+ String arg5 = args .length > 5 ? cproverFormatArgument (args [5 ]) : "" ;
3998
+ String arg6 = args .length > 6 ? cproverFormatArgument (args [6 ]) : "" ;
3999
+ String arg7 = args .length > 7 ? cproverFormatArgument (args [7 ]) : "" ;
4000
+ String arg8 = args .length > 8 ? cproverFormatArgument (args [8 ]) : "" ;
4001
+ String arg9 = args .length > 9 ? cproverFormatArgument (args [9 ]) : "" ;
4002
+ return CProverString
4003
+ .format (format , arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 , arg9 );
3952
4004
}
3953
4005
3954
4006
/**
@@ -3988,12 +4040,11 @@ public static String format(String format, Object... args) {
3988
4040
* @see java.util.Formatter
3989
4041
* @since 1.5
3990
4042
*
3991
- * @diffblue.noSupport
4043
+ * @diffblue.limitedSupport The locale argument is ignored
3992
4044
*/
3993
4045
public static String format (Locale l , String format , Object ... args ) {
3994
4046
// return new Formatter(l).format(format, args).toString();
3995
- CProver .notModelled ();
3996
- return CProver .nondetWithoutNullForNotModelled ();
4047
+ return format (format , args );
3997
4048
}
3998
4049
3999
4050
/**
0 commit comments