use of android.icu.util.UResourceBundleIterator in project j2objc by google.
the class KeyTypeData method getKeyInfo.
/**
* Reads
*keyInfo{
* deprecated{
* kh{"true"}
* vt{"true"}
* }
* valueType{
* ca{"incremental"}
* kr{"multiple"}
* vt{"multiple"}
* x0{"any"}
* }
*}
*/
private static void getKeyInfo(UResourceBundle keyInfoRes) {
Set<String> _deprecatedKeys = new LinkedHashSet<String>();
Map<String, ValueType> _valueTypes = new LinkedHashMap<String, ValueType>();
for (UResourceBundleIterator keyInfoIt = keyInfoRes.getIterator(); keyInfoIt.hasNext(); ) {
UResourceBundle keyInfoEntry = keyInfoIt.next();
String key = keyInfoEntry.getKey();
KeyInfoType keyInfo = KeyInfoType.valueOf(key);
for (UResourceBundleIterator keyInfoIt2 = keyInfoEntry.getIterator(); keyInfoIt2.hasNext(); ) {
UResourceBundle keyInfoEntry2 = keyInfoIt2.next();
String key2 = keyInfoEntry2.getKey();
String value2 = keyInfoEntry2.getString();
switch(keyInfo) {
case deprecated:
_deprecatedKeys.add(key2);
break;
case valueType:
_valueTypes.put(key2, ValueType.valueOf(value2));
break;
}
}
}
DEPRECATED_KEYS = Collections.unmodifiableSet(_deprecatedKeys);
VALUE_TYPES = Collections.unmodifiableMap(_valueTypes);
}
use of android.icu.util.UResourceBundleIterator in project j2objc by google.
the class NumberingSystem method getAvailableNames.
/**
* Returns a string array containing a list of the names of numbering systems
* currently known to ICU.
*/
public static String[] getAvailableNames() {
UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, "numberingSystems");
UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
UResourceBundle temp;
String nsName;
ArrayList<String> output = new ArrayList<String>();
UResourceBundleIterator it = nsCurrent.getIterator();
while (it.hasNext()) {
temp = it.next();
nsName = temp.getKey();
output.add(nsName);
}
return output.toArray(new String[output.size()]);
}
use of android.icu.util.UResourceBundleIterator in project j2objc by google.
the class DateFormatSymbols method initializeData.
/**
* Initializes format symbols for the locale and calendar type
* @param desiredLocale The locale whose symbols are desired.
* @param b Resource bundle provided externally
* @param calendarType The calendar type being used
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
protected // This API was accidentally marked as @stable ICU 3.0 formerly.
void initializeData(ULocale desiredLocale, ICUResourceBundle b, String calendarType) {
// Create a CalendarSink to load this data and a resource bundle
CalendarDataSink calendarSink = new CalendarDataSink();
if (b == null) {
b = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, desiredLocale);
}
// Iterate over the resource bundle data following the fallbacks through different calendar types
while (calendarType != null) {
// Enumerate this calendar type. If the calendar is not found fallback to gregorian.
ICUResourceBundle dataForType = b.findWithFallback("calendar/" + calendarType);
if (dataForType == null) {
if (!"gregorian".equals(calendarType)) {
calendarType = "gregorian";
calendarSink.visitAllResources();
continue;
}
throw new MissingResourceException("The 'gregorian' calendar type wasn't found for the locale: " + desiredLocale.getBaseName(), getClass().getName(), "gregorian");
}
calendarSink.preEnumerate(calendarType);
dataForType.getAllItemsWithFallback("", calendarSink);
// Stop loading when gregorian was loaded
if (calendarType.equals("gregorian")) {
break;
}
// Get the next calendar type to process from the sink
calendarType = calendarSink.nextCalendarType;
// Gregorian is always the last fallback
if (calendarType == null) {
calendarType = "gregorian";
calendarSink.visitAllResources();
}
}
Map<String, String[]> arrays = calendarSink.arrays;
Map<String, Map<String, String>> maps = calendarSink.maps;
eras = arrays.get("eras/abbreviated");
eraNames = arrays.get("eras/wide");
narrowEras = arrays.get("eras/narrow");
months = arrays.get("monthNames/format/wide");
shortMonths = arrays.get("monthNames/format/abbreviated");
narrowMonths = arrays.get("monthNames/format/narrow");
standaloneMonths = arrays.get("monthNames/stand-alone/wide");
standaloneShortMonths = arrays.get("monthNames/stand-alone/abbreviated");
standaloneNarrowMonths = arrays.get("monthNames/stand-alone/narrow");
String[] lWeekdays = arrays.get("dayNames/format/wide");
weekdays = new String[8];
// 1-based
weekdays[0] = "";
System.arraycopy(lWeekdays, 0, weekdays, 1, lWeekdays.length);
String[] aWeekdays = arrays.get("dayNames/format/abbreviated");
shortWeekdays = new String[8];
// 1-based
shortWeekdays[0] = "";
System.arraycopy(aWeekdays, 0, shortWeekdays, 1, aWeekdays.length);
String[] sWeekdays = arrays.get("dayNames/format/short");
shorterWeekdays = new String[8];
// 1-based
shorterWeekdays[0] = "";
System.arraycopy(sWeekdays, 0, shorterWeekdays, 1, sWeekdays.length);
String[] nWeekdays = arrays.get("dayNames/format/narrow");
if (nWeekdays == null) {
nWeekdays = arrays.get("dayNames/stand-alone/narrow");
if (nWeekdays == null) {
nWeekdays = arrays.get("dayNames/format/abbreviated");
if (nWeekdays == null) {
throw new MissingResourceException("Resource not found", getClass().getName(), "dayNames/format/abbreviated");
}
}
}
narrowWeekdays = new String[8];
// 1-based
narrowWeekdays[0] = "";
System.arraycopy(nWeekdays, 0, narrowWeekdays, 1, nWeekdays.length);
String[] swWeekdays = null;
swWeekdays = arrays.get("dayNames/stand-alone/wide");
standaloneWeekdays = new String[8];
// 1-based
standaloneWeekdays[0] = "";
System.arraycopy(swWeekdays, 0, standaloneWeekdays, 1, swWeekdays.length);
String[] saWeekdays = null;
saWeekdays = arrays.get("dayNames/stand-alone/abbreviated");
standaloneShortWeekdays = new String[8];
// 1-based
standaloneShortWeekdays[0] = "";
System.arraycopy(saWeekdays, 0, standaloneShortWeekdays, 1, saWeekdays.length);
String[] ssWeekdays = null;
ssWeekdays = arrays.get("dayNames/stand-alone/short");
standaloneShorterWeekdays = new String[8];
// 1-based
standaloneShorterWeekdays[0] = "";
System.arraycopy(ssWeekdays, 0, standaloneShorterWeekdays, 1, ssWeekdays.length);
String[] snWeekdays = null;
snWeekdays = arrays.get("dayNames/stand-alone/narrow");
standaloneNarrowWeekdays = new String[8];
// 1-based
standaloneNarrowWeekdays[0] = "";
System.arraycopy(snWeekdays, 0, standaloneNarrowWeekdays, 1, snWeekdays.length);
ampms = arrays.get("AmPmMarkers");
ampmsNarrow = arrays.get("AmPmMarkersNarrow");
quarters = arrays.get("quarters/format/wide");
shortQuarters = arrays.get("quarters/format/abbreviated");
standaloneQuarters = arrays.get("quarters/stand-alone/wide");
standaloneShortQuarters = arrays.get("quarters/stand-alone/abbreviated");
abbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/abbreviated"));
wideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/wide"));
narrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/narrow"));
standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/abbreviated"));
standaloneWideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/wide"));
standaloneNarrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/narrow"));
for (int i = 0; i < DT_MONTH_PATTERN_COUNT; i++) {
String monthPatternPath = LEAP_MONTH_PATTERNS_PATHS[i];
if (monthPatternPath != null) {
Map<String, String> monthPatternMap = maps.get(monthPatternPath);
if (monthPatternMap != null) {
String leapMonthPattern = monthPatternMap.get("leap");
if (leapMonthPattern != null) {
if (leapMonthPatterns == null) {
leapMonthPatterns = new String[DT_MONTH_PATTERN_COUNT];
}
leapMonthPatterns[i] = leapMonthPattern;
}
}
}
}
shortYearNames = arrays.get("cyclicNameSets/years/format/abbreviated");
shortZodiacNames = arrays.get("cyclicNameSets/zodiacs/format/abbreviated");
requestedLocale = desiredLocale;
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, desiredLocale);
localPatternChars = patternChars;
// TODO: obtain correct actual/valid locale later
ULocale uloc = rb.getULocale();
setLocale(uloc, uloc);
capitalization = new HashMap<CapitalizationContextUsage, boolean[]>();
boolean[] noTransforms = new boolean[2];
noTransforms[0] = false;
noTransforms[1] = false;
CapitalizationContextUsage[] allUsages = CapitalizationContextUsage.values();
for (CapitalizationContextUsage usage : allUsages) {
capitalization.put(usage, noTransforms);
}
UResourceBundle contextTransformsBundle = null;
try {
contextTransformsBundle = rb.getWithFallback("contextTransforms");
} catch (MissingResourceException e) {
// probably redundant
contextTransformsBundle = null;
}
if (contextTransformsBundle != null) {
UResourceBundleIterator ctIterator = contextTransformsBundle.getIterator();
while (ctIterator.hasNext()) {
UResourceBundle contextTransformUsage = ctIterator.next();
int[] intVector = contextTransformUsage.getIntVector();
if (intVector.length >= 2) {
String usageKey = contextTransformUsage.getKey();
CapitalizationContextUsage usage = contextUsageTypeMap.get(usageKey);
if (usage != null) {
boolean[] transforms = new boolean[2];
transforms[0] = (intVector[0] != 0);
transforms[1] = (intVector[1] != 0);
capitalization.put(usage, transforms);
}
}
}
}
NumberingSystem ns = NumberingSystem.getInstance(desiredLocale);
// Latin is default.
String nsName = ns == null ? "latn" : ns.getName();
String tsPath = "NumberElements/" + nsName + "/symbols/timeSeparator";
try {
setTimeSeparatorString(rb.getStringWithFallback(tsPath));
} catch (MissingResourceException e) {
setTimeSeparatorString(DEFAULT_TIME_SEPARATOR);
}
}
Aggregations