1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.util;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 import java.text.DecimalFormatSymbols;
49 import java.util.Enumeration;
50 import java.util.Locale;
51 import java.util.Vector;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460 public class PrintfFormat {
461
462
463
464
465
466
467
468
469
470
471
472
473 public PrintfFormat(String fmtArg) throws IllegalArgumentException {
474 this(Locale.getDefault(), fmtArg);
475 }
476
477
478
479
480
481
482
483
484
485
486
487
488 public PrintfFormat(Locale locale, String fmtArg) throws IllegalArgumentException {
489 dfs = new DecimalFormatSymbols(locale);
490 int ePos = 0;
491 ConversionSpecification sFmt = null;
492 String unCS = this.nonControl(fmtArg, 0);
493 if (unCS != null) {
494 sFmt = new ConversionSpecification();
495 sFmt.setLiteral(unCS);
496 vFmt.addElement(sFmt);
497 }
498 while (cPos != -1 && cPos < fmtArg.length()) {
499 for (ePos = cPos + 1; ePos < fmtArg.length(); ePos++) {
500 char c = 0;
501 c = fmtArg.charAt(ePos);
502 if (c == 'i')
503 break;
504 if (c == 'd')
505 break;
506 if (c == 'f')
507 break;
508 if (c == 'g')
509 break;
510 if (c == 'G')
511 break;
512 if (c == 'o')
513 break;
514 if (c == 'x')
515 break;
516 if (c == 'X')
517 break;
518 if (c == 'e')
519 break;
520 if (c == 'E')
521 break;
522 if (c == 'c')
523 break;
524 if (c == 's')
525 break;
526 if (c == '%')
527 break;
528 }
529 ePos = Math.min(ePos + 1, fmtArg.length());
530
531
532
533
534 if (ePos < fmtArg.length() && ( fmtArg.charAt(ePos-1)=='e' || fmtArg.charAt(ePos-1)=='E')) {
535 if (Character.isDigit(fmtArg.charAt(ePos))) {
536 ePos++;
537 }
538 }
539
540
541 sFmt = new ConversionSpecification(fmtArg.substring(cPos, ePos));
542 vFmt.addElement(sFmt);
543 unCS = this.nonControl(fmtArg, ePos);
544 if (unCS != null) {
545 sFmt = new ConversionSpecification();
546 sFmt.setLiteral(unCS);
547 vFmt.addElement(sFmt);
548 }
549 }
550 }
551
552
553
554
555
556
557
558
559
560
561
562
563
564 private String nonControl(String s, int start) {
565
566 cPos = s.indexOf("%", start);
567 if (cPos == -1)
568 cPos = s.length();
569 return s.substring(start, cPos);
570 }
571
572
573
574
575
576
577
578
579 public String sprintf(Object[] o) {
580 Enumeration e = vFmt.elements();
581 ConversionSpecification cs = null;
582 char c = 0;
583 int i = 0;
584 StringBuffer sb = new StringBuffer();
585 while (e.hasMoreElements()) {
586 cs = (ConversionSpecification) e.nextElement();
587 c = cs.getConversionCharacter();
588 if (c == '\0')
589 sb.append(cs.getLiteral());
590 else if (c == '%')
591 sb.append("%");
592 else {
593 if (cs.isPositionalSpecification()) {
594 i = cs.getArgumentPosition() - 1;
595 if (cs.isPositionalFieldWidth()) {
596 int ifw = cs.getArgumentPositionForFieldWidth() - 1;
597 cs.setFieldWidthWithArg(((Integer) o[ifw]).intValue());
598 }
599 if (cs.isPositionalPrecision()) {
600 int ipr = cs.getArgumentPositionForPrecision() - 1;
601 cs.setPrecisionWithArg(((Integer) o[ipr]).intValue());
602 }
603 } else {
604 if (cs.isVariableFieldWidth()) {
605 cs.setFieldWidthWithArg(((Integer) o[i]).intValue());
606 i++;
607 }
608 if (cs.isVariablePrecision()) {
609 cs.setPrecisionWithArg(((Integer) o[i]).intValue());
610 i++;
611 }
612 }
613 if (o[i] instanceof Byte)
614 sb.append(cs.internalsprintf(((Byte) o[i]).byteValue()));
615 else if (o[i] instanceof Short)
616 sb.append(cs.internalsprintf(((Short) o[i]).shortValue()));
617 else if (o[i] instanceof Integer)
618 sb.append(cs.internalsprintf(((Integer) o[i]).intValue()));
619 else if (o[i] instanceof Long)
620 sb.append(cs.internalsprintf(((Long) o[i]).longValue()));
621 else if (o[i] instanceof Float)
622 sb.append(cs.internalsprintf(((Float) o[i]).floatValue()));
623 else if (o[i] instanceof Double)
624 sb.append(cs.internalsprintf(((Double) o[i]).doubleValue()));
625 else if (o[i] instanceof Character)
626 sb.append(cs.internalsprintf(((Character) o[i]).charValue()));
627 else if (o[i] instanceof String)
628 sb.append(cs.internalsprintf((String) o[i]));
629 else
630 sb.append(cs.internalsprintf(o[i]));
631 if (!cs.isPositionalSpecification())
632 i++;
633 }
634 }
635 return sb.toString();
636 }
637
638
639
640
641 public String sprintf() {
642 Enumeration e = vFmt.elements();
643 ConversionSpecification cs = null;
644 char c = 0;
645 StringBuffer sb = new StringBuffer();
646 while (e.hasMoreElements()) {
647 cs = (ConversionSpecification) e.nextElement();
648 c = cs.getConversionCharacter();
649 if (c == '\0')
650 sb.append(cs.getLiteral());
651 else if (c == '%')
652 sb.append("%");
653 }
654 return sb.toString();
655 }
656
657
658
659
660
661
662
663
664 public String sprintf(int x) throws IllegalArgumentException {
665 Enumeration e = vFmt.elements();
666 ConversionSpecification cs = null;
667 char c = 0;
668 StringBuffer sb = new StringBuffer();
669 while (e.hasMoreElements()) {
670 cs = (ConversionSpecification) e.nextElement();
671 c = cs.getConversionCharacter();
672 if (c == '\0')
673 sb.append(cs.getLiteral());
674 else if (c == '%')
675 sb.append("%");
676 else
677 sb.append(cs.internalsprintf(x));
678 }
679 return sb.toString();
680 }
681
682
683
684
685
686
687
688
689 public String sprintf(long x) throws IllegalArgumentException {
690 Enumeration e = vFmt.elements();
691 ConversionSpecification cs = null;
692 char c = 0;
693 StringBuffer sb = new StringBuffer();
694 while (e.hasMoreElements()) {
695 cs = (ConversionSpecification) e.nextElement();
696 c = cs.getConversionCharacter();
697 if (c == '\0')
698 sb.append(cs.getLiteral());
699 else if (c == '%')
700 sb.append("%");
701 else
702 sb.append(cs.internalsprintf(x));
703 }
704 return sb.toString();
705 }
706
707
708
709
710
711
712
713
714 public String sprintf(double x) throws IllegalArgumentException {
715 Enumeration e = vFmt.elements();
716 ConversionSpecification cs = null;
717 char c = 0;
718 StringBuffer sb = new StringBuffer();
719 while (e.hasMoreElements()) {
720 cs = (ConversionSpecification) e.nextElement();
721 c = cs.getConversionCharacter();
722 if (c == '\0')
723 sb.append(cs.getLiteral());
724 else if (c == '%')
725 sb.append("%");
726 else
727 sb.append(cs.internalsprintf(x));
728 }
729 return sb.toString();
730 }
731
732
733
734
735
736
737
738 public String sprintf(String x) throws IllegalArgumentException {
739 Enumeration e = vFmt.elements();
740 ConversionSpecification cs = null;
741 char c = 0;
742 StringBuffer sb = new StringBuffer();
743 while (e.hasMoreElements()) {
744 cs = (ConversionSpecification) e.nextElement();
745 c = cs.getConversionCharacter();
746 if (c == '\0')
747 sb.append(cs.getLiteral());
748 else if (c == '%')
749 sb.append("%");
750 else
751 sb.append(cs.internalsprintf(x));
752 }
753 return sb.toString();
754 }
755
756
757
758
759
760
761
762
763
764
765
766
767
768 public String sprintf(Object x) throws IllegalArgumentException {
769 Enumeration e = vFmt.elements();
770 ConversionSpecification cs = null;
771 char c = 0;
772 StringBuffer sb = new StringBuffer();
773 while (e.hasMoreElements()) {
774 cs = (ConversionSpecification) e.nextElement();
775 c = cs.getConversionCharacter();
776 if (c == '\0')
777 sb.append(cs.getLiteral());
778 else if (c == '%')
779 sb.append("%");
780 else {
781 if (x instanceof Byte)
782 sb.append(cs.internalsprintf(((Byte) x).byteValue()));
783 else if (x instanceof Short)
784 sb.append(cs.internalsprintf(((Short) x).shortValue()));
785 else if (x instanceof Integer)
786 sb.append(cs.internalsprintf(((Integer) x).intValue()));
787 else if (x instanceof Long)
788 sb.append(cs.internalsprintf(((Long) x).longValue()));
789 else if (x instanceof Float)
790 sb.append(cs.internalsprintf(((Float) x).floatValue()));
791 else if (x instanceof Double)
792 sb.append(cs.internalsprintf(((Double) x).doubleValue()));
793 else if (x instanceof Character)
794 sb.append(cs.internalsprintf(((Character) x).charValue()));
795 else if (x instanceof String)
796 sb.append(cs.internalsprintf((String) x));
797 else
798 sb.append(cs.internalsprintf(x));
799 }
800 }
801 return sb.toString();
802 }
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836 private class ConversionSpecification {
837
838
839
840
841 ConversionSpecification() {
842 }
843
844
845
846
847
848
849
850
851
852
853
854 ConversionSpecification(String fmtArg) throws IllegalArgumentException {
855 if (fmtArg == null)
856 throw new NullPointerException();
857 if (fmtArg.length() == 0)
858 throw new IllegalArgumentException("Control strings must have positive" + " lengths.");
859 if (fmtArg.charAt(0) == '%') {
860 fmt = fmtArg;
861 pos = 1;
862 setArgPosition();
863 setFlagCharacters();
864 setFieldWidth();
865 setPrecision();
866 setOptionalHL();
867 if (setConversionCharacter()) {
868 setPrecisionE();
869 if (pos == fmtArg.length()) {
870 if (leadingZeros && leftJustify)
871 leadingZeros = false;
872 if (precisionSet && leadingZeros) {
873 if (conversionCharacter == 'd'
874 || conversionCharacter == 'i'
875 || conversionCharacter == 'o'
876 || conversionCharacter == 'x') {
877 leadingZeros = false;
878 }
879 }
880 } else
881 throw new IllegalArgumentException("Malformed conversion specification=" + fmtArg);
882 } else
883 throw new IllegalArgumentException("Malformed conversion specification=" + fmtArg);
884 } else
885 throw new IllegalArgumentException("Control strings must begin with %.");
886 }
887
888
889
890
891 void setLiteral(String s) {
892 fmt = s;
893 }
894
895
896
897
898
899
900 String getLiteral() {
901 StringBuffer sb = new StringBuffer();
902 int i = 0;
903 while (i < fmt.length()) {
904 if (fmt.charAt(i) == '\\') {
905 i++;
906 if (i < fmt.length()) {
907 char c = fmt.charAt(i);
908 switch (c) {
909 case 'a' :
910 sb.append((char) 0x07);
911 break;
912 case 'b' :
913 sb.append('\b');
914 break;
915 case 'f' :
916 sb.append('\f');
917 break;
918 case 'n' :
919 sb.append(System.getProperty("line.separator"));
920 break;
921 case 'r' :
922 sb.append('\r');
923 break;
924 case 't' :
925 sb.append('\t');
926 break;
927 case 'v' :
928 sb.append((char) 0x0b);
929 break;
930 case '\\' :
931 sb.append('\\');
932 break;
933 }
934 i++;
935 } else
936 sb.append('\\');
937 } else
938 i++;
939 }
940 return fmt;
941 }
942
943
944
945
946
947
948 char getConversionCharacter() {
949 return conversionCharacter;
950 }
951
952
953
954
955
956
957
958
959 boolean isVariableFieldWidth() {
960 return variableFieldWidth;
961 }
962
963
964
965
966
967
968 void setFieldWidthWithArg(int fw) {
969 if (fw < 0)
970 leftJustify = true;
971 fieldWidthSet = true;
972 fieldWidth = Math.abs(fw);
973 }
974
975
976
977
978
979
980
981
982 boolean isVariablePrecision() {
983 return variablePrecision;
984 }
985
986
987
988
989
990 void setPrecisionWithArg(int pr) {
991 precisionSet = true;
992 precision = Math.max(pr, 0);
993 }
994
995
996
997
998
999
1000
1001
1002 String internalsprintf(int s) throws IllegalArgumentException {
1003 String s2 = "";
1004 switch (conversionCharacter) {
1005 case 'd' :
1006 case 'i' :
1007 if (optionalh)
1008 s2 = printDFormat((short) s);
1009 else if (optionall)
1010 s2 = printDFormat((long) s);
1011 else
1012 s2 = printDFormat(s);
1013 break;
1014 case 'x' :
1015 case 'X' :
1016 if (optionalh)
1017 s2 = printXFormat((short) s);
1018 else if (optionall)
1019 s2 = printXFormat((long) s);
1020 else
1021 s2 = printXFormat(s);
1022 break;
1023 case 'o' :
1024 if (optionalh)
1025 s2 = printOFormat((short) s);
1026 else if (optionall)
1027 s2 = printOFormat((long) s);
1028 else
1029 s2 = printOFormat(s);
1030 break;
1031 case 'c' :
1032 case 'C' :
1033 s2 = printCFormat((char) s);
1034 break;
1035 default :
1036 throw new IllegalArgumentException(
1037 "Cannot format a int with a format using a " + conversionCharacter + " conversion character.");
1038 }
1039 return s2;
1040 }
1041
1042
1043
1044
1045
1046
1047
1048
1049 String internalsprintf(long s) throws IllegalArgumentException {
1050 String s2 = "";
1051 switch (conversionCharacter) {
1052 case 'd' :
1053 case 'i' :
1054 if (optionalh)
1055 s2 = printDFormat((short) s);
1056 else if (optionall)
1057 s2 = printDFormat(s);
1058 else
1059 s2 = printDFormat((int) s);
1060 break;
1061 case 'x' :
1062 case 'X' :
1063 if (optionalh)
1064 s2 = printXFormat((short) s);
1065 else if (optionall)
1066 s2 = printXFormat(s);
1067 else
1068 s2 = printXFormat((int) s);
1069 break;
1070 case 'o' :
1071 if (optionalh)
1072 s2 = printOFormat((short) s);
1073 else if (optionall)
1074 s2 = printOFormat(s);
1075 else
1076 s2 = printOFormat((int) s);
1077 break;
1078 case 'c' :
1079 case 'C' :
1080 s2 = printCFormat((char) s);
1081 break;
1082 default :
1083 throw new IllegalArgumentException(
1084 "Cannot format a long with a format using a " + conversionCharacter + " conversion character.");
1085 }
1086 return s2;
1087 }
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097 String internalsprintf(double s) throws IllegalArgumentException {
1098 String s2 = "";
1099 switch (conversionCharacter) {
1100 case 'f' :
1101 s2 = printFFormat(s);
1102 break;
1103 case 'E' :
1104 case 'e' :
1105 s2 = printEFormat(s);
1106 break;
1107 case 'G' :
1108 case 'g' :
1109 s2 = printGFormat(s);
1110 break;
1111 case 'D' :
1112 case 'd' :
1113 s2 = printDFormat(Math.round(s));
1114 break;
1115 default :
1116 throw new IllegalArgumentException(
1117 "Cannot "
1118 + "format a double with a format using a "
1119 + conversionCharacter
1120 + " conversion character.");
1121 }
1122 return s2;
1123 }
1124
1125
1126
1127
1128
1129
1130
1131
1132 String internalsprintf(String s) throws IllegalArgumentException {
1133 String s2 = "";
1134 if (conversionCharacter == 's' || conversionCharacter == 'S')
1135 s2 = printSFormat(s);
1136 else
1137 throw new IllegalArgumentException(
1138 "Cannot "
1139 + "format a String with a format using a "
1140 + conversionCharacter
1141 + " conversion character.");
1142 return s2;
1143 }
1144
1145
1146
1147
1148
1149
1150
1151
1152 String internalsprintf(Object s) {
1153 String s2 = "";
1154 if (conversionCharacter == 's' || conversionCharacter == 'S')
1155 s2 = printSFormat(s.toString());
1156 else
1157 throw new IllegalArgumentException(
1158 "Cannot format a String with a format using"
1159 + " a "
1160 + conversionCharacter
1161 + " conversion character.");
1162 return s2;
1163 }
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186 private char[] fFormatDigits(double x) {
1187
1188 String sx;
1189 int i, j, k;
1190 int n1In, n2In;
1191 int expon = 0;
1192 boolean minusSign = false;
1193 if (x > 0.0)
1194 sx = Double.toString(x);
1195 else if (x < 0.0) {
1196 sx = Double.toString(-x);
1197 minusSign = true;
1198 } else {
1199 sx = Double.toString(x);
1200 if (sx.charAt(0) == '-') {
1201 minusSign = true;
1202 sx = sx.substring(1);
1203 }
1204 }
1205 int ePos = sx.indexOf('E');
1206 int rPos = sx.indexOf('.');
1207 if (rPos != -1)
1208 n1In = rPos;
1209 else if (ePos != -1)
1210 n1In = ePos;
1211 else
1212 n1In = sx.length();
1213 if (rPos != -1) {
1214 if (ePos != -1)
1215 n2In = ePos - rPos - 1;
1216 else
1217 n2In = sx.length() - rPos - 1;
1218 } else
1219 n2In = 0;
1220 if (ePos != -1) {
1221 int ie = ePos + 1;
1222 expon = 0;
1223 if (sx.charAt(ie) == '-') {
1224 for (++ie; ie < sx.length(); ie++)
1225 if (sx.charAt(ie) != '0')
1226 break;
1227 if (ie < sx.length())
1228 expon = -Integer.parseInt(sx.substring(ie));
1229 } else {
1230 if (sx.charAt(ie) == '+')
1231 ++ie;
1232 for (; ie < sx.length(); ie++)
1233 if (sx.charAt(ie) != '0')
1234 break;
1235 if (ie < sx.length())
1236 expon = Integer.parseInt(sx.substring(ie));
1237 }
1238 }
1239 int p;
1240 if (precisionSet)
1241 p = precision;
1242 else
1243 p = defaultDigits - 1;
1244 char[] ca1 = sx.toCharArray();
1245 char[] ca2 = new char[n1In + n2In];
1246 char[] ca3, ca4, ca5;
1247 for (j = 0; j < n1In; j++)
1248 ca2[j] = ca1[j];
1249 i = j + 1;
1250 for (k = 0; k < n2In; j++, i++, k++)
1251 ca2[j] = ca1[i];
1252 if (n1In + expon <= 0) {
1253 ca3 = new char[-expon + n2In];
1254 for (j = 0, k = 0; k < (-n1In - expon); k++, j++)
1255 ca3[j] = '0';
1256 for (i = 0; i < (n1In + n2In); i++, j++)
1257 ca3[j] = ca2[i];
1258 } else
1259 ca3 = ca2;
1260 boolean carry = false;
1261 if (p < -expon + n2In) {
1262 if (expon < 0)
1263 i = p;
1264 else
1265 i = p + n1In;
1266 carry = checkForCarry(ca3, i);
1267 if (carry)
1268 carry = startSymbolicCarry(ca3, i - 1, 0);
1269 }
1270 if (n1In + expon <= 0) {
1271 ca4 = new char[2 + p];
1272 if (!carry)
1273 ca4[0] = '0';
1274 else
1275 ca4[0] = '1';
1276 if (alternateForm || !precisionSet || precision != 0) {
1277 ca4[1] = '.';
1278 for (i = 0, j = 2; i < Math.min(p, ca3.length); i++, j++)
1279 ca4[j] = ca3[i];
1280 for (; j < ca4.length; j++)
1281 ca4[j] = '0';
1282 }
1283 } else {
1284 if (!carry) {
1285 if (alternateForm || !precisionSet || precision != 0)
1286 ca4 = new char[n1In + expon + p + 1];
1287 else
1288 ca4 = new char[n1In + expon];
1289 j = 0;
1290 } else {
1291 if (alternateForm || !precisionSet || precision != 0)
1292 ca4 = new char[n1In + expon + p + 2];
1293 else
1294 ca4 = new char[n1In + expon + 1];
1295 ca4[0] = '1';
1296 j = 1;
1297 }
1298 for (i = 0; i < Math.min(n1In + expon, ca3.length); i++, j++)
1299 ca4[j] = ca3[i];
1300 for (; i < n1In + expon; i++, j++)
1301 ca4[j] = '0';
1302 if (alternateForm || !precisionSet || precision != 0) {
1303 ca4[j] = '.';
1304 j++;
1305 for (k = 0; i < ca3.length && k < p; i++, j++, k++)
1306 ca4[j] = ca3[i];
1307 for (; j < ca4.length; j++)
1308 ca4[j] = '0';
1309 }
1310 }
1311 int nZeros = 0;
1312 if (!leftJustify && leadingZeros) {
1313 int xThousands = 0;
1314 if (thousands) {
1315 int xlead = 0;
1316 if (ca4[0] == '+' || ca4[0] == '-' || ca4[0] == ' ')
1317 xlead = 1;
1318 int xdp = xlead;
1319 for (; xdp < ca4.length; xdp++)
1320 if (ca4[xdp] == '.')
1321 break;
1322 xThousands = (xdp - xlead) / 3;
1323 }
1324 if (fieldWidthSet)
1325 nZeros = fieldWidth - ca4.length;
1326 if ((!minusSign && (leadingSign || leadingSpace)) || minusSign)
1327 nZeros--;
1328 nZeros -= xThousands;
1329 if (nZeros < 0)
1330 nZeros = 0;
1331 }
1332 j = 0;
1333 if ((!minusSign && (leadingSign || leadingSpace)) || minusSign) {
1334 ca5 = new char[ca4.length + nZeros + 1];
1335 j++;
1336 } else
1337 ca5 = new char[ca4.length + nZeros];
1338 if (!minusSign) {
1339 if (leadingSign)
1340 ca5[0] = '+';
1341 if (leadingSpace)
1342 ca5[0] = ' ';
1343 } else
1344 ca5[0] = '-';
1345 for (i = 0; i < nZeros; i++, j++)
1346 ca5[j] = '0';
1347 for (i = 0; i < ca4.length; i++, j++)
1348 ca5[j] = ca4[i];
1349
1350 int lead = 0;
1351 if (ca5[0] == '+' || ca5[0] == '-' || ca5[0] == ' ')
1352 lead = 1;
1353 int dp = lead;
1354 for (; dp < ca5.length; dp++)
1355 if (ca5[dp] == '.')
1356 break;
1357 int nThousands = (dp - lead) / 3;
1358
1359 if (dp < ca5.length)
1360 ca5[dp] = dfs.getDecimalSeparator();
1361 char[] ca6 = ca5;
1362 if (thousands && nThousands > 0) {
1363 ca6 = new char[ca5.length + nThousands + lead];
1364 ca6[0] = ca5[0];
1365 for (i = lead, k = lead; i < dp; i++) {
1366 if (i > 0 && (dp - i) % 3 == 0) {
1367
1368 ca6[k] = dfs.getGroupingSeparator();
1369 ca6[k + 1] = ca5[i];
1370 k += 2;
1371 } else {
1372 ca6[k] = ca5[i];
1373 k++;
1374 }
1375 }
1376 for (; i < ca5.length; i++, k++) {
1377 ca6[k] = ca5[i];
1378 }
1379 }
1380 return ca6;
1381 }
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391 private String fFormatString(double x) {
1392
1393 char[] ca6, ca7;
1394 if (Double.isInfinite(x)) {
1395 if (x == Double.POSITIVE_INFINITY) {
1396 if (leadingSign)
1397 ca6 = "+Inf".toCharArray();
1398 else if (leadingSpace)
1399 ca6 = " Inf".toCharArray();
1400 else
1401 ca6 = "Inf".toCharArray();
1402 } else
1403 ca6 = "-Inf".toCharArray();
1404
1405 } else if (Double.isNaN(x)) {
1406 if (leadingSign)
1407 ca6 = "+NaN".toCharArray();
1408 else if (leadingSpace)
1409 ca6 = " NaN".toCharArray();
1410 else
1411 ca6 = "NaN".toCharArray();
1412
1413 } else
1414 ca6 = fFormatDigits(x);
1415 ca7 = applyFloatPadding(ca6, false);
1416 return new String(ca7);
1417 }
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448 private char[] eFormatDigits(double x, char eChar) {
1449 char[] ca1, ca2, ca3;
1450
1451 String sx;
1452 int i, j, k, p;
1453
1454 int expon = 0;
1455 int ePos, rPos, eSize;
1456 boolean minusSign = false;
1457 if (x > 0.0)
1458 sx = Double.toString(x);
1459 else if (x < 0.0) {
1460 sx = Double.toString(-x);
1461 minusSign = true;
1462 } else {
1463 sx = Double.toString(x);
1464 if (sx.charAt(0) == '-') {
1465 minusSign = true;
1466 sx = sx.substring(1);
1467 }
1468 }
1469 ePos = sx.indexOf('E');
1470 if (ePos == -1)
1471 ePos = sx.indexOf('e');
1472 rPos = sx.indexOf('.');
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489 if (ePos != -1) {
1490 int ie = ePos + 1;
1491 expon = 0;
1492 if (sx.charAt(ie) == '-') {
1493 for (++ie; ie < sx.length(); ie++)
1494 if (sx.charAt(ie) != '0')
1495 break;
1496 if (ie < sx.length())
1497 expon = -Integer.parseInt(sx.substring(ie));
1498 } else {
1499 if (sx.charAt(ie) == '+')
1500 ++ie;
1501 for (; ie < sx.length(); ie++)
1502 if (sx.charAt(ie) != '0')
1503 break;
1504 if (ie < sx.length())
1505 expon = Integer.parseInt(sx.substring(ie));
1506 }
1507 }
1508 if (rPos != -1)
1509 expon += rPos - 1;
1510 if (precisionSet)
1511 p = precision;
1512 else
1513 p = defaultDigits - 1;
1514 if (rPos != -1 && ePos != -1)
1515 ca1 = (sx.substring(0, rPos) + sx.substring(rPos + 1, ePos)).toCharArray();
1516 else if (rPos != -1)
1517 ca1 = (sx.substring(0, rPos) + sx.substring(rPos + 1)).toCharArray();
1518 else if (ePos != -1)
1519 ca1 = sx.substring(0, ePos).toCharArray();
1520 else
1521 ca1 = sx.toCharArray();
1522 boolean carry = false;
1523 int i0 = 0;
1524 if (ca1[0] != '0')
1525 i0 = 0;
1526 else
1527 for (i0 = 0; i0 < ca1.length; i0++)
1528 if (ca1[i0] != '0')
1529 break;
1530 if (i0 + p < ca1.length - 1) {
1531 carry = checkForCarry(ca1, i0 + p + 1);
1532 if (carry)
1533 carry = startSymbolicCarry(ca1, i0 + p, i0);
1534 if (carry) {
1535 ca2 = new char[i0 + p + 1];
1536 ca2[i0] = '1';
1537 for (j = 0; j < i0; j++)
1538 ca2[j] = '0';
1539 for (i = i0, j = i0 + 1; j < p + 1; i++, j++)
1540 ca2[j] = ca1[i];
1541 expon++;
1542 ca1 = ca2;
1543 }
1544 }
1545 if (Math.abs(expon) < 10 && !optionalL) {
1546
1547 eSize= precisionE + 2;
1548 } else
1549 if (Math.abs(expon) < 100 && !optionalL && precisionE>1) {
1550
1551
1552 eSize= precisionE + 2;
1553 } else
1554 eSize = 5;
1555 if (alternateForm || !precisionSet || precision != 0)
1556 ca2 = new char[2 + p + eSize];
1557 else
1558 ca2 = new char[1 + eSize];
1559 if (ca1[0] != '0') {
1560 ca2[0] = ca1[0];
1561 j = 1;
1562 } else {
1563 for (j = 1; j < (ePos == -1 ? ca1.length : ePos); j++)
1564 if (ca1[j] != '0')
1565 break;
1566 if ((ePos != -1 && j < ePos) || (ePos == -1 && j < ca1.length)) {
1567 ca2[0] = ca1[j];
1568 expon -= j;
1569 j++;
1570 } else {
1571 ca2[0] = '0';
1572 j = 2;
1573 }
1574 }
1575 if (alternateForm || !precisionSet || precision != 0) {
1576 ca2[1] = '.';
1577 i = 2;
1578 } else
1579 i = 1;
1580 for (k = 0; k < p && j < ca1.length; j++, i++, k++)
1581 ca2[i] = ca1[j];
1582 for (; i < ca2.length - eSize; i++)
1583 ca2[i] = '0';
1584 ca2[i++] = eChar;
1585 if (expon < 0)
1586 ca2[i++] = '-';
1587 else
1588 ca2[i++] = '+';
1589 expon = Math.abs(expon);
1590 if (eSize==5) {
1591 switch (expon / 100) {
1592 case 0 :
1593 ca2[i] = '0';
1594 break;
1595 case 1 :
1596 ca2[i] = '1';
1597 break;
1598 case 2 :
1599 ca2[i] = '2';
1600 break;
1601 case 3 :
1602 ca2[i] = '3';
1603 break;
1604 case 4 :
1605 ca2[i] = '4';
1606 break;
1607 case 5 :
1608 ca2[i] = '5';
1609 break;
1610 case 6 :
1611 ca2[i] = '6';
1612 break;
1613 case 7 :
1614 ca2[i] = '7';
1615 break;
1616 case 8 :
1617 ca2[i] = '8';
1618 break;
1619 case 9 :
1620 ca2[i] = '9';
1621 break;
1622 }
1623 i++;
1624 }
1625 if (eSize>=4) {
1626 switch ((expon % 100) / 10) {
1627 case 0 :
1628 ca2[i] = '0';
1629 break;
1630 case 1 :
1631 ca2[i] = '1';
1632 break;
1633 case 2 :
1634 ca2[i] = '2';
1635 break;
1636 case 3 :
1637 ca2[i] = '3';
1638 break;
1639 case 4 :
1640 ca2[i] = '4';
1641 break;
1642 case 5 :
1643 ca2[i] = '5';
1644 break;
1645 case 6 :
1646 ca2[i] = '6';
1647 break;
1648 case 7 :
1649 ca2[i] = '7';
1650 break;
1651 case 8 :
1652 ca2[i] = '8';
1653 break;
1654 case 9 :
1655 ca2[i] = '9';
1656 break;
1657 }
1658 i++;
1659 }
1660 switch (expon % 10) {
1661 case 0 :
1662 ca2[i] = '0';
1663 break;
1664 case 1 :
1665 ca2[i] = '1';
1666 break;
1667 case 2 :
1668 ca2[i] = '2';
1669 break;
1670 case 3 :
1671 ca2[i] = '3';
1672 break;
1673 case 4 :
1674 ca2[i] = '4';
1675 break;
1676 case 5 :
1677 ca2[i] = '5';
1678 break;
1679 case 6 :
1680 ca2[i] = '6';
1681 break;
1682 case 7 :
1683 ca2[i] = '7';
1684 break;
1685 case 8 :
1686 ca2[i] = '8';
1687 break;
1688 case 9 :
1689 ca2[i] = '9';
1690 break;
1691 }
1692 int nZeros = 0;
1693 if (!leftJustify && leadingZeros) {
1694 int xThousands = 0;
1695 if (thousands) {
1696 int xlead = 0;
1697 if (ca2[0] == '+' || ca2[0] == '-' || ca2[0] == ' ')
1698 xlead = 1;
1699 int xdp = xlead;
1700 for (; xdp < ca2.length; xdp++)
1701 if (ca2[xdp] == '.')
1702 break;
1703 xThousands = (xdp - xlead) / 3;
1704 }
1705 if (fieldWidthSet)
1706 nZeros = fieldWidth - ca2.length;
1707 if ((!minusSign && (leadingSign || leadingSpace)) || minusSign)
1708 nZeros--;
1709 nZeros -= xThousands;
1710 if (nZeros < 0)
1711 nZeros = 0;
1712 }
1713 j = 0;
1714 if ((!minusSign && (leadingSign || leadingSpace)) || minusSign) {
1715 ca3 = new char[ca2.length + nZeros + 1];
1716 j++;
1717 } else
1718 ca3 = new char[ca2.length + nZeros];
1719 if (!minusSign) {
1720 if (leadingSign)
1721 ca3[0] = '+';
1722 if (leadingSpace)
1723 ca3[0] = ' ';
1724 } else
1725 ca3[0] = '-';
1726 for (k = 0; k < nZeros; j++, k++)
1727 ca3[j] = '0';
1728 for (i = 0; i < ca2.length && j < ca3.length; i++, j++)
1729 ca3[j] = ca2[i];
1730
1731 int lead = 0;
1732 if (ca3[0] == '+' || ca3[0] == '-' || ca3[0] == ' ')
1733 lead = 1;
1734 int dp = lead;
1735 for (; dp < ca3.length; dp++)
1736 if (ca3[dp] == '.')
1737 break;
1738 int nThousands = dp / 3;
1739
1740 if (dp < ca3.length)
1741 ca3[dp] = dfs.getDecimalSeparator();
1742 char[] ca4 = ca3;
1743 if (thousands && nThousands > 0) {
1744 ca4 = new char[ca3.length + nThousands + lead];
1745 ca4[0] = ca3[0];
1746 for (i = lead, k = lead; i < dp; i++) {
1747 if (i > 0 && (dp - i) % 3 == 0) {
1748
1749 ca4[k] = dfs.getGroupingSeparator();
1750 ca4[k + 1] = ca3[i];
1751 k += 2;
1752 } else {
1753 ca4[k] = ca3[i];
1754 k++;
1755 }
1756 }
1757 for (; i < ca3.length; i++, k++)
1758 ca4[k] = ca3[i];
1759 }
1760 return ca4;
1761 }
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772 private boolean checkForCarry(char[] ca1, int icarry) {
1773 boolean carry = false;
1774 if (icarry < ca1.length) {
1775 if (ca1[icarry] == '6' || ca1[icarry] == '7' || ca1[icarry] == '8' || ca1[icarry] == '9')
1776 carry = true;
1777 else if (ca1[icarry] == '5') {
1778 int ii = icarry + 1;
1779 for (; ii < ca1.length; ii++)
1780 if (ca1[ii] != '0')
1781 break;
1782 carry = ii < ca1.length;
1783 if (!carry && icarry > 0) {
1784 carry =
1785 (ca1[icarry - 1] == '1'
1786 || ca1[icarry - 1] == '3'
1787 || ca1[icarry - 1] == '5'
1788 || ca1[icarry - 1] == '7'
1789 || ca1[icarry - 1] == '9');
1790 }
1791 }
1792 }
1793 return carry;
1794 }
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808 private boolean startSymbolicCarry(char[] ca, int cLast, int cFirst) {
1809 boolean carry = true;
1810 for (int i = cLast; carry && i >= cFirst; i--) {
1811 carry = false;
1812 switch (ca[i]) {
1813 case '0' :
1814 ca[i] = '1';
1815 break;
1816 case '1' :
1817 ca[i] = '2';
1818 break;
1819 case '2' :
1820 ca[i] = '3';
1821 break;
1822 case '3' :
1823 ca[i] = '4';
1824 break;
1825 case '4' :
1826 ca[i] = '5';
1827 break;
1828 case '5' :
1829 ca[i] = '6';
1830 break;
1831 case '6' :
1832 ca[i] = '7';
1833 break;
1834 case '7' :
1835 ca[i] = '8';
1836 break;
1837 case '8' :
1838 ca[i] = '9';
1839 break;
1840 case '9' :
1841 ca[i] = '0';
1842 carry = true;
1843 break;
1844 }
1845 }
1846 return carry;
1847 }
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859 private String eFormatString(double x, char eChar) {
1860
1861 char[] ca4, ca5;
1862 if (Double.isInfinite(x)) {
1863 if (x == Double.POSITIVE_INFINITY) {
1864 if (leadingSign)
1865 ca4 = "+Inf".toCharArray();
1866 else if (leadingSpace)
1867 ca4 = " Inf".toCharArray();
1868 else
1869 ca4 = "Inf".toCharArray();
1870 } else
1871 ca4 = "-Inf".toCharArray();
1872
1873 } else if (Double.isNaN(x)) {
1874 if (leadingSign)
1875 ca4 = "+NaN".toCharArray();
1876 else if (leadingSpace)
1877 ca4 = " NaN".toCharArray();
1878 else
1879 ca4 = "NaN".toCharArray();
1880
1881 } else
1882 ca4 = eFormatDigits(x, eChar);
1883 ca5 = applyFloatPadding(ca4, false);
1884 return new String(ca5);
1885 }
1886
1887
1888
1889
1890
1891
1892
1893 private char[] applyFloatPadding(char[] ca4, boolean noDigits) {
1894 char[] ca5 = ca4;
1895 if (fieldWidthSet) {
1896 int i, j, nBlanks;
1897 if (leftJustify) {
1898 nBlanks = fieldWidth - ca4.length;
1899 if (nBlanks > 0) {
1900 ca5 = new char[ca4.length + nBlanks];
1901 for (i = 0; i < ca4.length; i++)
1902 ca5[i] = ca4[i];
1903 for (j = 0; j < nBlanks; j++, i++)
1904 ca5[i] = ' ';
1905 }
1906 } else if (!leadingZeros || noDigits) {
1907 nBlanks = fieldWidth - ca4.length;
1908 if (nBlanks > 0) {
1909 ca5 = new char[ca4.length + nBlanks];
1910 for (i = 0; i < nBlanks; i++)
1911 ca5[i] = ' ';
1912 for (j = 0; j < ca4.length; i++, j++)
1913 ca5[i] = ca4[j];
1914 }
1915 } else if (leadingZeros) {
1916 nBlanks = fieldWidth - ca4.length;
1917 if (nBlanks > 0) {
1918 ca5 = new char[ca4.length + nBlanks];
1919 i = 0;
1920 j = 0;
1921 if (ca4[0] == '-') {
1922 ca5[0] = '-';
1923 i++;
1924 j++;
1925 }
1926 for (int k = 0; k < nBlanks; i++, k++)
1927 ca5[i] = '0';
1928 for (; j < ca4.length; i++, j++)
1929 ca5[i] = ca4[j];
1930 }
1931 }
1932 }
1933 return ca5;
1934 }
1935
1936
1937
1938
1939
1940 private String printFFormat(double x) {
1941 return fFormatString(x);
1942 }
1943
1944
1945
1946
1947
1948
1949 private String printEFormat(double x) {
1950 if (conversionCharacter == 'e')
1951 return eFormatString(x, 'e');
1952 else
1953 return eFormatString(x, 'E');
1954 }
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981 private String printGFormat(double x) {
1982 String sx, sy, sz, ret;
1983 int savePrecision = precision;
1984 int i;
1985 char[] ca4, ca5;
1986
1987 if (Double.isInfinite(x)) {
1988 if (x == Double.POSITIVE_INFINITY) {
1989 if (leadingSign)
1990 ca4 = "+Inf".toCharArray();
1991 else if (leadingSpace)
1992 ca4 = " Inf".toCharArray();
1993 else
1994 ca4 = "Inf".toCharArray();
1995 } else
1996 ca4 = "-Inf".toCharArray();
1997
1998 } else if (Double.isNaN(x)) {
1999 if (leadingSign)
2000 ca4 = "+NaN".toCharArray();
2001 else if (leadingSpace)
2002 ca4 = " NaN".toCharArray();
2003 else
2004 ca4 = "NaN".toCharArray();
2005
2006 } else {
2007 if (!precisionSet)
2008 precision = defaultDigits;
2009 if (precision == 0)
2010 precision = 1;
2011 int ePos = -1;
2012 if (conversionCharacter == 'g') {
2013 sx = eFormatString(x, 'e').trim();
2014 ePos = sx.indexOf('e');
2015 } else {
2016 sx = eFormatString(x, 'E').trim();
2017 ePos = sx.indexOf('E');
2018 }
2019 i = ePos + 1;
2020 int expon = 0;
2021 if (sx.charAt(i) == '-') {
2022 for (++i; i < sx.length(); i++)
2023 if (sx.charAt(i) != '0')
2024 break;
2025 if (i < sx.length())
2026 expon = -Integer.parseInt(sx.substring(i));
2027 } else {
2028 if (sx.charAt(i) == '+')
2029 ++i;
2030 for (; i < sx.length(); i++)
2031 if (sx.charAt(i) != '0')
2032 break;
2033 if (i < sx.length())
2034 expon = Integer.parseInt(sx.substring(i));
2035 }
2036
2037
2038
2039 if (!alternateForm) {
2040 if (expon >= -4 && expon < precision)
2041 sy = fFormatString(x).trim();
2042 else
2043 sy = sx.substring(0, ePos);
2044 i = sy.length() - 1;
2045 for (; i >= 0; i--)
2046 if (sy.charAt(i) != '0')
2047 break;
2048 if (i >= 0 && sy.charAt(i) == '.')
2049 i--;
2050 if (i == -1)
2051 sz = "0";
2052 else if (!Character.isDigit(sy.charAt(i)))
2053 sz = sy.substring(0, i + 1) + "0";
2054 else
2055 sz = sy.substring(0, i + 1);
2056 if (expon >= -4 && expon < precision)
2057 ret = sz;
2058 else
2059 ret = sz + sx.substring(ePos);
2060 } else {
2061 if (expon >= -4 && expon < precision)
2062 ret = fFormatString(x).trim();
2063 else
2064 ret = sx;
2065 }
2066
2067
2068 if (leadingSpace)
2069 if (x >= 0)
2070 ret = " " + ret;
2071 ca4 = ret.toCharArray();
2072 }
2073
2074 ca5 = applyFloatPadding(ca4, false);
2075 precision = savePrecision;
2076 return new String(ca5);
2077 }
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104 private String printDFormat(short x) {
2105 return printDFormat(Short.toString(x));
2106 }
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133 private String printDFormat(long x) {
2134 return printDFormat(Long.toString(x));
2135 }
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162 private String printDFormat(int x) {
2163 return printDFormat(Integer.toString(x));
2164 }
2165
2166
2167
2168
2169
2170
2171
2172
2173 private String printDFormat(String sx) {
2174 int nLeadingZeros = 0;
2175 int nBlanks = 0, n = 0;
2176 int i = 0, jFirst = 0;
2177 boolean neg = sx.charAt(0) == '-';
2178 if (sx.equals("0") && precisionSet && precision == 0)
2179 sx = "";
2180 if (!neg) {
2181 if (precisionSet && sx.length() < precision)
2182 nLeadingZeros = precision - sx.length();
2183 } else {
2184 if (precisionSet && (sx.length() - 1) < precision)
2185 nLeadingZeros = precision - sx.length() + 1;
2186 }
2187 if (nLeadingZeros < 0)
2188 nLeadingZeros = 0;
2189 if (fieldWidthSet) {
2190 nBlanks = fieldWidth - nLeadingZeros - sx.length();
2191 if (!neg && (leadingSign || leadingSpace))
2192 nBlanks--;
2193 }
2194 if (nBlanks < 0)
2195 nBlanks = 0;
2196 if (leadingSign && !neg)
2197 n++;
2198 else if (leadingSpace)
2199 n++;
2200 n += nBlanks;
2201 n += nLeadingZeros;
2202 n += sx.length();
2203 char[] ca = new char[n];
2204 if (leftJustify) {
2205 if (neg)
2206 ca[i++] = '-';
2207 else if (leadingSign)
2208 ca[i++] = '+';
2209 else if (leadingSpace)
2210 ca[i++] = ' ';
2211 char[] csx = sx.toCharArray();
2212 jFirst = neg ? 1 : 0;
2213 for (int j = 0; j < nLeadingZeros; i++, j++)
2214 ca[i] = '0';
2215 for (int j = jFirst; j < csx.length; j++, i++)
2216 ca[i] = csx[j];
2217 for (int j = 0; j < nBlanks; i++, j++)
2218 ca[i] = ' ';
2219 } else {
2220 if (!leadingZeros) {
2221 for (i = 0; i < nBlanks; i++)
2222 ca[i] = ' ';
2223 if (neg)
2224 ca[i++] = '-';
2225 else if (leadingSign)
2226 ca[i++] = '+';
2227 else if (leadingSpace)
2228 ca[i++] = ' ';
2229 } else {
2230 if (neg)
2231 ca[i++] = '-';
2232 else if (leadingSign)
2233 ca[i++] = '+';
2234 else if (leadingSpace)
2235 ca[i++] = ' ';
2236 for (int j = 0; j < nBlanks; j++, i++)
2237 ca[i] = '0';
2238 }
2239 for (int j = 0; j < nLeadingZeros; j++, i++)
2240 ca[i] = '0';
2241 char[] csx = sx.toCharArray();
2242 jFirst = neg ? 1 : 0;
2243 for (int j = jFirst; j < csx.length; j++, i++)
2244 ca[i] = csx[j];
2245 }
2246 return new String(ca);
2247 }
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268 private String printXFormat(short x) {
2269 String sx = null;
2270 if (x == Short.MIN_VALUE)
2271 sx = "8000";
2272 else if (x < 0) {
2273 String t;
2274 if (x == Short.MIN_VALUE)
2275 t = "0";
2276 else {
2277 t = Integer.toString((~(-x - 1)) ^ Short.MIN_VALUE, 16);
2278 if (t.charAt(0) == 'F' || t.charAt(0) == 'f')
2279 t = t.substring(16, 32);
2280 }
2281 switch (t.length()) {
2282 case 1 :
2283 sx = "800" + t;
2284 break;
2285 case 2 :
2286 sx = "80" + t;
2287 break;
2288 case 3 :
2289 sx = "8" + t;
2290 break;
2291 case 4 :
2292 switch (t.charAt(0)) {
2293 case '1' :
2294 sx = "9" + t.substring(1, 4);
2295 break;
2296 case '2' :
2297 sx = "a" + t.substring(1, 4);
2298 break;
2299 case '3' :
2300 sx = "b" + t.substring(1, 4);
2301 break;
2302 case '4' :
2303 sx = "c" + t.substring(1, 4);
2304 break;
2305 case '5' :
2306 sx = "d" + t.substring(1, 4);
2307 break;
2308 case '6' :
2309 sx = "e" + t.substring(1, 4);
2310 break;
2311 case '7' :
2312 sx = "f" + t.substring(1, 4);
2313 break;
2314 }
2315 break;
2316 }
2317 } else
2318 sx = Integer.toString((int) x, 16);
2319 return printXFormat(sx);
2320 }
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341 private String printXFormat(long x) {
2342 String sx = null;
2343 if (x == Long.MIN_VALUE)
2344 sx = "8000000000000000";
2345 else if (x < 0) {
2346 String t = Long.toString((~(-x - 1)) ^ Long.MIN_VALUE, 16);
2347 switch (t.length()) {
2348 case 1 :
2349 sx = "800000000000000" + t;
2350 break;
2351 case 2 :
2352 sx = "80000000000000" + t;
2353 break;
2354 case 3 :
2355 sx = "8000000000000" + t;
2356 break;
2357 case 4 :
2358 sx = "800000000000" + t;
2359 break;
2360 case 5 :
2361 sx = "80000000000" + t;
2362 break;
2363 case 6 :
2364 sx = "8000000000" + t;
2365 break;
2366 case 7 :
2367 sx = "800000000" + t;
2368 break;
2369 case 8 :
2370 sx = "80000000" + t;
2371 break;
2372 case 9 :
2373 sx = "8000000" + t;
2374 break;
2375 case 10 :
2376 sx = "800000" + t;
2377 break;
2378 case 11 :
2379 sx = "80000" + t;
2380 break;
2381 case 12 :
2382 sx = "8000" + t;
2383 break;
2384 case 13 :
2385 sx = "800" + t;
2386 break;
2387 case 14 :
2388 sx = "80" + t;
2389 break;
2390 case 15 :
2391 sx = "8" + t;
2392 break;
2393 case 16 :
2394 switch (t.charAt(0)) {
2395 case '1' :
2396 sx = "9" + t.substring(1, 16);
2397 break;
2398 case '2' :
2399 sx = "a" + t.substring(1, 16);
2400 break;
2401 case '3' :
2402 sx = "b" + t.substring(1, 16);
2403 break;
2404 case '4' :
2405 sx = "c" + t.substring(1, 16);
2406 break;
2407 case '5' :
2408 sx = "d" + t.substring(1, 16);
2409 break;
2410 case '6' :
2411 sx = "e" + t.substring(1, 16);
2412 break;
2413 case '7' :
2414 sx = "f" + t.substring(1, 16);
2415 break;
2416 }
2417 break;
2418 }
2419 } else
2420 sx = Long.toString(x, 16);
2421 return printXFormat(sx);
2422 }
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443 private String printXFormat(int x) {
2444 String sx = null;
2445 if (x == Integer.MIN_VALUE)
2446 sx = "80000000";
2447 else if (x < 0) {
2448 String t = Integer.toString((~(-x - 1)) ^ Integer.MIN_VALUE, 16);
2449 switch (t.length()) {
2450 case 1 :
2451 sx = "8000000" + t;
2452 break;
2453 case 2 :
2454 sx = "800000" + t;
2455 break;
2456 case 3 :
2457 sx = "80000" + t;
2458 break;
2459 case 4 :
2460 sx = "8000" + t;
2461 break;
2462 case 5 :
2463 sx = "800" + t;
2464 break;
2465 case 6 :
2466 sx = "80" + t;
2467 break;
2468 case 7 :
2469 sx = "8" + t;
2470 break;
2471 case 8 :
2472 switch (t.charAt(0)) {
2473 case '1' :
2474 sx = "9" + t.substring(1, 8);
2475 break;
2476 case '2' :
2477 sx = "a" + t.substring(1, 8);
2478 break;
2479 case '3' :
2480 sx = "b" + t.substring(1, 8);
2481 break;
2482 case '4' :
2483 sx = "c" + t.substring(1, 8);
2484 break;
2485 case '5' :
2486 sx = "d" + t.substring(1, 8);
2487 break;
2488 case '6' :
2489 sx = "e" + t.substring(1, 8);
2490 break;
2491 case '7' :
2492 sx = "f" + t.substring(1, 8);
2493 break;
2494 }
2495 break;
2496 }
2497 } else
2498 sx = Integer.toString(x, 16);
2499 return printXFormat(sx);
2500 }
2501
2502
2503
2504
2505
2506
2507
2508
2509 private String printXFormat(String sx) {
2510 int nLeadingZeros = 0;
2511 int nBlanks = 0;
2512 if (sx.equals("0") && precisionSet && precision == 0)
2513 sx = "";
2514 if (precisionSet)
2515 nLeadingZeros = precision - sx.length();
2516 if (nLeadingZeros < 0)
2517 nLeadingZeros = 0;
2518 if (fieldWidthSet) {
2519 nBlanks = fieldWidth - nLeadingZeros - sx.length();
2520 if (alternateForm)
2521 nBlanks = nBlanks - 2;
2522 }
2523 if (nBlanks < 0)
2524 nBlanks = 0;
2525 int n = 0;
2526 if (alternateForm)
2527 n += 2;
2528 n += nLeadingZeros;
2529 n += sx.length();
2530 n += nBlanks;
2531 char[] ca = new char[n];
2532 int i = 0;
2533 if (leftJustify) {
2534 if (alternateForm) {
2535 ca[i++] = '0';
2536 ca[i++] = 'x';
2537 }
2538 for (int j = 0; j < nLeadingZeros; j++, i++)
2539 ca[i] = '0';
2540 char[] csx = sx.toCharArray();
2541 for (int j = 0; j < csx.length; j++, i++)
2542 ca[i] = csx[j];
2543 for (int j = 0; j < nBlanks; j++, i++)
2544 ca[i] = ' ';
2545 } else {
2546 if (!leadingZeros)
2547 for (int j = 0; j < nBlanks; j++, i++)
2548 ca[i] = ' ';
2549 if (alternateForm) {
2550 ca[i++] = '0';
2551 ca[i++] = 'x';
2552 }
2553 if (leadingZeros)
2554 for (int j = 0; j < nBlanks; j++, i++)
2555 ca[i] = '0';
2556 for (int j = 0; j < nLeadingZeros; j++, i++)
2557 ca[i] = '0';
2558 char[] csx = sx.toCharArray();
2559 for (int j = 0; j < csx.length; j++, i++)
2560 ca[i] = csx[j];
2561 }
2562 String caReturn = new String(ca);
2563 if (conversionCharacter == 'X')
2564 caReturn = caReturn.toUpperCase();
2565 return caReturn;
2566 }
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588 private String printOFormat(short x) {
2589 String sx = null;
2590 if (x == Short.MIN_VALUE)
2591 sx = "100000";
2592 else if (x < 0) {
2593 String t = Integer.toString((~(-x - 1)) ^ Short.MIN_VALUE, 8);
2594 switch (t.length()) {
2595 case 1 :
2596 sx = "10000" + t;
2597 break;
2598 case 2 :
2599 sx = "1000" + t;
2600 break;
2601 case 3 :
2602 sx = "100" + t;
2603 break;
2604 case 4 :
2605 sx = "10" + t;
2606 break;
2607 case 5 :
2608 sx = "1" + t;
2609 break;
2610 }
2611 } else
2612 sx = Integer.toString((int) x, 8);
2613 return printOFormat(sx);
2614 }
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636 private String printOFormat(long x) {
2637 String sx = null;
2638 if (x == Long.MIN_VALUE)
2639 sx = "1000000000000000000000";
2640 else if (x < 0) {
2641 String t = Long.toString((~(-x - 1)) ^ Long.MIN_VALUE, 8);
2642 switch (t.length()) {
2643 case 1 :
2644 sx = "100000000000000000000" + t;
2645 break;
2646 case 2 :
2647 sx = "10000000000000000000" + t;
2648 break;
2649 case 3 :
2650 sx = "1000000000000000000" + t;
2651 break;
2652 case 4 :
2653 sx = "100000000000000000" + t;
2654 break;
2655 case 5 :
2656 sx = "10000000000000000" + t;
2657 break;
2658 case 6 :
2659 sx = "1000000000000000" + t;
2660 break;
2661 case 7 :
2662 sx = "100000000000000" + t;
2663 break;
2664 case 8 :
2665 sx = "10000000000000" + t;
2666 break;
2667 case 9 :
2668 sx = "1000000000000" + t;
2669 break;
2670 case 10 :
2671 sx = "100000000000" + t;
2672 break;
2673 case 11 :
2674 sx = "10000000000" + t;
2675 break;
2676 case 12 :
2677 sx = "1000000000" + t;
2678 break;
2679 case 13 :
2680 sx = "100000000" + t;
2681 break;
2682 case 14 :
2683 sx = "10000000" + t;
2684 break;
2685 case 15 :
2686 sx = "1000000" + t;
2687 break;
2688 case 16 :
2689 sx = "100000" + t;
2690 break;
2691 case 17 :
2692 sx = "10000" + t;
2693 break;
2694 case 18 :
2695 sx = "1000" + t;
2696 break;
2697 case 19 :
2698 sx = "100" + t;
2699 break;
2700 case 20 :
2701 sx = "10" + t;
2702 break;
2703 case 21 :
2704 sx = "1" + t;
2705 break;
2706 }
2707 } else
2708 sx = Long.toString(x, 8);
2709 return printOFormat(sx);
2710 }
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732 private String printOFormat(int x) {
2733 String sx = null;
2734 if (x == Integer.MIN_VALUE)
2735 sx = "20000000000";
2736 else if (x < 0) {
2737 String t = Integer.toString((~(-x - 1)) ^ Integer.MIN_VALUE, 8);
2738 switch (t.length()) {
2739 case 1 :
2740 sx = "2000000000" + t;
2741 break;
2742 case 2 :
2743 sx = "200000000" + t;
2744 break;
2745 case 3 :
2746 sx = "20000000" + t;
2747 break;
2748 case 4 :
2749 sx = "2000000" + t;
2750 break;
2751 case 5 :
2752 sx = "200000" + t;
2753 break;
2754 case 6 :
2755 sx = "20000" + t;
2756 break;
2757 case 7 :
2758 sx = "2000" + t;
2759 break;
2760 case 8 :
2761 sx = "200" + t;
2762 break;
2763 case 9 :
2764 sx = "20" + t;
2765 break;
2766 case 10 :
2767 sx = "2" + t;
2768 break;
2769 case 11 :
2770 sx = "3" + t.substring(1);
2771 break;
2772 }
2773 } else
2774 sx = Integer.toString(x, 8);
2775 return printOFormat(sx);
2776 }
2777
2778
2779
2780
2781
2782
2783
2784
2785 private String printOFormat(String sx) {
2786 int nLeadingZeros = 0;
2787 int nBlanks = 0;
2788 if (sx.equals("0") && precisionSet && precision == 0)
2789 sx = "";
2790 if (precisionSet)
2791 nLeadingZeros = precision - sx.length();
2792 if (alternateForm)
2793 nLeadingZeros++;
2794 if (nLeadingZeros < 0)
2795 nLeadingZeros = 0;
2796 if (fieldWidthSet)
2797 nBlanks = fieldWidth - nLeadingZeros - sx.length();
2798 if (nBlanks < 0)
2799 nBlanks = 0;
2800 int n = nLeadingZeros + sx.length() + nBlanks;
2801 char[] ca = new char[n];
2802 int i;
2803 if (leftJustify) {
2804 for (i = 0; i < nLeadingZeros; i++)
2805 ca[i] = '0';
2806 char[] csx = sx.toCharArray();
2807 for (int j = 0; j < csx.length; j++, i++)
2808 ca[i] = csx[j];
2809 for (int j = 0; j < nBlanks; j++, i++)
2810 ca[i] = ' ';
2811 } else {
2812 if (leadingZeros)
2813 for (i = 0; i < nBlanks; i++)
2814 ca[i] = '0';
2815 else
2816 for (i = 0; i < nBlanks; i++)
2817 ca[i] = ' ';
2818 for (int j = 0; j < nLeadingZeros; j++, i++)
2819 ca[i] = '0';
2820 char[] csx = sx.toCharArray();
2821 for (int j = 0; j < csx.length; j++, i++)
2822 ca[i] = csx[j];
2823 }
2824 return new String(ca);
2825 }
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843 private String printCFormat(char x) {
2844 int nPrint = 1;
2845 int width = fieldWidth;
2846 if (!fieldWidthSet)
2847 width = nPrint;
2848 char[] ca = new char[width];
2849 int i = 0;
2850 if (leftJustify) {
2851 ca[0] = x;
2852 for (i = 1; i <= width - nPrint; i++)
2853 ca[i] = ' ';
2854 } else {
2855 for (i = 0; i < width - nPrint; i++)
2856 ca[i] = ' ';
2857 ca[i] = x;
2858 }
2859 return new String(ca);
2860 }
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884 private String printSFormat(String x) {
2885 int nPrint = x.length();
2886 int width = fieldWidth;
2887 if (precisionSet && nPrint > precision)
2888 nPrint = precision;
2889 if (!fieldWidthSet)
2890 width = nPrint;
2891 int n = 0;
2892 if (width > nPrint)
2893 n += width - nPrint;
2894 if (nPrint >= x.length())
2895 n += x.length();
2896 else
2897 n += nPrint;
2898 char[] ca = new char[n];
2899 int i = 0;
2900 if (leftJustify) {
2901 if (nPrint >= x.length()) {
2902 char[] csx = x.toCharArray();
2903 for (i = 0; i < x.length(); i++)
2904 ca[i] = csx[i];
2905 } else {
2906 char[] csx = x.substring(0, nPrint).toCharArray();
2907 for (i = 0; i < nPrint; i++)
2908 ca[i] = csx[i];
2909 }
2910 for (int j = 0; j < width - nPrint; j++, i++)
2911 ca[i] = ' ';
2912 } else {
2913 for (i = 0; i < width - nPrint; i++)
2914 ca[i] = ' ';
2915 if (nPrint >= x.length()) {
2916 char[] csx = x.toCharArray();
2917 for (int j = 0; j < x.length(); i++, j++)
2918 ca[i] = csx[j];
2919 } else {
2920 char[] csx = x.substring(0, nPrint).toCharArray();
2921 for (int j = 0; j < nPrint; i++, j++)
2922 ca[i] = csx[j];
2923 }
2924 }
2925 return new String(ca);
2926 }
2927
2928
2929
2930
2931
2932
2933
2934 private boolean setConversionCharacter() {
2935
2936 boolean ret = false;
2937 conversionCharacter = '\0';
2938 if (pos < fmt.length()) {
2939 char c = fmt.charAt(pos);
2940 if (c == 'i'
2941 || c == 'd'
2942 || c == 'f'
2943 || c == 'g'
2944 || c == 'G'
2945 || c == 'o'
2946 || c == 'x'
2947 || c == 'X'
2948 || c == 'e'
2949 || c == 'E'
2950 || c == 'c'
2951 || c == 's'
2952 || c == '%') {
2953 conversionCharacter = c;
2954 pos++;
2955 ret = true;
2956 }
2957 }
2958 return ret;
2959 }
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969 private void setOptionalHL() {
2970 optionalh = false;
2971 optionall = false;
2972 optionalL = false;
2973 if (pos < fmt.length()) {
2974 char c = fmt.charAt(pos);
2975 if (c == 'h') {
2976 optionalh = true;
2977 pos++;
2978 } else if (c == 'l') {
2979 optionall = true;
2980 pos++;
2981 } else if (c == 'L') {
2982 optionalL = true;
2983 pos++;
2984 }
2985 }
2986 }
2987
2988
2989
2990 private void setPrecisionE() {
2991 if (pos<fmt.length() && Character.isDigit(fmt.charAt(pos))) {
2992 precisionE= Integer.parseInt(fmt.substring(pos,pos+1));
2993 if (precisionE>3) precisionE=3;
2994 if (precisionE<1) precisionE=1;
2995 pos++;
2996 }
2997 }
2998
2999
3000
3001 private void setPrecision() {
3002 int firstPos = pos;
3003 precisionSet = false;
3004 if (pos < fmt.length() && fmt.charAt(pos) == '.') {
3005 pos++;
3006 if ((pos < fmt.length()) && (fmt.charAt(pos) == '*')) {
3007 pos++;
3008 if (!setPrecisionArgPosition()) {
3009 variablePrecision = true;
3010 precisionSet = true;
3011 }
3012 return;
3013 } else {
3014 while (pos < fmt.length()) {
3015 char c = fmt.charAt(pos);
3016 if (Character.isDigit(c))
3017 pos++;
3018 else
3019 break;
3020 }
3021 if (pos > firstPos + 1) {
3022 String sz = fmt.substring(firstPos + 1, pos);
3023 precision = Integer.parseInt(sz);
3024 precisionSet = true;
3025 }
3026 }
3027 }
3028 }
3029
3030
3031
3032 private void setFieldWidth() {
3033 int firstPos = pos;
3034 fieldWidth = 0;
3035 fieldWidthSet = false;
3036 if ((pos < fmt.length()) && (fmt.charAt(pos) == '*')) {
3037 pos++;
3038 if (!setFieldWidthArgPosition()) {
3039 variableFieldWidth = true;
3040 fieldWidthSet = true;
3041 }
3042 } else {
3043 while (pos < fmt.length()) {
3044 char c = fmt.charAt(pos);
3045 if (Character.isDigit(c))
3046 pos++;
3047 else
3048 break;
3049 }
3050 if (firstPos < pos && firstPos < fmt.length()) {
3051 String sz = fmt.substring(firstPos, pos);
3052 fieldWidth = Integer.parseInt(sz);
3053 fieldWidthSet = true;
3054 }
3055 }
3056 }
3057
3058
3059
3060 private void setArgPosition() {
3061 int xPos;
3062 for (xPos = pos; xPos < fmt.length(); xPos++) {
3063 if (!Character.isDigit(fmt.charAt(xPos)))
3064 break;
3065 }
3066 if (xPos > pos && xPos < fmt.length()) {
3067 if (fmt.charAt(xPos) == '$') {
3068 positionalSpecification = true;
3069 argumentPosition = Integer.parseInt(fmt.substring(pos, xPos));
3070 pos = xPos + 1;
3071 }
3072 }
3073 }
3074
3075
3076
3077 private boolean setFieldWidthArgPosition() {
3078 boolean ret = false;
3079 int xPos;
3080 for (xPos = pos; xPos < fmt.length(); xPos++) {
3081 if (!Character.isDigit(fmt.charAt(xPos)))
3082 break;
3083 }
3084 if (xPos > pos && xPos < fmt.length()) {
3085 if (fmt.charAt(xPos) == '$') {
3086 positionalFieldWidth = true;
3087 argumentPositionForFieldWidth = Integer.parseInt(fmt.substring(pos, xPos));
3088 pos = xPos + 1;
3089 ret = true;
3090 }
3091 }
3092 return ret;
3093 }
3094
3095
3096
3097 private boolean setPrecisionArgPosition() {
3098 boolean ret = false;
3099 int xPos;
3100 for (xPos = pos; xPos < fmt.length(); xPos++) {
3101 if (!Character.isDigit(fmt.charAt(xPos)))
3102 break;
3103 }
3104 if (xPos > pos && xPos < fmt.length()) {
3105 if (fmt.charAt(xPos) == '$') {
3106 positionalPrecision = true;
3107 argumentPositionForPrecision = Integer.parseInt(fmt.substring(pos, xPos));
3108 pos = xPos + 1;
3109 ret = true;
3110 }
3111 }
3112 return ret;
3113 }
3114 boolean isPositionalSpecification() {
3115 return positionalSpecification;
3116 }
3117 int getArgumentPosition() {
3118 return argumentPosition;
3119 }
3120 boolean isPositionalFieldWidth() {
3121 return positionalFieldWidth;
3122 }
3123 int getArgumentPositionForFieldWidth() {
3124 return argumentPositionForFieldWidth;
3125 }
3126 boolean isPositionalPrecision() {
3127 return positionalPrecision;
3128 }
3129 int getArgumentPositionForPrecision() {
3130 return argumentPositionForPrecision;
3131 }
3132
3133
3134
3135 private void setFlagCharacters() {
3136
3137 thousands = false;
3138 leftJustify = false;
3139 leadingSign = false;
3140 leadingSpace = false;
3141 alternateForm = false;
3142 leadingZeros = false;
3143 for (; pos < fmt.length(); pos++) {
3144 char c = fmt.charAt(pos);
3145 if (c == '\'')
3146 thousands = true;
3147 else if (c == '-') {
3148 leftJustify = true;
3149 leadingZeros = false;
3150 } else if (c == '+') {
3151 leadingSign = true;
3152 leadingSpace = false;
3153 } else if (c == ' ') {
3154 if (!leadingSign)
3155 leadingSpace = true;
3156 } else if (c == '#')
3157 alternateForm = true;
3158 else if (c == '0') {
3159 if (!leftJustify)
3160 leadingZeros = true;
3161 } else
3162 break;
3163 }
3164 }
3165
3166
3167
3168
3169
3170
3171 private boolean thousands = false;
3172
3173
3174
3175
3176 private boolean leftJustify = false;
3177
3178
3179
3180
3181 private boolean leadingSign = false;
3182
3183
3184
3185
3186 private boolean leadingSpace = false;
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198 private boolean alternateForm = false;
3199
3200
3201
3202
3203 private boolean leadingZeros = false;
3204
3205
3206
3207 private boolean variableFieldWidth = false;
3208
3209
3210
3211
3212
3213 private int fieldWidth = 0;
3214
3215
3216
3217
3218 private boolean fieldWidthSet = false;
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228 private int precision = 0;
3229
3230
3231
3232
3233 private int precisionE = 3;
3234 private boolean precisionSetE = false;
3235
3236
3237 private final static int defaultDigits = 6;
3238
3239
3240
3241 private boolean variablePrecision = false;
3242
3243
3244
3245
3246 private boolean precisionSet = false;
3247
3248
3249 private boolean positionalSpecification = false;
3250 private int argumentPosition = 0;
3251 private boolean positionalFieldWidth = false;
3252 private int argumentPositionForFieldWidth = 0;
3253 private boolean positionalPrecision = false;
3254 private int argumentPositionForPrecision = 0;
3255
3256
3257
3258
3259
3260 private boolean optionalh = false;
3261
3262
3263
3264
3265
3266 private boolean optionall = false;
3267
3268
3269
3270
3271
3272 private boolean optionalL = false;
3273
3274 private char conversionCharacter = '\0';
3275
3276
3277
3278
3279 private int pos = 0;
3280
3281 private String fmt;
3282 }
3283
3284 private Vector vFmt = new Vector();
3285
3286 private int cPos = 0;
3287
3288 private DecimalFormatSymbols dfs = null;
3289 }