LcData.java
36.9 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.ut;
import com.adobe.xfa.ut.LcLocale;
import com.adobe.xfa.ut.StringUtils;
import com.adobe.xfa.ut.lcdata.LcBundle;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class LcData {
public static final int SUN = 0;
public static final int MON = 1;
public static final int TUE = 2;
public static final int WED = 3;
public static final int THU = 4;
public static final int FRI = 5;
public static final int SAT = 6;
public static final int JAN = 0;
public static final int FEB = 1;
public static final int MAR = 2;
public static final int APR = 3;
public static final int MAY = 4;
public static final int JUN = 5;
public static final int JUL = 6;
public static final int AUG = 7;
public static final int SEP = 8;
public static final int OCT = 9;
public static final int NOV = 10;
public static final int DEC = 11;
public static final int AM = 0;
public static final int PM = 1;
public static final int BC = 0;
public static final int AD = 1;
public static final int DEFLT = 2;
public static final int FULL = 0;
public static final int LONG = 1;
public static final int MED = 2;
public static final int SHORT = 3;
public static final int NUMERIC = 0;
public static final int CURRENCY = 1;
public static final int PERCENT = 2;
public static final int NUM_DECIMAL = 0;
public static final int NUM_GROUPING = 1;
public static final int NUM_PERCENT = 2;
public static final int NUM_MINUS = 3;
public static final int NUM_ZERO = 4;
public static final int CUR_SYMBOL = 0;
public static final int CUR_ISONAME = 1;
public static final int CUR_DECIMAL = 2;
public static final int DEFLT_FMT = 0;
public static final int SHORT_FMT = 1;
public static final int MED_FMT = 2;
public static final int LONG_FMT = 3;
public static final int FULL_FMT = 4;
public static final int INTEGRAL_FMT = 0;
public static final int DECIMAL_FMT = 1;
public static final int CURRENCY_FMT = 2;
public static final int PERCENT_FMT = 3;
public static final int WITHOUT_RADIX = 0;
public static final int WITHOUT_GROUPINGS = 0;
public static final int WITH_GROUPINGS = 1;
public static final int WITH_ZEDS = 0;
public static final int WITH_EIGHTS = 2;
public static final int WITH_RADIX = 4;
public static final int KEEP_NINES = 8;
public static final int WITHOUT_CATEGORIES = 0;
public static final int WITH_CATEGORIES = 1;
private static final int MAX_DBL_DIG = 18;
private static final int MAX_INT_DIG = 10;
private static final int MAX_DBL_WIDTH = 15;
private static final String gpDateMask = "GYMD EJFwW ";
private static final String gpTimeMask = " KHMSF AhkZz";
private static final ThreadLocal<Map<String, LcRunTimeData>> mRuntimeMap = new ThreadLocal<Map<String, LcRunTimeData>>(){
@Override
protected Map<String, LcRunTimeData> initialValue() {
return new HashMap<String, LcRunTimeData>();
}
};
private static final String[] gLocaleList = new String[]{"ar", "ar_AE", "ar_BH", "ar_DZ", "ar_EG", "ar_IQ", "ar_JO", "ar_KW", "ar_LB", "ar_LY", "ar_MA", "ar_OM", "ar_QA", "ar_SA", "ar_SD", "ar_SY", "ar_TN", "ar_YE", "az", "az_AZ", "az_Cyrl", "az_Cyrl_AZ", "az_Latn", "az_Latn_AZ", "be", "be_BY", "bg", "bg_BG", "bs", "bs_BA", "c", "ca", "ca_ES", "cs", "cs_CZ", "da", "da_DK", "de", "de_AT", "de_BE", "de_CH", "de_DE", "de_LI", "de_LU", "el", "el_GR", "en", "en_AU", "en_BE", "en_CA", "en_GB", "en_GB_EURO", "en_HK", "en_IE", "en_IN", "en_IN_RUPEE", "en_NZ", "en_PH", "en_SG", "en_US", "en_US_POSIX", "en_VI", "en_ZA", "es", "es_AR", "es_BO", "es_CL", "es_CO", "es_CR", "es_DO", "es_EC", "es_ES", "es_GT", "es_HN", "es_MX", "es_NI", "es_PA", "es_PE", "es_PR", "es_PY", "es_SV", "es_US", "es_UY", "es_VE", "et", "et_EE", "eu", "eu_ES", "fa", "fa_IR", "fi", "fi_FI", "fr", "fr_BE", "fr_CA", "fr_CH", "fr_FR", "fr_LU", "he", "he_IL", "hi", "hi_IN", "hr", "hr_HR", "hu", "hu_HU", "hy", "hy_AM", "id", "id_ID", "is", "is_IS", "it", "it_CH", "it_IT", "ja", "ja_JP", "kk", "kk_KZ", "km", "km_KH", "ko", "ko_KR", "ko_KR_HANI", "lo", "lo_LA", "lt", "lt_LT", "lv", "lv_LV", "mk", "mk_MK", "ms", "ms_MY", "nb", "nb_NO", "nl", "nl_BE", "nl_NL", "nn", "nn_NO", "no", "no_NO", "no_NO_NY", "pl", "pl_PL", "pt", "pt_BR", "pt_PT", "ro", "ro_RO", "root", "ru", "ru_RU", "ru_UA", "sh", "sh_BA", "sh_CS", "sh_HR", "sk", "sk_SK", "sl", "sl_SI", "sq", "sq_AL", "sr", "sr_CS", "sr_Cyrl", "sr_Cyrl_CS", "sr_Latn", "sr_Latn_CS", "sv", "sv_FI", "sv_SE", "th", "th_TH", "th_TH_TH", "tl", "tl_PH", "tr", "tr_TR", "uk", "uk_UA", "vi", "vi_VN", "zh", "zh_CN", "zh_Hans", "zh_Hans_CN", "zh_Hans_SG", "zh_Hant", "zh_Hant_HK", "zh_Hant_TW", "zh_HK", "zh_SG", "zh_TW"};
private static final Map<String, String>[] staticData = new Map[gLocaleList.length];
private static final int[] staticParentIndex = new int[gLocaleList.length];
private static final int numAliases = 6;
private static final int[] aliasFromIndex = new int[6];
private static final int[] aliasToIndex = new int[6];
private static final int rootIndex = LcData.localeIndex("root");
private final String msLocale;
private final int mnIndex;
private static final PropertyRetriever<String> retrieveWeekdayNameProperty;
private static final PropertyRetriever<String> retrieveAbbrWeekdayNameProperty;
private static final PropertyRetriever<String> retrieveMonthNameProperty;
private static final PropertyRetriever<String> retrieveMonthAbbrNamesProperty;
private static final PropertyRetriever<String> retrieveMeridiemNameProperty;
private static final PropertyRetriever<String> retrieveEraNameProperty;
private static final PropertyRetriever<String> retrieveDatePatternProperty;
private static final PropertyRetriever<String> retrieveTimePatternProperty;
private static final PropertyRetriever<String> retrieveDateTimeSymbolsProperty;
private static final PropertyRetriever<String> retrieveDateTimeFormatProperty;
private static final PropertyRetriever<String> retrieveNumberPatternProperty;
private static final PropertyRetriever<String> retrieveCurrencySymbolProperty;
private static final PropertyRetriever<String> retrieveNumericSymbolProperty;
private static final PropertyRetriever<List<String>> retrieveTypefaceListProperty;
public static final int withWidth(int width) {
return width << 16;
}
public static final int withPrecision(int prec) {
return (prec & 255) << 8;
}
private static int localeIndex(String sLocaleName) {
return Arrays.binarySearch(gLocaleList, sLocaleName, String.CASE_INSENSITIVE_ORDER);
}
private static void initParentIndex(String sLocaleName, int parentIndex) {
int index = LcData.localeIndex(sLocaleName);
LcData.staticParentIndex[index] = parentIndex;
}
private static void initScriptAlias(int index, String sLocaleName, String sRealLocaleName) {
LcData.aliasFromIndex[index] = LcData.localeIndex(sLocaleName);
LcData.aliasToIndex[index] = LcData.localeIndex(sRealLocaleName);
}
private static int mapLocaleIndexToAlias(int localeIndex) {
for (int i = 0; i < 6; ++i) {
if (aliasFromIndex[i] != localeIndex) continue;
return aliasToIndex[i];
}
return localeIndex;
}
public LcData(String locale) {
int localeIndex = LcData.localeIndex(locale);
if (localeIndex >= 0) {
locale = gLocaleList[localeIndex];
localeIndex = LcData.mapLocaleIndexToAlias(localeIndex);
} else {
String sLocaleName = locale = LcLocale.normalize(locale);
do {
if ((localeIndex = LcData.localeIndex(sLocaleName)) >= 0) {
localeIndex = LcData.mapLocaleIndexToAlias(localeIndex);
break;
}
if (localeIndex == -1) {
localeIndex = rootIndex;
break;
}
int delim = sLocaleName.lastIndexOf(95);
if (delim == -1) {
localeIndex = rootIndex;
break;
}
sLocaleName = sLocaleName.substring(0, delim);
} while (true);
}
assert (localeIndex >= 0);
this.msLocale = locale;
this.mnIndex = localeIndex;
}
private static Map<String, String> getStaticData(int staticDataIndex) {
Map<String, String> result = staticData[staticDataIndex];
if (result == null) {
result = LcData.loadStaticData(gLocaleList[staticDataIndex]);
assert (result != null);
LcData.staticData[staticDataIndex] = result;
}
return result;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private static Map<String, String> loadStaticData(String sLocale) {
if (sLocale.equals("root")) {
sLocale = "";
}
String resourceName = "com/adobe/xfa/ut/lcdata/Locale" + (sLocale.length() == 0 ? "" : Character.valueOf('_')) + sLocale + ".properties";
InputStream stream = LcData.class.getClassLoader().getResourceAsStream(resourceName);
Properties properties = new Properties();
try {
properties.load(stream);
}
catch (IOException ignored) {
assert (false);
Map<String, String> map = null;
return map;
}
finally {
try {
stream.close();
}
catch (IOException streamCantBeClosedException) {}
stream = null;
}
HashMap<String, String> staticData = new HashMap<String, String>(properties.size());
Enumeration keys = properties.keys();
while (keys.hasMoreElements()) {
String key = (String)keys.nextElement();
staticData.put(key, (String)properties.get(key));
}
return staticData;
}
public String getLocale() {
return this.msLocale;
}
public static boolean validate(LcRunTimeData oLcData) {
String decimal = oLcData.numericSymbols[0];
if (decimal != null && decimal.equals(oLcData.numericSymbols[2])) {
return false;
}
return true;
}
public static void reset() {
LcData.getMap().clear();
}
public static void update(LcRunTimeData oLcData) {
Map<String, LcRunTimeData> map = LcData.getMap();
map.put(oLcData.localeName, oLcData);
}
public static LcRunTimeData get(String sLocale) {
LcRunTimeData oRunTimeData = LcData.getMap().get(sLocale);
if (oRunTimeData == null) {
oRunTimeData = new LcRunTimeData(sLocale);
}
return oRunTimeData;
}
public String getWeekDayName(int weekday) {
if (weekday < 0 || weekday > 6) {
assert (false);
return "";
}
return this.searchRuntimeThenStaticStore(weekday, retrieveWeekdayNameProperty);
}
public String getAbbrWeekdayName(int weekday) {
if (weekday < 0 || weekday > 6) {
assert (false);
return "";
}
return this.searchRuntimeThenStaticStore(weekday, retrieveAbbrWeekdayNameProperty);
}
public String getMonthName(int month) {
if (month < 0 || month > 11) {
assert (false);
return "";
}
return this.searchRuntimeThenStaticStore(month, retrieveMonthNameProperty);
}
public String getAbbrMonthName(int month) {
if (month < 0 || month > 11) {
assert (false);
return "";
}
return this.searchRuntimeThenStaticStore(month, retrieveMonthAbbrNamesProperty);
}
public String getMeridiemName(int aspect) {
if (aspect < 0 || aspect > 1) {
assert (false);
return "";
}
return this.searchRuntimeThenStaticStore(aspect, retrieveMeridiemNameProperty);
}
public String getEraName(int era) {
if (era < 0 || era > 1) {
assert (false);
return "";
}
return this.searchRuntimeThenStaticStore(era, retrieveEraNameProperty);
}
public String getDateFormat(int style) {
if (style < 0 || style > 4) {
style = 2;
}
if (style == 0) {
style = 2;
}
return this.searchRuntimeThenStaticStore(4 - style, retrieveDatePatternProperty);
}
public String getTimeFormat(int style) {
if (style < 0 || style > 4) {
style = 2;
}
if (style == 0) {
style = 2;
}
return this.searchRuntimeThenStaticStore(4 - style, retrieveTimePatternProperty);
}
public String getDateTimePattern() {
return this.searchRuntimeThenStaticStore(0, retrieveDateTimeSymbolsProperty);
}
public String getDateTimeFormat(int style, int type) {
if (style < 0 || 4 < style) {
style = 2;
}
StringBuilder sDateTimeFmt = new StringBuilder(this.searchStaticStore(0, retrieveDateTimeFormatProperty));
if (type == 0) {
String sDateFmt = this.getDateFormat(style);
String sTimeFmt = this.getTimeFormat(style);
int nPat = sDateTimeFmt.indexOf("date{}");
if (nPat >= 0) {
sDateTimeFmt.replace(nPat, nPat + 6, sDateFmt);
}
if ((nPat = sDateTimeFmt.indexOf("time{}")) >= 0) {
sDateTimeFmt.replace(nPat, nPat + 6, sTimeFmt);
}
} else if (type == 1) {
String sDateFmt = this.getDateFormat(style);
String sTimeFmt = this.getTimeFormat(style);
int nPat = sDateTimeFmt.indexOf("date{}");
if (nPat >= 0) {
sDateTimeFmt.insert(nPat + 5, sDateFmt);
}
if ((nPat = sDateTimeFmt.indexOf("time{}")) >= 0) {
sDateTimeFmt.insert(nPat + 5, sTimeFmt);
}
}
return sDateTimeFmt.toString();
}
public String getLocalDateFormat(int style) {
String date = this.getDateFormat(style);
if (StringUtils.isEmpty(date)) {
return "";
}
String pattern = this.getDateTimePattern();
return LcData.xlate(date, pattern, "GYMD EJFwW ");
}
public String getLocalTimeFormat(int style) {
String time = this.getTimeFormat(style);
if (StringUtils.isEmpty(time)) {
return "";
}
String pattern = this.getDateTimePattern();
return LcData.xlate(time, pattern, " KHMSF AhkZz");
}
public String getLocalDateTimeFormat() {
return "";
}
public String getNumericFormat(int style) {
if (style < 0 || style > 2) {
assert (false);
return "";
}
return this.searchRuntimeThenStaticStore(style, retrieveNumberPatternProperty);
}
public String getNumberFormat(int style, int option) {
StringBuilder sFormat;
int nBar;
int nTrim;
if (style < 0 || style > 3) {
style = 1;
}
if ((nBar = (sFormat = new StringBuilder(this.getNumericFormat(style > 0 ? style - 1 : style))).indexOf("|")) >= 0) {
sFormat.delete(0, nBar + 1);
}
String[] dotChars = new String[]{".", "v", "V", "E", " ", "%"};
int nDot = -1;
for (int i = 0; i < dotChars.length && (nDot = sFormat.indexOf(dotChars[i])) < 0; ++i) {
}
if (nDot < 0) {
nDot = sFormat.length();
} else if (StringUtils.skipOver(sFormat, "89zZ", nDot - 1) != 1) {
nDot = sFormat.length();
}
StringBuilder sZZZ = new StringBuilder();
int nZed = sFormat.indexOf("z,");
if (nZed >= 0) {
int nSep = nDot;
int nComma = sFormat.indexOf(",", nZed + 2);
if (nComma >= 0) {
nSep = nComma;
}
if (nSep > nZed + 2) {
int n = nSep - nZed - 1;
for (int i2 = 1; i2 <= n; ++i2) {
sZZZ.append('z');
}
} else {
sZZZ.append('z');
}
} else {
nZed = 0;
}
int nPrec = 0;
int nWidth = 10;
if (style != 0) {
boolean trim;
nPrec = option >> 8 & 255;
boolean bl = trim = (nPrec & 128) == 0;
if ((nPrec &= 127) == 127) {
nPrec = StringUtils.skipOver(sFormat, "89zZ", nDot + 1);
}
nWidth = (option & 16711680) != 0 ? option >> 16 & 255 : 18;
if (sFormat.indexOf("s") >= 0) {
++nWidth;
}
if (sFormat.indexOf("(") >= 0) {
++nWidth;
}
if (sFormat.indexOf(")") >= 0) {
++nWidth;
}
int nFmtPrec = StringUtils.skipOver(sFormat, "89zZ", nDot + 1);
if (0 < nPrec && nPrec < nFmtPrec) {
nWidth += nFmtPrec - nPrec;
}
if (trim && nPrec > 0 && nWidth > nPrec) {
if (nPrec <= sFormat.length() - 1 - nDot) {
nWidth += sFormat.length() - 1 - nDot - nPrec;
}
for (int i3 = nWidth - 1; i3 > 15 && nPrec > sFormat.length() - 1 - nDot; --nPrec, --i3) {
}
}
}
if (style == 2) {
if (sFormat.indexOf("$") >= 0) {
++nWidth;
}
if (sFormat.indexOf(" ") >= 0) {
++nWidth;
}
}
if (style == 3) {
nTrim = StringUtils.skipOver(sFormat, "89zZ", nDot + 1);
if (nDot < sFormat.length()) {
sFormat.replace(nDot + 1, nDot + 1 + nTrim, "");
}
if (sFormat.indexOf("%") >= 0) {
++nWidth;
}
} else if (style == 0 || nPrec == 0 && (option & 4) == 0) {
nTrim = StringUtils.skipOver(sFormat, "89zZ", nDot + 1);
if (nDot < sFormat.length()) {
sFormat.replace(nDot, nDot + nTrim + 1, "");
}
} else if ((option & 2) == 2) {
int nEight = nDot + 1;
while ((nEight = sFormat.indexOf("z", nEight)) >= 0) {
sFormat.setCharAt(nEight, '8');
}
while (sFormat.length() - nDot <= nPrec) {
sFormat.insert(nDot + 1, '8');
}
} else if ((option & 2) == 0 && (option & 8) != 8) {
int nNine = nDot + 1;
while ((nNine = sFormat.indexOf("9", nNine)) >= 0) {
sFormat.setCharAt(nNine, 'z');
}
while (sFormat.length() - nDot <= nPrec) {
sFormat.insert(nDot + 1, 'z');
}
}
if (StringUtils.isEmpty(sZZZ)) {
sZZZ.append('z');
} else if ((option & 1) == 0) {
int nComma = nZed + 1;
sFormat.setCharAt(nComma, 'z');
while ((nComma = sFormat.indexOf(",", nComma)) >= 0 && nComma < nDot) {
sFormat.setCharAt(nComma, '8');
}
} else if ((option & 1) == 1) {
sZZZ.setCharAt(0, ',');
nWidth += (nWidth + sZZZ.length()) / sZZZ.length();
}
while (sFormat.length() < nWidth) {
sFormat.insert(nZed + 1, sZZZ);
}
return sFormat.toString();
}
public int getNumberPrecision(String sVal) {
int nRadix = sVal.indexOf(this.getRadixSymbol());
if (nRadix >= 0) {
return sVal.length() - nRadix - 1;
}
return 0;
}
private <T> T searchRuntimeStore(int key, PropertyRetriever<T> retriever) {
Map<String, LcRunTimeData> runtimeMap = mRuntimeMap.get();
if (runtimeMap.size() == 0) {
return null;
}
String sLocaleName = this.msLocale;
int staticIndex = -1;
do {
T value;
LcRunTimeData lcData;
if ((lcData = runtimeMap.get(sLocaleName)) != null && (value = retriever.retrieveRuntime(lcData, key)) != null) {
return value;
}
if (staticIndex >= 0) {
int parentIndex = staticParentIndex[staticIndex];
if (parentIndex < 0) break;
sLocaleName = gLocaleList[parentIndex];
staticIndex = parentIndex;
continue;
}
int delim = sLocaleName.lastIndexOf(95);
if (delim == -1) {
if (sLocaleName.equals("root")) break;
sLocaleName = "root";
staticIndex = rootIndex;
continue;
}
staticIndex = LcData.localeIndex(sLocaleName = sLocaleName.substring(0, delim));
if (staticIndex < 0) continue;
staticIndex = LcData.mapLocaleIndexToAlias(staticIndex);
} while (true);
return null;
}
private <T> T searchStaticStore(int key, PropertyRetriever<T> retriever) {
int staticDataIndex = this.mnIndex;
do {
Map<String, String> lcData;
T value;
if ((value = retriever.retrieveStatic(lcData = LcData.getStaticData(staticDataIndex), key)) == null) continue;
return value;
} while ((staticDataIndex = staticParentIndex[staticDataIndex]) != -1);
assert (false);
return null;
}
private <T> T searchRuntimeThenStaticStore(int key, PropertyRetriever<T> retriever) {
T value = this.searchRuntimeStore(key, retriever);
if (value != null) {
return value;
}
return this.searchStaticStore(key, retriever);
}
public String getCurrencyName() {
return this.searchRuntimeThenStaticStore(1, retrieveCurrencySymbolProperty);
}
public String getCurrencySymbol() {
return this.searchRuntimeThenStaticStore(0, retrieveCurrencySymbolProperty);
}
public String getCurrencyRadix() {
return this.searchRuntimeThenStaticStore(2, retrieveCurrencySymbolProperty);
}
public String getRadixSymbol() {
return this.searchRuntimeThenStaticStore(0, retrieveNumericSymbolProperty);
}
public String getGroupingSymbol() {
return this.searchRuntimeThenStaticStore(1, retrieveNumericSymbolProperty);
}
public String getPercentSymbol() {
return this.searchRuntimeThenStaticStore(2, retrieveNumericSymbolProperty);
}
public List<String> getTypefaces() {
List typefaces = this.searchRuntimeThenStaticStore(0, retrieveTypefaceListProperty);
if (typefaces == null) {
typefaces = Collections.emptyList();
}
return typefaces;
}
public String getNegativeSymbol() {
return this.searchRuntimeThenStaticStore(3, retrieveNumericSymbolProperty);
}
public String getZeroSymbol() {
return this.searchRuntimeThenStaticStore(4, retrieveNumericSymbolProperty);
}
public String getPositiveSymbol() {
return "+";
}
public static void getLocaleNames(List<String> oLocales) {
oLocales.addAll(LcData.getMap().keySet());
for (int i = 0; i < gLocaleList.length; ++i) {
oLocales.add(gLocaleList[i]);
}
}
public static String findMatchingLocale(String sCurrencySymbol, String sRadixSymbol, String sGroupingSymbol) {
String dflt = LcLocale.getLocale();
if (LcData.testMatchingLocale(dflt, sCurrencySymbol, sRadixSymbol, sGroupingSymbol)) {
return dflt;
}
for (int i = 0; i < gLocaleList.length; ++i) {
String locale = gLocaleList[i];
if (!LcData.testMatchingLocale(locale, sCurrencySymbol, sRadixSymbol, sGroupingSymbol)) continue;
return locale;
}
return "";
}
private static boolean testMatchingLocale(String locale, String sCurrencySymbol, String sRadixSymbol, String sGroupingSymbol) {
LcData oData = new LcData(locale);
if (!StringUtils.isEmpty(sCurrencySymbol) && !oData.getCurrencySymbol().equals(sCurrencySymbol)) {
return false;
}
if (!StringUtils.isEmpty(sRadixSymbol) && !oData.getRadixSymbol().equals(sRadixSymbol)) {
return false;
}
if (!StringUtils.isEmpty(sGroupingSymbol) && !oData.getGroupingSymbol().equals(sGroupingSymbol)) {
return false;
}
return true;
}
private static String xlate(String pPat, String pLocal, String pMask) {
StringBuilder sBuf = new StringBuilder();
char prevChr = '\u0000';
int chrCnt = 0;
boolean inQuoted = false;
boolean inQuoteQuoted = false;
int nPatLen = pPat.length();
for (int i = 0; i < nPatLen; ++i) {
char c;
char chr = pPat.charAt(i);
if (inQuoteQuoted) {
if (chr == '\'') {
chrCnt = 0;
sBuf.append(chr);
} else {
inQuoted = false;
chrCnt = 1;
prevChr = chr;
}
inQuoteQuoted = false;
continue;
}
if (inQuoted) {
if (chr == '\'') {
inQuoteQuoted = true;
} else {
sBuf.append(chr);
}
++chrCnt;
continue;
}
if (chr == '\'') {
if (chrCnt > 0) {
c = LcData.subXlate(prevChr, pLocal, pMask);
while (chrCnt-- > 0) {
sBuf.append(c);
}
chrCnt = 0;
prevChr = '\u0000';
}
inQuoted = true;
continue;
}
if ('a' <= chr && chr <= 'z' || 'A' <= chr && chr <= 'Z') {
if (chr != prevChr) {
if (chrCnt > 0) {
c = LcData.subXlate(prevChr, pLocal, pMask);
while (chrCnt-- > 0) {
sBuf.append(c);
}
chrCnt = 0;
}
prevChr = chr;
}
++chrCnt;
continue;
}
if (chrCnt > 0) {
c = LcData.subXlate(prevChr, pLocal, pMask);
while (chrCnt-- > 0) {
sBuf.append(c);
}
if (chr == '?' || chr == '*' || chr == '+') {
sBuf.append(' ');
} else {
sBuf.append(chr);
}
chrCnt = 0;
prevChr = '\u0000';
continue;
}
if (chr == '?' || chr == '*' || chr == '+') {
sBuf.append(' ');
} else {
sBuf.append(chr);
}
prevChr = '\u0000';
}
if (inQuoteQuoted) {
inQuoted = false;
}
if (inQuoted) {
sBuf.setLength(0);
}
if (prevChr > '\u0000' && chrCnt > 0) {
char c = LcData.subXlate(prevChr, pLocal, pMask);
while (chrCnt-- > 0) {
sBuf.append(c);
}
}
return sBuf.toString();
}
private static char subXlate(char c, String pPat, String pMask) {
assert (pPat != null && pMask != null);
assert (pPat.length() == pMask.length());
if (c == ' ') {
return c;
}
int index = pMask.indexOf(c);
if (index >= 0) {
return pPat.charAt(index);
}
return c;
}
private static final Map<String, LcRunTimeData> getMap() {
return mRuntimeMap.get();
}
static {
assert (rootIndex != -1);
LcData.staticParentIndex[LcData.rootIndex] = -1;
for (int i = 0; i < gLocaleList.length; ++i) {
String sFollowingLocaleName;
if (i == rootIndex) continue;
String sLocaleName = gLocaleList[i];
if (sLocaleName.indexOf(95) == -1) {
LcData.staticParentIndex[i] = rootIndex;
}
for (int j = i + 1; j < gLocaleList.length && (sFollowingLocaleName = gLocaleList[j]).length() > sLocaleName.length() && sFollowingLocaleName.startsWith(sLocaleName) && sFollowingLocaleName.charAt(sLocaleName.length()) == '_'; ++j) {
LcData.staticParentIndex[j] = i;
}
}
LcData.initParentIndex("az_Cyrl", rootIndex);
LcData.initParentIndex("sr_Latn", rootIndex);
int index = 0;
LcData.initScriptAlias(index++, "zh_CN", "zh_Hans_CN");
LcData.initScriptAlias(index++, "zh_SG", "zh_Hans_SG");
LcData.initScriptAlias(index++, "zh_HK", "zh_Hant_HK");
LcData.initScriptAlias(index++, "zh_TW", "zh_Hant_TW");
LcData.initScriptAlias(index++, "az_AZ", "az_Latn_AZ");
LcData.initScriptAlias(index++, "sr_CS", "sr_Cyrl_CS");
assert (index == 6);
retrieveWeekdayNameProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.dayNames[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getLongDayProperty(key));
}
};
retrieveAbbrWeekdayNameProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.abbrWeekdayNames[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getShortDayProperty(key));
}
};
retrieveMonthNameProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.monthNames[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getLongMonthProperty(key));
}
};
retrieveMonthAbbrNamesProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.abbrMonthNames[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getShortMonthProperty(key));
}
};
retrieveMeridiemNameProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.meridiemNames[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getMeridiemProperty(key));
}
};
retrieveEraNameProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.eraNames[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getEraProperty(key));
}
};
retrieveDatePatternProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.datePatterns[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getDateFormatProperty(key));
}
};
retrieveTimePatternProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.timePatterns[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getTimeFormatProperty(key));
}
};
retrieveDateTimeSymbolsProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.dateTimeSymbols[0];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getDateTimeSymbolsProperty());
}
};
retrieveDateTimeFormatProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return null;
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getDateTimeFormatProperty());
}
};
retrieveNumberPatternProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.numberPatterns[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getNumberFormatProperty(key));
}
};
retrieveCurrencySymbolProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.currencySymbols[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getCurrencySymbolProperty(key));
}
};
retrieveNumericSymbolProperty = new PropertyRetriever<String>(){
@Override
public String retrieveRuntime(LcRunTimeData runtimeData, int key) {
return runtimeData.numericSymbols[key];
}
@Override
public String retrieveStatic(Map<String, String> staticData, int key) {
return staticData.get(LcBundle.getNumericSymbolProperty(key));
}
};
retrieveTypefaceListProperty = new PropertyRetriever<List<String>>(){
@Override
public List<String> retrieveRuntime(LcRunTimeData runtimeData, int key) {
List<String> typefaces = runtimeData.typefaceList;
return typefaces.size() == 0 ? null : typefaces;
}
@Override
public List<String> retrieveStatic(Map<String, String> staticData, int key) {
String sList = staticData.get(LcBundle.getTypefacesProperty());
if (StringUtils.isEmpty(sList)) {
return null;
}
ArrayList<String> typefaceList = new ArrayList<String>();
StringTokenizer tokenizer = new StringTokenizer(sList, ";");
while (tokenizer.hasMoreTokens()) {
typefaceList.add(tokenizer.nextToken());
}
return typefaceList;
}
};
}
private static interface PropertyRetriever<T> {
public T retrieveRuntime(LcRunTimeData var1, int var2);
public T retrieveStatic(Map<String, String> var1, int var2);
}
public static class LcRunTimeData {
public final String localeName;
public final String[] monthNames = new String[12];
public final String[] abbrMonthNames = new String[12];
public final String[] dayNames = new String[7];
public final String[] abbrWeekdayNames = new String[7];
public final String[] meridiemNames = new String[2];
public final String[] eraNames = new String[2];
public final String[] datePatterns = new String[4];
public final String[] timePatterns = new String[4];
public final String[] dateTimeSymbols = new String[1];
public final String[] numberPatterns = new String[3];
public final String[] numericSymbols = new String[5];
public final String[] currencySymbols = new String[3];
public final List<String> typefaceList = new ArrayList<String>();
public LcRunTimeData(String sLocaleName) {
int index = LcData.localeIndex(sLocaleName);
sLocaleName = index >= 0 ? gLocaleList[index] : LcLocale.normalize(sLocaleName);
this.localeName = sLocaleName;
}
}
}