@@ -1244,124 +1244,118 @@ public static String formatStringF(String strFormat, String key, float floatT) {
12441244 return formatString (strFormat , key , null , floatT , Double .NaN , false );
12451245 }
12461246
1247+ public static String formatStringD (String strFormat , String key , double doubleT ) {
1248+ return formatString (strFormat , key , null , Float .NaN , doubleT , false );
1249+ }
1250+
12471251 public static String formatStringI (String strFormat , String key , int intT ) {
12481252 return formatString (strFormat , key , "" + intT , Float .NaN , Double .NaN , false );
12491253 }
12501254
1251- /**
1252- * sprintf emulation uses (almost) c++ standard string formats
1253- *
1254- * 's' string 'i' or 'd' integer, 'e' double, 'f' float, 'p' point3f, 'P' exponential point3f, 'q'
1255- * quaternion/plane/axisangle with added "i" (equal to the insipid "d" --
1256- * digits?)
1257- *
1258- * @param strFormat
1259- * @param list
1260- * a listing of what sort of data will be found in Object[] values, in
1261- * order: s string, f float, i integer, d double, p point3f, q
1262- * quaternion/point4f, S String[], F float[], I int[], and D double[]
1263- * @param values
1264- * Object[] containing above types
1265- * @return formatted string
1266- */
1267- public static String sprintf (String strFormat , String list , Object [] values ) {
1268- if (values == null )
1269- return strFormat ;
1270- int n = list .length ();
1271- if (n == values .length )
1272- try {
1273- for (int o = 0 ; o < n ; o ++) {
1274- if (values [o ] == null )
1275- continue ;
1276- char c ;
1277- switch (c = list .charAt (o )) {
1278- case 's' :
1279- strFormat = formatString (strFormat , "s" , (String ) values [o ],
1280- Float .NaN , Double .NaN , true );
1281- break ;
1282- case 'f' :
1283- strFormat = formatString (strFormat , "f" , null ,
1284- ((Float ) values [o ]).floatValue (), Double .NaN , true );
1285- break ;
1286- case 'i' :
1287- strFormat = formatString (strFormat , "d" , "" + values [o ], Float .NaN ,
1288- Double .NaN , true );
1289- strFormat = formatString (strFormat , "i" , "" + values [o ], Float .NaN ,
1290- Double .NaN , true );
1291- break ;
1292- case 'd' :
1293- strFormat = formatString (strFormat , "e" , null , Float .NaN ,
1294- ((Double ) values [o ]).doubleValue (), true );
1295- strFormat = formatString (strFormat , "f" , null , Float .NaN ,
1296- ((Double ) values [o ]).doubleValue (), true );
1297- break ;
1298- case 'p' :
1299- case 'P' :
1300- if (values [o ] instanceof T3 ) {
1301- T3 pVal = (T3 ) values [o ];
1302- strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , pVal .x , Double .NaN ,
1303- true );
1304- strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , pVal .y , Double .NaN ,
1305- true );
1306- strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , pVal .z , Double .NaN ,
1307- true );
1308- } else {
1309- T3d pVal = (T3d ) values [o ];
1310- strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , Float .NaN , pVal .x ,
1311- true );
1312- strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , Float .NaN , pVal .y ,
1313- true );
1314- strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , Float .NaN , pVal .z ,
1315- true );
1316- }
1317- break ;
1318- case 'q' :
1319- T4 qVal = (T4 ) values [o ];
1320- strFormat = formatString (strFormat , "q" , null , qVal .x , Double .NaN ,
1321- true );
1322- strFormat = formatString (strFormat , "q" , null , qVal .y , Double .NaN ,
1323- true );
1324- strFormat = formatString (strFormat , "q" , null , qVal .z , Double .NaN ,
1325- true );
1326- strFormat = formatString (strFormat , "q" , null , qVal .w , Double .NaN ,
1327- true );
1328- break ;
1329- case 'S' :
1330- String [] sVal = (String []) values [o ];
1331- for (int i = 0 ; i < sVal .length ; i ++)
1332- strFormat = formatString (strFormat , "s" , sVal [i ], Float .NaN ,
1333- Double .NaN , true );
1334- break ;
1335- case 'F' :
1336- float [] fVal = (float []) values [o ];
1337- for (int i = 0 ; i < fVal .length ; i ++)
1338- strFormat = formatString (strFormat , "f" , null , fVal [i ],
1339- Double .NaN , true );
1340- break ;
1341- case 'I' :
1342- int [] iVal = (int []) values [o ];
1343- for (int i = 0 ; i < iVal .length ; i ++)
1344- strFormat = formatString (strFormat , "d" , "" + iVal [i ], Float .NaN ,
1345- Double .NaN , true );
1346- for (int i = 0 ; i < iVal .length ; i ++)
1347- strFormat = formatString (strFormat , "i" , "" + iVal [i ], Float .NaN ,
1348- Double .NaN , true );
1349- break ;
1350- case 'D' :
1351- double [] dVal = (double []) values [o ];
1352- for (int i = 0 ; i < dVal .length ; i ++)
1353- strFormat = formatString (strFormat , "e" , null , Float .NaN , dVal [i ],
1354- true );
1355- }
1255+ /**
1256+ * sprintf emulation uses (almost) c++ standard string formats
1257+ *
1258+ * 's' string 'i' or 'd' integer, 'e' double, 'f' float, 'p' point3f, 'P'
1259+ * exponential point3f, 'q' quaternion/plane/axisangle with added "i" (equal to
1260+ * the insipid "d" -- digits?)
1261+ *
1262+ * @param strFormat
1263+ * @param list a listing of what sort of data will be found in Object[]
1264+ * values, in order: s string, f float, i integer, d double, p
1265+ * point3f, q quaternion/point4f, S String[], F float[], I
1266+ * int[], and D double[]
1267+ * @param values Object[] containing above types
1268+ * @return formatted string
1269+ */
1270+ public static String sprintf (String strFormat , String list , Object [] values ) {
1271+ if (values == null )
1272+ return strFormat ;
1273+ int n = list .length ();
1274+ if (n == values .length )
1275+ try {
1276+ for (int o = 0 ; o < n ; o ++) {
1277+ if (values [o ] == null )
1278+ continue ;
1279+ char c ;
1280+ switch (c = list .charAt (o )) {
1281+ case 's' :
1282+ strFormat = formatString (strFormat , "s" , (String ) values [o ], Float .NaN , Double .NaN , true );
1283+ break ;
1284+ case 'f' :
1285+ strFormat = formatString (strFormat , "f" , null , ((Float ) values [o ]).floatValue (), Double .NaN ,
1286+ true );
1287+ break ;
1288+ case 'i' :
1289+ strFormat = formatString (strFormat , "d" , "" + values [o ], Float .NaN , Double .NaN , true );
1290+ strFormat = formatString (strFormat , "i" , "" + values [o ], Float .NaN , Double .NaN , true );
1291+ break ;
1292+ case 'd' :
1293+ strFormat = formatString (strFormat , "e" , null , Float .NaN , ((Double ) values [o ]).doubleValue (),
1294+ true );
1295+ strFormat = formatString (strFormat , "f" , null , Float .NaN , ((Double ) values [o ]).doubleValue (),
1296+ true );
1297+ break ;
1298+ case 'p' :
1299+ case 'P' :
1300+ if (values [o ] instanceof T3 ) {
1301+ T3 pVal = (T3 ) values [o ];
1302+ strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , pVal .x , Double .NaN , true );
1303+ strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , pVal .y , Double .NaN , true );
1304+ strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , pVal .z , Double .NaN , true );
1305+ } else {
1306+ T3d pVal = (T3d ) values [o ];
1307+ strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , Float .NaN , pVal .x , true );
1308+ strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , Float .NaN , pVal .y , true );
1309+ strFormat = formatString (strFormat , (c == 'p' ? "p" : "P" ), null , Float .NaN , pVal .z , true );
1310+ }
1311+ break ;
1312+ case 'q' :
1313+ if (values [o ] instanceof T4 ) {
1314+ T4 qVal = (T4 ) values [o ];
1315+ strFormat = formatString (strFormat , "q" , null , qVal .x , Double .NaN , true );
1316+ strFormat = formatString (strFormat , "q" , null , qVal .y , Double .NaN , true );
1317+ strFormat = formatString (strFormat , "q" , null , qVal .z , Double .NaN , true );
1318+ strFormat = formatString (strFormat , "q" , null , qVal .w , Double .NaN , true );
1319+ } else {
1320+ T4d qVal = (T4d ) values [o ];
1321+ strFormat = formatString (strFormat , "q" , null , Float .NaN , qVal .x , true );
1322+ strFormat = formatString (strFormat , "q" , null , Float .NaN , qVal .y , true );
1323+ strFormat = formatString (strFormat , "q" , null , Float .NaN , qVal .z , true );
1324+ strFormat = formatString (strFormat , "q" , null , Float .NaN , qVal .w , true );
1325+ }
1326+ break ;
1327+
1328+ case 'S' :
1329+ String [] sVal = (String []) values [o ];
1330+ for (int i = 0 ; i < sVal .length ; i ++)
1331+ strFormat = formatString (strFormat , "s" , sVal [i ], Float .NaN , Double .NaN , true );
1332+ break ;
1333+ case 'F' :
1334+ float [] fVal = (float []) values [o ];
1335+ for (int i = 0 ; i < fVal .length ; i ++)
1336+ strFormat = formatString (strFormat , "f" , null , fVal [i ], Double .NaN , true );
1337+ break ;
1338+ case 'I' :
1339+ int [] iVal = (int []) values [o ];
1340+ for (int i = 0 ; i < iVal .length ; i ++)
1341+ strFormat = formatString (strFormat , "d" , "" + iVal [i ], Float .NaN , Double .NaN , true );
1342+ for (int i = 0 ; i < iVal .length ; i ++)
1343+ strFormat = formatString (strFormat , "i" , "" + iVal [i ], Float .NaN , Double .NaN , true );
1344+ break ;
1345+ case 'D' :
1346+ double [] dVal = (double []) values [o ];
1347+ for (int i = 0 ; i < dVal .length ; i ++)
1348+ strFormat = formatString (strFormat , "e" , null , Float .NaN , dVal [i ], true );
1349+ }
13561350
1357- }
1358- return rep (strFormat , "%%" , "%" );
1359- } catch (Exception e ) {
1360- //
1361- }
1362- System .out .println ("TextFormat.sprintf error " + list + " " + strFormat );
1363- return rep (strFormat , "%" , "?" );
1364- }
1351+ }
1352+ return rep (strFormat , "%%" , "%" );
1353+ } catch (Exception e ) {
1354+ //
1355+ }
1356+ System .out .println ("TextFormat.sprintf error " + list + " " + strFormat );
1357+ return rep (strFormat , "%" , "?" );
1358+ }
13651359
13661360 /**
13671361 *
0 commit comments