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