PictureFmt.java
71.3 KB
1
2
3
4
5
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
38
39
40
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
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
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
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.ut;
import com.adobe.xfa.ut.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public final class PictureFmt {
private final String msLocale;
static final String gsPictureLiterals = "\"' ,-./:?+*$()";
static final String gsNull = "null";
static final String gsZero = "zero";
static final String gsNum = "num";
static final String gsText = "text";
static final String gsDate = "date";
static final String gsTime = "time";
static final String gsDateTime = "datetime";
static final String gsShort = "short";
static final String gsMedium = "medium";
static final String gsLong = "long";
static final String gsFull = "full";
static final String gsDefault = "default";
static final String gsInteger = "integer";
static final String gsDecimal = "decimal";
static final String gsCurrency = "currency";
static final String gsPercent = "percent";
public static Point resolveRange(String s, int startIndex, int endIndex) {
if (startIndex > s.length()) {
startIndex = s.length();
}
if (endIndex > s.length()) {
endIndex = s.length();
}
return new Point(startIndex, endIndex);
}
public PictureFmt(String sLocale) {
this.msLocale = sLocale;
}
public boolean format(String sSource, String sPicture, StringBuilder sResult) {
sResult.setLength(0);
if (StringUtils.isEmpty(sPicture)) {
sResult.append(sSource);
return true;
}
ArrayList<String> oAlt = new ArrayList<String>();
if (!PictureFmt.getAlternates(sPicture, oAlt)) {
return true;
}
boolean bSuccess = false;
for (int i = 0; i < oAlt.size(); ++i) {
String sMask = PictureFmt.interpret(oAlt.get(i));
StringBuilder sDateMask = new StringBuilder();
StringBuilder sTimeMask = new StringBuilder();
if (sSource == null) {
if (PictureFmt.isNullPicture(sMask)) {
bSuccess = PictureFmt.formatNull(sSource, sMask, this.msLocale, sResult);
}
} else if (sSource.length() == 0) {
if (PictureFmt.isEmptyPicture(sMask)) {
bSuccess = true;
sResult.setLength(0);
}
} else {
bSuccess = PictureFmt.isNumericPicture(sMask) ? PictureFmt.formatNumeric(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isNullPicture(sMask) ? PictureFmt.formatNull(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isZeroPicture(sMask) ? PictureFmt.formatZero(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isDateTimePicture(sMask, sDateMask, sTimeMask) ? PictureFmt.formatDateTime(sSource, sMask, sDateMask.toString(), sTimeMask.toString(), this.msLocale, sResult, true) : (PictureFmt.isDatePicture(sMask) ? PictureFmt.formatDate(sSource, sMask, this.msLocale, sResult, true) : (PictureFmt.isTimePicture(sMask) ? PictureFmt.formatTime(sSource, sMask, this.msLocale, sResult, true) : (PictureFmt.isTextPicture(sMask) ? PictureFmt.formatText(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isCompoundPicture(sMask) ? PictureFmt.formatCompound(sSource, sMask, this.msLocale, sResult) : false)))))));
}
if (bSuccess) break;
}
return bSuccess;
}
public String parse(String sSource, String sPicture, BooleanHolder pbSuccess) {
if (StringUtils.isEmpty(sPicture)) {
return sSource;
}
if (sSource == null) {
if (pbSuccess != null) {
pbSuccess.value = true;
}
return null;
}
ArrayList<String> oAlt = new ArrayList<String>();
if (!PictureFmt.getAlternates(sPicture, oAlt)) {
return "";
}
boolean bSuccess = false;
StringHolder sResult = new StringHolder();
StringBuilder sDateMask = new StringBuilder();
StringBuilder sTimeMask = new StringBuilder();
for (int i = 0; i < oAlt.size(); ++i) {
String sMask = PictureFmt.interpret(oAlt.get(i));
sDateMask.setLength(0);
sTimeMask.setLength(0);
String string = sResult.value = sSource.length() > 0 ? "" : null;
bSuccess = PictureFmt.isNumericPicture(sMask) ? PictureFmt.parseNumeric(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isNullPicture(sMask) ? PictureFmt.parseNull(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isZeroPicture(sMask) ? PictureFmt.parseZero(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isDateTimePicture(sMask, sDateMask, sTimeMask) ? PictureFmt.parseDateTime(sSource, sMask, sDateMask.toString(), sTimeMask.toString(), this.msLocale, sResult, true) : (PictureFmt.isDatePicture(sMask) ? PictureFmt.parseDate(sSource, sMask, this.msLocale, sResult, true) : (PictureFmt.isTimePicture(sMask) ? PictureFmt.parseTime(sSource, sMask, this.msLocale, sResult, true) : (PictureFmt.isTextPicture(sMask) ? PictureFmt.parseText(sSource, sMask, this.msLocale, sResult) : (PictureFmt.isCompoundPicture(sMask) ? PictureFmt.parseCompound(sSource, sMask, this.msLocale, sResult) : false)))))));
if (bSuccess) break;
}
if (pbSuccess != null) {
pbSuccess.value = bSuccess;
}
return sResult.value;
}
public static String FF99ToXFA(String sPicture) {
int picLen = sPicture.length();
int needs_escapes = 0;
for (int i = 0; i < picLen; ++i) {
char chr = sPicture.charAt(i);
if (chr != '\"' && chr != '\'') continue;
++needs_escapes;
}
StringBuilder sRes = new StringBuilder(sPicture.length() + needs_escapes);
boolean START = false;
boolean SGLQUOTE = true;
int DBLQUOTE = 2;
int eState = 0;
int i2 = 0;
while (i2 < picLen) {
char chr = sPicture.charAt(i2++);
if (eState == 0) {
if (chr == '\'') {
eState = 1;
} else if (chr == '\"') {
eState = 2;
chr = '\'';
}
} else if (eState == 1) {
if (chr == '\'') {
eState = 0;
} else if (chr == '\"') {
sRes.append(chr);
}
} else if (eState == 2) {
if (chr == '\"') {
eState = 0;
chr = '\'';
} else if (chr == '\'') {
sRes.append(chr);
}
}
sRes.append(chr);
}
return sRes.toString();
}
public static boolean formatCompound(String sSource, String sPicture, String sLocale, StringBuilder sResult) {
MsgFormatPos oMessage = new MsgFormatPos(ResId.UNSUPPORTED_OPERATION, "PictureFmt#formatCompound");
oMessage.format("formatCompound");
throw new ExFull(oMessage);
}
public static boolean formatDate(String sSource, String sPicture, String sLocale, StringBuilder sResult, boolean bAsLocal) {
ISODate oDate;
assert (sResult != null);
sResult.setLength(0);
if (sSource == null) {
return false;
}
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sDateMask = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory, sLoc, sDateMask) && !sCategory.toString().equals("date")) {
sDateMask.replace(0, sDateMask.length(), sPicture);
}
if ((oDate = new ISODate(sSource, sLoc.toString())).isValid()) {
if (bAsLocal) {
oDate.setLocalDate();
}
sResult.append(oDate.format(sDateMask.toString()));
}
return sResult.length() != 0;
}
public static boolean formatDateTime(String sSource, String sPicture, String sDateMask, String sTimeMask, String sLocale, StringBuilder sResult, boolean bAsLocal) {
String sSourceDate;
String sSourceTime;
assert (sResult != null);
sResult.setLength(0);
if (sSource == null) {
return false;
}
boolean bValid = true;
String sFormattedDate = "";
String sFormattedTime = "";
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sCategory = new StringBuilder();
StringBuilder sDateSubMask = new StringBuilder();
StringBuilder sTimeSubMask = new StringBuilder();
if (!PictureFmt.isSubPicture(sDateMask, 0, sCategory, sLoc, sDateSubMask) && !sCategory.toString().startsWith("date")) {
sDateSubMask.replace(0, sDateSubMask.length(), sDateMask);
}
String sDateLocale = sLoc.toString();
sLoc.replace(0, sLoc.length(), sLocale);
if (!PictureFmt.isSubPicture(sTimeMask, 0, sCategory, sLoc, sTimeSubMask) && !sCategory.toString().startsWith("time")) {
sTimeSubMask.replace(0, sTimeSubMask.length(), sTimeMask);
}
String sTimeLocale = sLoc.toString();
int nFound = sSource.indexOf(84);
if (nFound >= 0) {
sSourceDate = sSource.substring(0, nFound);
sSourceTime = sSource.substring(nFound + 1);
ISODate oISODate = new ISODate(sSourceDate, sDateLocale);
ISOTime oISOTime = new ISOTime(sSourceTime, sTimeLocale);
boolean bl = bValid = oISODate.isValid() && oISOTime.isValid();
if (bValid) {
if (bAsLocal) {
oISODate.setLocalDate();
oISOTime.setLocalTime();
}
sFormattedDate = oISODate.format(sDateSubMask.toString());
sFormattedTime = oISOTime.format(sTimeSubMask.toString());
}
} else {
nFound = sSource.indexOf(32);
if (nFound >= 0) {
sSourceDate = sSource.substring(0, nFound);
sSourceTime = sSource.substring(nFound + 1);
String sSourceDateFmt = new LcData(sLocale).getDateFormat(1);
String sSourceTimeFmt = new LcData(sLocale).getTimeFormat(1);
LcDate oDate = new LcDate(sSourceDate, sSourceDateFmt, sDateLocale, 30);
LcTime oTime = new LcTime(sSourceTime, sSourceTimeFmt, sTimeLocale);
boolean bl = bValid = oDate.isValid() && oTime.isValid();
if (bValid) {
if (bAsLocal) {
oDate.setLocalDate();
oTime.setLocalTime();
}
sFormattedDate = oDate.format(sDateSubMask.toString());
sFormattedTime = oTime.format(sTimeSubMask.toString());
}
} else {
bValid = false;
}
}
if (bValid) {
if (sPicture.startsWith("datetime")) {
sResult.append(sDateMask);
sResult.append(' ');
sResult.append(sTimeMask);
} else {
sResult.replace(0, sResult.length(), sPicture);
}
int nCharPos = 0;
while (nCharPos < sResult.length()) {
char cChar;
int nPrevPos = nCharPos;
if ((cChar = sResult.charAt(nCharPos++)) != '\'') continue;
StringBuilder sLiteral = new StringBuilder();
int nEnd = nCharPos;
int n = PictureFmt.getLiteralSubstr(sResult.toString(), cChar, nEnd, sLiteral);
if (n <= nEnd) continue;
nEnd = n;
sResult.replace(nPrevPos, nEnd, sLiteral.toString());
nCharPos = nEnd - 2;
}
int nDateTag = sResult.indexOf("date");
int nEnd = sResult.substring(nDateTag, sResult.length()).indexOf(125);
sResult.replace(nDateTag, nDateTag + nEnd + 1, sFormattedDate);
int nTimeTag = sResult.indexOf("time");
nEnd = sResult.substring(nTimeTag, sResult.length()).indexOf(125);
sResult.replace(nTimeTag, nTimeTag + nEnd + 1, sFormattedTime);
}
return bValid;
}
public static boolean formatNull(String sSource, String sPicture, String sLocale, StringBuilder sResult) {
assert (sResult != null);
sResult.setLength(0);
if (sSource != null) {
return false;
}
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sNullMask = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory, sLoc, sNullMask) && !sCategory.toString().equals("null")) {
sNullMask.replace(0, sNullMask.length(), sPicture);
}
if (sNullMask.length() == 0) {
return true;
}
LcNum oNum = new LcNum("0", sLoc.toString());
if (oNum.isValid()) {
sResult.append(oNum.format(sNullMask.toString(), null));
}
return sResult.length() != 0;
}
public static boolean formatNumeric(String sSource, String sPicture, String sLocale, StringBuilder sResult) {
LcNum oNum;
assert (sResult != null);
sResult.setLength(0);
if (sSource == null) {
return false;
}
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sNumMask = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory, sLoc, sNumMask) && !sCategory.toString().equals("num")) {
sNumMask.replace(0, sNumMask.length(), sPicture);
}
if ((oNum = new LcNum(sSource, sLoc.toString())).isValid()) {
sResult.append(oNum.format(sNumMask.toString(), null));
}
return sResult.length() != 0;
}
public static boolean formatText(String sSource, String sPicture, String sLocale, StringBuilder sResult) {
LcText oText;
assert (sResult != null);
sResult.setLength(0);
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sCategory = new StringBuilder();
StringBuilder sTextMask = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory, sLoc, sTextMask) && !sCategory.toString().equals("text")) {
sTextMask.replace(0, sTextMask.length(), sPicture);
}
if ((oText = new LcText(sSource, sLoc.toString())).isValid()) {
sResult.append(oText.format(sTextMask.toString()));
}
return sResult.length() != 0;
}
public static boolean formatTime(String sSource, String sPicture, String sLocale, StringBuilder sResult, boolean bAsLocal) {
ISOTime oTime;
assert (sResult != null);
sResult.setLength(0);
if (sSource == null) {
return false;
}
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sTimeMask = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory, sLoc, sTimeMask) && !sCategory.toString().equals("time")) {
sTimeMask.replace(0, sTimeMask.length(), sPicture);
}
if ((oTime = new ISOTime(sSource, sLoc.toString())).isValid()) {
if (bAsLocal) {
oTime.setLocalTime();
}
sResult.append(oTime.format(sTimeMask.toString()));
}
return sResult.length() != 0;
}
public static boolean formatZero(String sSource, String sPicture, String sLocale, StringBuilder sResult) {
assert (sResult != null);
sResult.setLength(0);
if (sSource == null) {
return false;
}
if (!sSource.equals("0")) {
return false;
}
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sZeroMask = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory, sLoc, sZeroMask) && !sCategory.toString().equals("zero")) {
sZeroMask.replace(0, sZeroMask.length(), sPicture);
}
if (sZeroMask.length() == 0) {
return true;
}
LcNum oNum = new LcNum(sSource, sLoc.toString());
if (oNum.isValid()) {
sResult.append(oNum.format(sZeroMask.toString(), null));
}
return sResult.length() != 0;
}
public static boolean getAlternates(String sSource, List<String> oAlternates) {
int i;
char prevChr = '\u0000';
int chrCnt = 0;
boolean inQuoted = false;
boolean inQuoteQuoted = false;
int picLen = sSource.length();
int k = i = 0;
while (i < picLen) {
int j = i;
char chr = sSource.charAt(i++);
if (inQuoteQuoted) {
if (chr == '\'') {
chrCnt = 0;
} else {
inQuoted = false;
chrCnt = 1;
prevChr = chr;
}
inQuoteQuoted = false;
continue;
}
if (inQuoted) {
if (chr == '\'') {
inQuoteQuoted = true;
}
++chrCnt;
prevChr = chr;
continue;
}
if (chr == '\'') {
if (chrCnt > 0) {
if (prevChr == '|') {
oAlternates.add(sSource.substring(k, j - 1));
k = j;
}
chrCnt = 0;
prevChr = '\u0000';
}
inQuoted = true;
continue;
}
if (DateTimeUtil.matchChr("(%$,.)89BCDERSVZbcdrsvzt", chr) || DateTimeUtil.matchChr("9AO0Xt", chr) || DateTimeUtil.matchChr("DJMEeYWwGgt", chr) || DateTimeUtil.matchChr("hkHKMSFAZzt", chr) || 'a' <= chr && chr <= 'z' || 'A' <= chr && chr <= 'Z') {
if (chr != prevChr) {
if (chrCnt > 0) {
if (prevChr == '|') {
oAlternates.add(sSource.substring(k, j - 1));
k = j;
}
chrCnt = 0;
}
prevChr = chr;
}
++chrCnt;
continue;
}
if (chrCnt > 0) {
if (prevChr == '|') {
oAlternates.add(sSource.substring(k, j - 1));
k = j;
}
chrCnt = 1;
prevChr = chr;
continue;
}
if (prevChr == '|') {
oAlternates.add(sSource.substring(k, j - 1));
k = j;
}
chrCnt = 1;
prevChr = chr;
}
if (inQuoteQuoted) {
inQuoted = false;
}
if (inQuoted) {
int n = oAlternates.size();
while (n-- > 0) {
oAlternates.remove(n);
}
return false;
}
if (prevChr > '\u0000' && chrCnt > 0) {
assert (i == picLen);
oAlternates.add(sSource.substring(k, i));
}
return true;
}
public static boolean getLocaleFromPicture(String sPicture, String sCategory, StringBuilder sLocale) {
int nPictIndex = 0;
int nPrevIndex = 0;
sLocale.setLength(0);
while (nPictIndex < sPicture.length()) {
int nIndex;
char cChar;
nPrevIndex = nPictIndex;
if ((cChar = sPicture.charAt(nPictIndex++)) == '\'') {
nIndex = PictureFmt.getLiteralSubstr(sPicture, cChar, nPictIndex, null);
if (nIndex == nPictIndex) {
return false;
}
nPictIndex = nIndex;
continue;
}
if (PictureFmt.isCharAlphabetic(cChar)) {
int nLocaleEnd;
int nCategoryBeg = nPrevIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while (PictureFmt.isCharAlphabetic(sPicture.charAt(nPictIndex++))) {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
int nCategoryEnd = nPrevIndex;
int nLocaleBeg = nLocaleEnd = nPictIndex;
nPictIndex = nPrevIndex;
if ((cChar = sPicture.charAt(nPictIndex++)) == '(') {
nLocaleBeg = nPictIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while (sPicture.charAt(nPictIndex++) != ')') {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
nLocaleEnd = nPrevIndex;
cChar = sPicture.charAt(nPictIndex++);
}
if (cChar == '{') {
do {
if (nPictIndex == sPicture.length()) {
return false;
}
if ((cChar = sPicture.charAt(nPictIndex++)) == '\'') {
nIndex = PictureFmt.getLiteralSubstr(sPicture, cChar, nPictIndex, null);
if (nIndex == nPictIndex) {
return false;
}
nPictIndex = nIndex;
continue;
}
if (cChar == '}') break;
} while (true);
String sCandidate = sPicture.substring(nCategoryBeg, nCategoryEnd);
if (sCandidate.equals(sCategory)) {
if (sLocale.length() != 0) {
return false;
}
sLocale.replace(0, sLocale.length(), sPicture.substring(nLocaleBeg, nLocaleEnd));
continue;
}
}
return false;
}
if (PictureFmt.isCharNumeric(cChar) || PictureFmt.isCharLiteral(cChar)) continue;
return false;
}
return true;
}
public static boolean hasSubPicture(String sPicture, int nPictIndex, StringBuilder sCategory, StringBuilder sLocale, StringBuilder sSubMask) {
String sSubCategory = "";
while (nPictIndex < sPicture.length()) {
char cChar;
int nIndex;
int nPrevIndex = nPictIndex;
if ((cChar = sPicture.charAt(nPictIndex++)) == '\'') {
int nLiteralBeg = nPrevIndex;
nIndex = PictureFmt.getLiteralSubstr(sPicture, cChar, nPictIndex, null);
if (nIndex == nPictIndex) {
return false;
}
nPictIndex = nIndex;
int nLiteralEnd = nPictIndex - 1;
sSubMask.append(sPicture, nLiteralBeg, nLiteralEnd + 1);
continue;
}
if (PictureFmt.isCharAlphabetic(cChar)) {
int nLocaleEnd;
int nCategoryBeg = nPrevIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while (PictureFmt.isCharAlphabetic(sPicture.charAt(nPictIndex++))) {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
int nCategoryEnd = nPrevIndex;
int nLocaleBeg = nLocaleEnd = nPictIndex;
nPictIndex = nPrevIndex;
if ((cChar = sPicture.charAt(nPictIndex++)) == '.') {
int nSubCategoryBeg = nPictIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while ((cChar = sPicture.charAt(nPictIndex++)) != '(' && cChar != '{') {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
int nSubCategoryEnd = nPrevIndex;
sSubCategory = sPicture.substring(nSubCategoryBeg, nSubCategoryEnd);
}
if (cChar == '(') {
nLocaleBeg = nPictIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while (sPicture.charAt(nPictIndex++) != ')') {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
nLocaleEnd = nPrevIndex;
if (nLocaleEnd > nLocaleBeg) {
sLocale.replace(0, sLocale.length(), sPicture.substring(nLocaleBeg, nLocaleEnd));
}
cChar = sPicture.charAt(nPictIndex++);
}
if (cChar == '{') {
int nSubMaskBeg = nPictIndex;
do {
if (nPictIndex >= sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
if ((cChar = sPicture.charAt(nPictIndex++)) == '\'') {
nIndex = PictureFmt.getLiteralSubstr(sPicture, cChar, nPictIndex, null);
if (nIndex == nPictIndex) {
return false;
}
nPictIndex = nIndex;
continue;
}
if (cChar == '}') break;
} while (true);
int nSubMaskEnd = nPrevIndex;
String sCandidate = sPicture.substring(nCategoryBeg, nCategoryEnd);
if (sCandidate.equals("null") || sCandidate.equals("zero") || sCandidate.equals("text")) {
sCategory.append(sCandidate);
if (sLocale.length() == 0) {
sLocale.append("en_US");
}
sSubMask.append(sPicture, nSubMaskBeg, nSubMaskEnd);
continue;
}
if (sCandidate.equals("date") || sCandidate.equals("time")) {
LcData oData;
sCategory.append(sCandidate);
if (sLocale.length() == 0) {
sLocale.append("en_US");
}
String sFmt = null;
if (sSubCategory.length() == 0) {
sFmt = sPicture.substring(nSubMaskBeg, nSubMaskEnd);
} else if (sSubCategory.equals("short")) {
oData = new LcData(sLocale.toString());
sFmt = sCandidate.equals("date") ? oData.getDateFormat(1) : oData.getTimeFormat(1);
} else if (sSubCategory.equals("medium")) {
oData = new LcData(sLocale.toString());
sFmt = sCandidate.equals("date") ? oData.getDateFormat(2) : oData.getTimeFormat(2);
} else if (sSubCategory.equals("long")) {
oData = new LcData(sLocale.toString());
sFmt = sCandidate.equals("date") ? oData.getDateFormat(3) : oData.getTimeFormat(3);
} else if (sSubCategory.equals("full")) {
oData = new LcData(sLocale.toString());
sFmt = sCandidate.equals("date") ? oData.getDateFormat(4) : oData.getTimeFormat(4);
} else if (sSubCategory.equals("default")) {
oData = new LcData(sLocale.toString());
sFmt = sCandidate.equals("date") ? oData.getDateFormat(0) : oData.getTimeFormat(0);
} else {
return false;
}
sSubMask.append(sFmt);
continue;
}
if (sCandidate.equals("num")) {
int nOptn;
sCategory.append(sCandidate);
if (sLocale.length() == 0) {
sLocale.append("en_US");
}
LcData oData = new LcData(sLocale.toString());
String sFmt = null;
if (sSubCategory.length() == 0) {
sFmt = sPicture.substring(nSubMaskBeg, nSubMaskEnd);
} else if (sSubCategory.equals("integer")) {
nOptn = 1;
sFmt = oData.getNumberFormat(0, nOptn);
} else if (sSubCategory.equals("decimal")) {
nOptn = LcData.withPrecision(-1) | 1 | 8;
sFmt = oData.getNumberFormat(1, nOptn);
} else if (sSubCategory.equals("currency")) {
nOptn = LcData.withPrecision(-1) | 1 | 8;
sFmt = oData.getNumberFormat(2, nOptn);
} else if (sSubCategory.equals("percent")) {
nOptn = 1;
sFmt = oData.getNumberFormat(3, nOptn);
} else {
return false;
}
sSubMask.append(sFmt);
continue;
}
if (sCandidate.equals("datetime")) {
sCategory.append(sCandidate);
if (sLocale.length() == 0) {
sLocale.append("en_US");
}
LcData oData = new LcData(sLocale.toString());
int nOptn = 1;
String sFmt = null;
if (sSubCategory.equals("short")) {
sFmt = oData.getDateTimeFormat(1, nOptn);
} else if (sSubCategory.equals("medium")) {
sFmt = oData.getDateTimeFormat(2, nOptn);
} else if (sSubCategory.equals("long")) {
sFmt = oData.getDateTimeFormat(3, nOptn);
} else if (sSubCategory.equals("full")) {
sFmt = oData.getDateTimeFormat(4, nOptn);
} else if (sSubCategory.equals("default")) {
sFmt = oData.getDateTimeFormat(0, nOptn);
} else {
return false;
}
sSubMask.append(sFmt);
continue;
}
}
return false;
}
if (PictureFmt.isCharNumeric(cChar)) {
sSubMask.append(cChar);
continue;
}
if (PictureFmt.isCharLiteral(cChar)) {
sSubMask.append(cChar);
continue;
}
return false;
}
return true;
}
private static String interpret(String sSrc) {
int sSrcLen = sSrc.length();
StringBuilder sDst = new StringBuilder();
int i = 0;
while (i < sSrcLen) {
char ch;
if ((ch = sSrc.charAt(i++)) == '\\' && sSrc.charAt(i + 1) == 'u' && i + 5 < sSrcLen && PictureFmt.isCharHexDigit(sSrc.charAt(i + 2)) && PictureFmt.isCharHexDigit(sSrc.charAt(i + 3)) && PictureFmt.isCharHexDigit(sSrc.charAt(i + 4)) && PictureFmt.isCharHexDigit(sSrc.charAt(i + 5))) {
String sHex = sSrc.substring(i + 2, i + 6);
try {
char hHex = (char)Integer.parseInt(sHex, 16);
sDst.append(hHex);
i += 5;
continue;
}
catch (NumberFormatException e) {
assert (e != null);
continue;
}
}
sDst.append(ch);
}
return sDst.toString();
}
private static boolean isCharAlphabetic(char cChar) {
return Character.isLetter(cChar);
}
private static boolean isCharHexDigit(char cChar) {
return Character.isDigit(cChar) || 'a' <= Character.toLowerCase(cChar) && Character.toLowerCase(cChar) <= 'f';
}
private static boolean isCharLiteral(char cChar) {
return DateTimeUtil.matchChr("\"' ,-./:?+*$()", cChar);
}
private static boolean isCharNumeric(char cChar) {
return cChar == '0' || cChar == '9';
}
private static boolean isCompoundPicture(String sPicture) {
boolean bValid = true;
int nCharIndex = 0;
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder();
StringBuilder sMask = new StringBuilder();
while (nCharIndex < sPicture.length()) {
char cChar;
int nPrevIndex = nCharIndex;
if ((cChar = sPicture.charAt(nCharIndex++)) == '\'') {
int nIndex = PictureFmt.getLiteralSubstr(sPicture, cChar, nCharIndex, null);
if (nIndex > nCharIndex) {
nCharIndex = nIndex;
continue;
}
bValid = false;
continue;
}
if (PictureFmt.isSubPicture(sPicture, nPrevIndex, sCategory, sLoc, sMask)) {
if (sCategory.toString().startsWith("date")) {
bValid = PictureFmt.isDatePicture(sMask.toString());
} else if (sCategory.toString().startsWith("time")) {
bValid = PictureFmt.isTimePicture(sMask.toString());
} else if (sCategory.toString().equals("text")) {
bValid = PictureFmt.isTextPicture(sMask.toString());
} else if (sCategory.toString().equals("null")) {
bValid = PictureFmt.isNullPicture(sMask.toString());
} else if (sCategory.toString().equals("zero")) {
bValid = PictureFmt.isZeroPicture(sMask.toString());
} else if (sCategory.toString().equals("num")) {
bValid = PictureFmt.isNumericPicture(sMask.toString());
}
if (!bValid) break;
nPrevIndex += sCategory.length();
if (sLoc.length() != 0) {
nPrevIndex += sLoc.length() + 2;
}
nCharIndex = nPrevIndex += sMask.length() + 2;
continue;
}
if (PictureFmt.isCharNumeric(cChar) || PictureFmt.isCharLiteral(cChar)) continue;
bValid = false;
break;
}
return bValid;
}
public static boolean isDatePicture(String sPicture) {
return PictureFmt.isPicture(sPicture, "date", "DJMEeYWwGgt");
}
public static boolean isDatePictureValid(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder("en_US");
StringBuilder sPict = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCat, sLoc, sPict) || !sCat.toString().equals("date")) {
sPict.replace(0, sPict.length(), sPicture);
}
LcDate today = new LcDate(1, sLoc.toString(), 30);
return today.parse(today.format(sPict.toString()), sPict.toString());
}
public static boolean isDateTimePicture(String sPicture, StringBuilder sDateMask, StringBuilder sTimeMask) {
assert (sDateMask != null);
assert (sTimeMask != null);
sDateMask.setLength(0);
sTimeMask.setLength(0);
int i = 0;
while (i < sPicture.length()) {
char cChar;
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder();
StringBuilder sMask = new StringBuilder();
int j = i;
if ((cChar = sPicture.charAt(i++)) == '\'') {
int k = PictureFmt.getLiteralSubstr(sPicture, cChar, i, null);
if (k > i) {
i = k;
continue;
}
} else {
if (PictureFmt.isCharLiteral(cChar) || cChar == 'T') continue;
if (PictureFmt.isSubPicture(sPicture, j, sCategory, sLoc, sMask)) {
if (sCategory.toString().startsWith("date") && PictureFmt.isDatePicture(sMask.toString())) {
j += sCategory.length();
if (sLoc.length() != 0) {
j += sLoc.length() + 2;
}
if (sCategory.indexOf(".") < 0) {
j += sMask.length();
}
j += 2;
sDateMask.append(sCategory);
if (sLoc.length() != 0) {
sDateMask.append('(');
sDateMask.append(sLoc);
sDateMask.append(')');
}
sDateMask.append('{');
if (sCategory.indexOf(".") < 0) {
sDateMask.append(sMask);
}
sDateMask.append('}');
i = j;
continue;
}
if (sCategory.toString().startsWith("time") && PictureFmt.isTimePicture(sMask.toString())) {
j += sCategory.length();
if (sLoc.length() != 0) {
j += sLoc.length() + 2;
}
if (sCategory.indexOf(".") < 0) {
j += sMask.length();
}
j += 2;
sTimeMask.append(sCategory);
if (sLoc.length() != 0) {
sTimeMask.append('(');
sTimeMask.append(sLoc);
sTimeMask.append(')');
}
sTimeMask.append('{');
if (sCategory.indexOf(".") < 0) {
sTimeMask.append(sMask);
}
sTimeMask.append('}');
i = j;
continue;
}
if (sCategory.toString().startsWith("datetime")) {
if (!PictureFmt.isDateTimePicture(sMask.toString(), sDateMask, sTimeMask)) {
return false;
}
i = j += sPicture.length();
continue;
}
}
}
return false;
}
return sDateMask.length() != 0 && sTimeMask.length() != 0;
}
public static boolean isDateTimePictureValid(String sPicture) {
LcTime now;
LcDate today;
StringBuilder sDatePict = new StringBuilder();
StringBuilder sTimePict = new StringBuilder();
if (!PictureFmt.isDateTimePicture(sPicture, sDatePict, sTimePict)) {
return false;
}
StringBuilder sLoc = new StringBuilder("en_US");
StringBuilder sCat = new StringBuilder();
StringBuilder sPict = new StringBuilder();
if (PictureFmt.hasSubPicture(sDatePict.toString(), 0, sCat, sLoc, sPict)) {
sDatePict.replace(0, sDatePict.length(), sPict.toString());
}
if (!(today = new LcDate(1, sLoc.toString(), 30)).parse(today.format(sDatePict.toString()), sDatePict.toString())) {
return false;
}
sLoc = new StringBuilder("en_US");
sPict.setLength(0);
sCat.setLength(0);
if (PictureFmt.hasSubPicture(sTimePict.toString(), 0, sCat, sLoc, sPict)) {
sTimePict.replace(0, sTimePict.length(), sPict.toString());
}
if (!(now = new LcTime(1, sLoc.toString())).parse(now.format(sTimePict.toString()), sTimePict.toString())) {
return false;
}
return true;
}
public static boolean isNullPicture(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder();
StringBuilder sMask = new StringBuilder();
return PictureFmt.isSubPicture(sPicture, 0, sCat, sLoc, sMask) && sCat.toString().equals("null");
}
public static boolean isEmptyPicture(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder();
StringBuilder sMask = new StringBuilder();
return PictureFmt.isSubPicture(sPicture, 0, sCat, sLoc, sMask) && sMask.toString().length() == 0 && !sCat.toString().equals("null") && !sCat.toString().equals("zero");
}
public static boolean isNullPictureValid(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder("en_US");
StringBuilder sPict = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCat, sLoc, sPict) || !sCat.toString().equals("null")) {
sPict.replace(0, sPict.length(), sPicture);
}
LcNum one = new LcNum("1", sLoc.toString());
return one.parse(one.format(sPict.toString(), null), sPict.toString());
}
public static boolean isNumericPicture(String sPicture) {
return PictureFmt.isPicture(sPicture, "num", "(%$,.)89BCDERSVZbcdrsvzt");
}
public static boolean isNumericPictureValid(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder("en_US");
StringBuilder sPict = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCat, sLoc, sPict) || !sCat.toString().equals("num")) {
sPict.replace(0, sPict.length(), sPicture);
}
StringBuilder sOne = new StringBuilder("1");
int nDot = sPict.indexOf(".");
if (nDot >= 0) {
sOne.append('.');
if (sPict.indexOf("8", nDot + 1) >= 0) {
sOne.append('1');
} else if (sPict.indexOf("z", nDot + 1) >= 0) {
sOne.append('1');
} else if (sPict.indexOf("Z", nDot + 1) >= 0) {
sOne.append('1');
}
if (sPict.indexOf("%") >= 0) {
sOne.replace(0, sOne.length(), ".001");
}
} else if (sPict.indexOf("%") >= 0) {
sOne.replace(0, 1, ".00");
}
LcNum one = new LcNum(sOne.toString(), sLoc.toString());
LcNum num = new LcNum(one.format(sPict.toString(), null), sPict.toString());
return num.isValid();
}
private static boolean isPicture(String sPicture, String sCategory, String sSymbols) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder();
StringBuilder sMask = new StringBuilder();
int i = 0;
while (i < sPicture.length()) {
char cChar;
int j = i;
if ((cChar = sPicture.charAt(i++)) == '\'') {
int k = PictureFmt.getLiteralSubstr(sPicture, cChar, i, null);
if (k > i) {
i = k;
continue;
}
} else {
if (DateTimeUtil.matchChr("\"' ,-./:?+*$()", cChar)) continue;
if (PictureFmt.isSubPicture(sPicture, j, sCat, sLoc, sMask) && sCat.toString().startsWith(sCategory)) {
String sCatStr = sCat.toString();
String sMaskStr = sMask.toString();
if (sCatStr.startsWith("num") && PictureFmt.isNumericPicture(sMaskStr) || sCatStr.equals("null") && PictureFmt.isNullPicture(sMaskStr) || sCatStr.equals("zero") && PictureFmt.isZeroPicture(sMaskStr) || sCatStr.equals("text") && PictureFmt.isTextPicture(sMaskStr) || sCatStr.startsWith("date") && PictureFmt.isDatePicture(sMaskStr) || sCatStr.startsWith("time") && PictureFmt.isTimePicture(sMaskStr)) {
j += sCat.length();
if (sLoc.length() != 0) {
j += sLoc.length() + 2;
}
i = j += sMask.length() + 2;
continue;
}
} else if (DateTimeUtil.matchChr(sSymbols, cChar)) {
if (sSymbols != "(%$,.)89BCDERSVZbcdrsvzt") continue;
if (cChar == 'C' || cChar == 'c' || cChar == 'd' || cChar == 'D') {
if (i < sPicture.length()) {
char cNextChar = sPicture.charAt(i++);
if (!(cChar == 'C' && cNextChar != 'R' || cChar == 'c' && cNextChar != 'r' || cChar == 'd' && cNextChar != 'b') && (cChar != 'D' || cNextChar == 'B')) continue;
return false;
}
return false;
}
if (cChar != 'r' && cChar != 'R' && cChar != 'b' && cChar != 'B') continue;
return false;
}
}
return false;
}
return true;
}
public static boolean isSubPicture(String sPicture, int nPictIndex, StringBuilder sCategory, StringBuilder sLocale, StringBuilder sSubMask) {
String sSubCategory = "";
sCategory.setLength(0);
sSubMask.setLength(0);
int nPrevIndex = nPictIndex;
char cChar = sPicture.charAt(nPictIndex++);
if (PictureFmt.isCharAlphabetic(cChar)) {
int nLocaleEnd;
int nCategoryBeg = nPrevIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while (PictureFmt.isCharAlphabetic(sPicture.charAt(nPictIndex++))) {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
int nCategoryEnd = nPrevIndex;
int nLocaleBeg = nLocaleEnd = nPictIndex;
nPictIndex = nPrevIndex;
if ((cChar = sPicture.charAt(nPictIndex++)) == '.') {
int nSubCategoryBeg = nPictIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while ((cChar = sPicture.charAt(nPictIndex++)) != '(' && cChar != '{') {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
int nSubCategoryEnd = nPrevIndex;
sSubCategory = sPicture.substring(nSubCategoryBeg, nSubCategoryEnd);
}
if (cChar == '(') {
nLocaleBeg = nPictIndex;
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
while (sPicture.charAt(nPictIndex++) != ')') {
nPrevIndex = nPictIndex;
if (nPictIndex != sPicture.length()) continue;
return false;
}
nLocaleEnd = nPrevIndex;
cChar = sPicture.charAt(nPictIndex++);
}
if (cChar == '{') {
int nSubMaskBeg = nPictIndex;
do {
if (nPictIndex == sPicture.length()) {
return false;
}
nPrevIndex = nPictIndex;
if ((cChar = sPicture.charAt(nPictIndex++)) == '\'') {
int nIndex = PictureFmt.getLiteralSubstr(sPicture, cChar, nPictIndex, null);
if (nIndex == nPictIndex) {
return false;
}
nPictIndex = nIndex;
continue;
}
if (cChar == '}') break;
} while (true);
int nSubMaskEnd = nPrevIndex;
String sCandidate = sPicture.substring(nCategoryBeg, nCategoryEnd);
if (sCandidate.equals("null") || sCandidate.equals("zero") || sCandidate.equals("text")) {
sCategory.replace(0, sCategory.length(), sCandidate);
if (nLocaleEnd > nLocaleBeg) {
sLocale.replace(0, sLocale.length(), sPicture.substring(nLocaleBeg, nLocaleEnd));
}
sSubMask.replace(0, sSubMask.length(), sPicture.substring(nSubMaskBeg, nSubMaskEnd));
return true;
}
if (sCandidate.equals("date") || sCandidate.equals("time")) {
sCategory.replace(0, sCategory.length(), sCandidate);
if (nLocaleEnd > nLocaleBeg) {
sLocale.replace(0, sLocale.length(), sPicture.substring(nLocaleBeg, nLocaleEnd));
}
String sLoc = "en_US";
if (sLocale.length() != 0) {
sLoc = sLocale.toString();
}
String sFmt = null;
if (sSubCategory.length() == 0) {
sFmt = sPicture.substring(nSubMaskBeg, nSubMaskEnd);
} else if (sSubCategory.equals("short")) {
LcData oData = new LcData(sLoc);
sFmt = sCandidate.equals("date") ? oData.getDateFormat(1) : oData.getTimeFormat(1);
} else if (sSubCategory.equals("medium")) {
LcData oData = new LcData(sLoc);
sFmt = sCandidate.equals("date") ? oData.getDateFormat(2) : oData.getTimeFormat(2);
} else if (sSubCategory.equals("long")) {
LcData oData = new LcData(sLoc);
sFmt = sCandidate.equals("date") ? oData.getDateFormat(3) : oData.getTimeFormat(3);
} else if (sSubCategory.equals("full")) {
LcData oData = new LcData(sLoc);
sFmt = sCandidate.equals("date") ? oData.getDateFormat(4) : oData.getTimeFormat(4);
} else if (sSubCategory.equals("default")) {
LcData oData = new LcData(sLoc);
sFmt = sCandidate.equals("date") ? oData.getDateFormat(0) : oData.getTimeFormat(0);
} else {
return false;
}
sSubMask.replace(0, sSubMask.length(), sFmt);
if (sSubCategory.length() != 0) {
sCategory.append('.');
sCategory.append(sSubCategory);
}
return true;
}
if (sCandidate.equals("num")) {
sCategory.replace(0, sCategory.length(), sCandidate);
if (nLocaleEnd > nLocaleBeg) {
sLocale.replace(0, sLocale.length(), sPicture.substring(nLocaleBeg, nLocaleEnd));
}
String sLoc = "en_US";
if (sLocale.length() != 0) {
sLoc = sLocale.toString();
}
String sFmt = null;
if (sSubCategory.length() == 0) {
sFmt = sPicture.substring(nSubMaskBeg, nSubMaskEnd);
} else if (sSubCategory.equals("integer")) {
LcData oData = new LcData(sLoc);
int nOptn = 1;
sFmt = oData.getNumberFormat(0, nOptn);
} else if (sSubCategory.equals("decimal")) {
LcData oData = new LcData(sLoc);
int nOptn = LcData.withPrecision(-1) | 1;
sFmt = oData.getNumberFormat(1, nOptn);
} else if (sSubCategory.equals("currency")) {
LcData oData = new LcData(sLoc);
int nOptn = LcData.withPrecision(-1) | 1;
sFmt = oData.getNumberFormat(2, nOptn);
} else if (sSubCategory.equals("percent")) {
LcData oData = new LcData(sLoc);
int nOptn = 1;
sFmt = oData.getNumberFormat(3, nOptn);
} else {
return false;
}
sSubMask.replace(0, sSubMask.length(), sFmt);
if (sSubCategory.length() != 0) {
sCategory.append('.');
sCategory.append(sSubCategory);
}
return true;
}
if (sCandidate.equals("datetime")) {
int nCurly;
sCategory.replace(0, sCategory.length(), sCandidate);
if (nLocaleEnd > nLocaleBeg) {
sLocale.replace(0, sLocale.length(), sPicture.substring(nLocaleBeg, nLocaleEnd));
}
String sLoc = "en_US";
if (sLocale.length() != 0) {
sLoc = sLocale.toString();
}
String sFmt = null;
LcData oData = new LcData(sLoc);
int nOptn = 1;
if (sSubCategory.equals("short")) {
sFmt = oData.getDateTimeFormat(1, nOptn);
} else if (sSubCategory.equals("medium")) {
sFmt = oData.getDateTimeFormat(2, nOptn);
} else if (sSubCategory.equals("long")) {
sFmt = oData.getDateTimeFormat(3, nOptn);
} else if (sSubCategory.equals("full")) {
sFmt = oData.getDateTimeFormat(4, nOptn);
} else if (sSubCategory.equals("default")) {
sFmt = oData.getDateTimeFormat(0, nOptn);
} else {
return false;
}
sSubMask.replace(0, sSubMask.length(), sFmt);
if (sSubCategory.length() != 0) {
sCategory.append('.');
sCategory.append(sSubCategory);
}
if ((nCurly = sSubMask.indexOf("date{")) >= 0) {
sSubMask.insert(nCurly += 4, ')');
sSubMask.insert(nCurly, sLoc);
sSubMask.insert(nCurly, '(');
}
if ((nCurly = sSubMask.indexOf("time{")) >= 0) {
sSubMask.insert(nCurly += 4, ')');
sSubMask.insert(nCurly, sLoc);
sSubMask.insert(nCurly, '(');
}
return true;
}
}
}
return false;
}
public static boolean isTextPicture(String sPicture) {
return PictureFmt.isPicture(sPicture, "text", "9AO0Xt");
}
public static boolean isTextPictureValid(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder("en_US");
StringBuilder sPict = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCat, sLoc, sPict) || !sCat.toString().equals("text")) {
sPict.replace(0, sPict.length(), sPicture);
}
return true;
}
public static boolean isTimePicture(String sPicture) {
return PictureFmt.isPicture(sPicture, "time", "hkHKMSFAZzt");
}
public static boolean isTimePictureValid(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder("en_US");
StringBuilder sPict = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCat, sLoc, sPict) || !sCat.toString().equals("time")) {
sPict.replace(0, sPict.length(), sPicture);
}
LcTime now = new LcTime(1, sLoc.toString());
return now.parse(now.format(sPict.toString()), sPict.toString());
}
public static boolean isZeroPicture(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder();
StringBuilder sMask = new StringBuilder();
return PictureFmt.isSubPicture(sPicture, 0, sCat, sLoc, sMask) && sCat.toString().equals("zero");
}
public static boolean isZeroPictureValid(String sPicture) {
StringBuilder sCat = new StringBuilder();
StringBuilder sLoc = new StringBuilder("en_US");
StringBuilder sPict = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCat, sLoc, sPict) || !sCat.toString().equals("zero")) {
sPict.replace(0, sPict.length(), sPicture);
}
LcNum one = new LcNum("1", sLoc.toString());
return one.parse(one.format(sPict.toString(), null), sPict.toString());
}
public static boolean parseCompound(String sSource, String sPicture, String sLocale, StringHolder sResult) {
MsgFormatPos oMessage = new MsgFormatPos(ResId.UNSUPPORTED_OPERATION, "PictureFmt#parseCompound");
oMessage.format("parseCompound");
throw new ExFull(oMessage);
}
public static boolean parseDate(String sSource, String sPicture, String sLocale, StringHolder sResult, boolean bAsLocal) {
StringBuilder sLoc;
LcDate oDate;
StringBuilder sDateMask;
StringBuilder sCategory;
if (!StringUtils.isEmpty(sResult.value)) {
sResult.value = "";
}
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory = new StringBuilder(), sLoc = new StringBuilder(sLocale), sDateMask = new StringBuilder()) && !sCategory.toString().equals("date")) {
sDateMask.replace(0, sDateMask.length(), sPicture);
}
if ((oDate = new LcDate(sSource, sDateMask.toString(), sLoc.toString(), 30)).isValid()) {
ISODate oISODate = new ISODate(oDate.getDays());
if (bAsLocal) {
oISODate.setLocalDate();
}
sResult.value = oISODate.format("YYYY-MM-DD");
}
return !StringUtils.isEmpty(sResult.value);
}
public static boolean parseDateTime(String sSource, String sPicture, String sDateMask, String sTimeMask, String sLocale, StringHolder sResult, boolean bAsLocal) {
String sInfixMask;
String sPrefixMask;
Point p;
int nAt;
String sPostfixMask;
int nInfixSourceStart;
boolean bDateFirst = false;
int nDateFound = sPicture.indexOf(sDateMask);
assert (nDateFound >= 0);
int nTimeFound = sPicture.indexOf(sTimeMask);
assert (nTimeFound >= 0);
boolean bl = bDateFirst = nDateFound < nTimeFound;
if (bDateFirst) {
p = PictureFmt.resolveRange(sPicture, 0, nDateFound);
sPrefixMask = sPicture.substring(p.x, p.y);
p = PictureFmt.resolveRange(sPicture, nDateFound + sDateMask.length(), nTimeFound);
sInfixMask = sPicture.substring(p.x, p.y);
p = PictureFmt.resolveRange(sPicture, nTimeFound + sTimeMask.length(), sPicture.length());
sPostfixMask = sPicture.substring(p.x, p.y);
} else {
p = PictureFmt.resolveRange(sPicture, 0, nTimeFound);
sPrefixMask = sPicture.substring(p.x, p.y);
p = PictureFmt.resolveRange(sPicture, nTimeFound + sTimeMask.length(), nDateFound);
sInfixMask = sPicture.substring(p.x, p.y);
p = PictureFmt.resolveRange(sPicture, nDateFound + sDateMask.length(), sPicture.length());
sPostfixMask = sPicture.substring(p.x, p.y);
}
LcDate oPrefixData = new LcDate(sLocale, 30);
String sPrefixMaskData = oPrefixData.format(sPrefixMask);
LcDate oInfixData = new LcDate(sLocale, 30);
String sInfixMaskData = oInfixData.format(sInfixMask);
LcDate oPostfixData = new LcDate(sLocale, 30);
String sPostfixMaskData = oPostfixData.format(sPostfixMask);
int nInfixFound = 0;
if (sInfixMaskData.length() != 0) {
int nAt2;
int nStart = 0;
while ((nAt2 = sSource.indexOf(sInfixMaskData, nStart)) >= 0) {
nInfixSourceStart = nAt2;
nStart = nAt2 + sInfixMaskData.length();
++nInfixFound;
}
}
if (nInfixFound == 0) {
int nTimeSourceStart;
int nDateSourceStart;
int nPostfixSourceStart;
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sCategory = new StringBuilder();
StringBuilder sDateSubMask = new StringBuilder();
StringBuilder sTimeSubMask = new StringBuilder();
PictureFmt.isSubPicture(sDateMask, 0, sCategory, sLoc, sDateSubMask);
LcDate oToday = new LcDate(1, sLoc.toString(), 30);
String sDateMaskData = oToday.format(sDateSubMask.toString());
sLoc.replace(0, sLoc.length(), sLocale);
PictureFmt.isSubPicture(sTimeMask, 0, sCategory, sLoc, sTimeSubMask);
LcTime oNow = new LcTime(3661001, sLoc.toString());
String sTimeMaskData = oNow.format(sTimeSubMask.toString());
if (bDateFirst) {
nDateSourceStart = sPrefixMaskData.length();
nInfixSourceStart = nDateSourceStart + sDateMaskData.length();
nTimeSourceStart = nInfixSourceStart + sInfixMaskData.length();
nPostfixSourceStart = nTimeSourceStart + sTimeMaskData.length();
} else {
nTimeSourceStart = sPrefixMaskData.length();
nInfixSourceStart = nTimeSourceStart + sTimeMaskData.length();
nDateSourceStart = nInfixSourceStart + sInfixMaskData.length();
nPostfixSourceStart = nDateSourceStart + sDateMaskData.length();
}
Point p2 = PictureFmt.resolveRange(sSource, 0, sPrefixMaskData.length());
String sPrefixSource = sSource.substring(p2.x, p2.y);
p2 = PictureFmt.resolveRange(sSource, nDateSourceStart, nDateSourceStart + sDateMaskData.length());
String sDateSource = sSource.substring(p2.x, p2.y);
p2 = PictureFmt.resolveRange(sSource, nInfixSourceStart, nInfixSourceStart + sInfixMaskData.length());
String sInfixSource = sSource.substring(p2.x, p2.y);
p2 = PictureFmt.resolveRange(sSource, nTimeSourceStart, nTimeSourceStart + sTimeMaskData.length());
String sTimeSource = sSource.substring(p2.x, p2.y);
p2 = PictureFmt.resolveRange(sSource, nPostfixSourceStart, sSource.length());
String sPostfixSource = sSource.substring(p2.x, p2.y);
if (!sPrefixSource.equals(sPrefixMaskData)) {
return false;
}
if (!sPostfixSource.equals(sPostfixMaskData)) {
return false;
}
if (!sInfixSource.equals(sInfixMaskData)) {
return false;
}
StringHolder sParsedDate = new StringHolder();
if (!PictureFmt.parseDate(sDateSource, sDateMask, sLocale, sParsedDate, bAsLocal)) {
return false;
}
StringHolder sParsedTime = new StringHolder();
if (!PictureFmt.parseTime(sTimeSource, sTimeMask, sLocale, sParsedTime, bAsLocal)) {
return false;
}
sResult.value = sParsedDate.value + 'T' + sParsedTime.value;
return true;
}
int nStart = 0;
while ((nAt = sSource.indexOf(sInfixMaskData, nStart)) >= 0) {
int nDateSourceStart;
String sTimeSource;
StringHolder sParsedTime;
StringHolder sParsedDate;
Point p3;
String sDateSource;
int nTimeSourceStart;
nInfixSourceStart = nAt;
int nPostfixSourceStart = sSource.length() - sPostfixMaskData.length();
if (bDateFirst) {
nDateSourceStart = sPrefixMaskData.length();
p3 = PictureFmt.resolveRange(sSource, nDateSourceStart, nInfixSourceStart);
sDateSource = sSource.substring(p3.x, p3.y);
nTimeSourceStart = nInfixSourceStart + sInfixMaskData.length();
p3 = PictureFmt.resolveRange(sSource, nTimeSourceStart, nPostfixSourceStart);
sTimeSource = sSource.substring(p3.x, p3.y);
} else {
nTimeSourceStart = sPrefixMaskData.length();
p3 = PictureFmt.resolveRange(sSource, nTimeSourceStart, nInfixSourceStart);
sTimeSource = sSource.substring(p3.x, p3.y);
nDateSourceStart = nInfixSourceStart + sInfixMaskData.length();
p3 = PictureFmt.resolveRange(sSource, nDateSourceStart, nPostfixSourceStart);
sDateSource = sSource.substring(p3.x, p3.y);
}
p3 = PictureFmt.resolveRange(sSource, 0, sPrefixMaskData.length());
String sPrefixSource = sSource.substring(p3.x, p3.y);
p3 = PictureFmt.resolveRange(sSource, nInfixSourceStart, nInfixSourceStart + sInfixMaskData.length());
String sInfixSource = sSource.substring(p3.x, p3.y);
p3 = PictureFmt.resolveRange(sSource, nPostfixSourceStart, sSource.length());
String sPostfixSource = sSource.substring(p3.x, p3.y);
if (sPrefixSource.equals(sPrefixMaskData) && sPostfixSource.equals(sPostfixMaskData) && sInfixSource.equals(sInfixMaskData) && PictureFmt.parseDate(sDateSource, sDateMask, sLocale, sParsedDate = new StringHolder(), bAsLocal) && PictureFmt.parseTime(sTimeSource, sTimeMask, sLocale, sParsedTime = new StringHolder(), bAsLocal)) {
sResult.value = sParsedDate.value + 'T' + sParsedTime.value;
return true;
}
nStart = nAt + sInfixMaskData.length();
}
return false;
}
public static boolean parseNull(String sSource, String sPicture, String sLocale, StringHolder sResult) {
LcNum oNum;
sResult.value = "";
StringBuilder sCategory = new StringBuilder();
StringBuilder sLoc = new StringBuilder(sLocale);
StringBuilder sNullMask = new StringBuilder();
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory, sLoc, sNullMask) && !sCategory.toString().equals("null")) {
sNullMask.replace(0, sNullMask.length(), sPicture);
}
if ((oNum = new LcNum(sSource, sNullMask.toString(), sLoc.toString())).isValid()) {
sResult.value = null;
}
return sResult.value == null;
}
public static boolean parseNumeric(String sSource, String sPicture, String sLocale, StringHolder sResult) {
StringBuilder sLoc;
StringBuilder sCategory;
LcNum oNum;
StringBuilder sNumMask;
if (!StringUtils.isEmpty(sResult.value)) {
sResult.value = "";
}
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory = new StringBuilder(), sLoc = new StringBuilder(sLocale), sNumMask = new StringBuilder()) && !sCategory.toString().equals("num")) {
sNumMask.replace(0, sNumMask.length(), sPicture);
}
if ((oNum = new LcNum(sSource, sNumMask.toString(), sLoc.toString())).isValid()) {
sResult.value = oNum.getText();
}
return !StringUtils.isEmpty(sResult.value);
}
public static boolean parseText(String sSource, String sPicture, String sLocale, StringHolder sResult) {
StringBuilder sLoc;
StringBuilder sCategory;
StringBuilder sTextMask;
LcText oText;
if (!StringUtils.isEmpty(sResult.value)) {
sResult.value = "";
}
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory = new StringBuilder(), sLoc = new StringBuilder(sLocale), sTextMask = new StringBuilder()) && !sCategory.toString().equals("text")) {
sTextMask.replace(0, sTextMask.length(), sPicture);
}
if ((oText = new LcText(sSource, sTextMask.toString(), sLoc.toString())).isValid()) {
sResult.value = oText.getText();
}
return !StringUtils.isEmpty(sResult.value);
}
public static boolean parseTime(String sSource, String sPicture, String sLocale, StringHolder sResult, boolean bAsLocal) {
StringBuilder sLoc;
LcTime oTime;
StringBuilder sTimeMask;
StringBuilder sCategory;
if (!StringUtils.isEmpty(sResult.value)) {
sResult.value = "";
}
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory = new StringBuilder(), sLoc = new StringBuilder(sLocale), sTimeMask = new StringBuilder()) && !sCategory.toString().equals("time")) {
sTimeMask.replace(0, sTimeMask.length(), sPicture);
}
if ((oTime = new LcTime(sSource, sTimeMask.toString(), sLoc.toString())).isValid()) {
ISOTime oISOTime = new ISOTime(oTime.getMillis());
if (bAsLocal) {
oISOTime.setLocalTime();
}
sResult.value = oISOTime.getMilliSecond() > 0 ? oISOTime.format("HH:MM:SS.FFF") : (oISOTime.getSecond() > 0 ? oISOTime.format("HH:MM:SS") : (oISOTime.getMinute() > 0 ? oISOTime.format("HH:MM") : oISOTime.format("HH")));
}
return !StringUtils.isEmpty(sResult.value);
}
public static boolean parseZero(String sSource, String sPicture, String sLocale, StringHolder sResult) {
StringBuilder sLoc;
StringBuilder sCategory;
StringBuilder sZeroMask;
LcNum oNum;
if (!StringUtils.isEmpty(sResult.value)) {
sResult.value = "";
}
if (!PictureFmt.hasSubPicture(sPicture, 0, sCategory = new StringBuilder(), sLoc = new StringBuilder(sLocale), sZeroMask = new StringBuilder()) && !sCategory.toString().equals("zero")) {
sZeroMask.replace(0, sZeroMask.length(), sPicture);
}
if ((oNum = new LcNum(sSource, sZeroMask.toString(), sLoc.toString())).isValid() && oNum.getValue() == 0.0) {
sResult.value = "0";
}
return !StringUtils.isEmpty(sResult.value);
}
private static int getLiteralSubstr(String sPicture, char cChar, int nCharPos, StringBuilder sLiteral) {
assert (cChar == '\'');
int nFoundPos = nCharPos;
int nPos = 0;
int nQuoteBeg = nCharPos;
int nQuoteEnd = sPicture.length() - 1;
int nStart = nPos = nCharPos;
while ((nPos = sPicture.indexOf(cChar, nStart)) >= 0 && nPos + 1 != sPicture.length() && sPicture.charAt(nPos + 1) == cChar) {
nStart = nPos + 2;
}
if (nPos > nCharPos) {
nQuoteEnd = nPos;
nFoundPos = nPos + 1;
if (sLiteral != null) {
sLiteral.append(sPicture, nQuoteBeg, nQuoteEnd);
}
}
return nFoundPos;
}
}