status_t ICULocaleconvData::_SetLocaleconvEntry(const DecimalFormatSymbols* formatSymbols, char* destination, FormatSymbol symbol, const char* defaultValue) { status_t result = B_OK; UnicodeString symbolString = formatSymbols->getSymbol(symbol); if (!symbolString.isEmpty()) { result = _ConvertUnicodeStringToLocaleconvEntry(symbolString, destination, skLCBufSize, defaultValue); } else destination[0] = '\0'; return result; }
status_t ICUTimeData::_SetLCTimeEntries(const UnicodeString* strings, char* destination, int entrySize, int count, int maxCount) { if (strings == NULL) return B_ERROR; status_t result = B_OK; if (count > maxCount) count = maxCount; for (int32 i = 0; result == B_OK && i < count; ++i) { result = _ConvertUnicodeStringToLocaleconvEntry(strings[i], destination, entrySize); destination += entrySize; } return result; }
status_t ICUTimeData::_SetLCTimePattern(DateFormat* format, char* destination, int destinationSize) { SimpleDateFormat* simpleFormat = dynamic_cast<SimpleDateFormat*>(format); if (!simpleFormat) return B_BAD_TYPE; // convert ICU-type pattern to posix (i.e. strftime()) format string UnicodeString icuPattern; simpleFormat->toPattern(icuPattern); UnicodeString posixPattern; if (icuPattern.length() > 0) { UChar lastCharSeen = 0; int lastCharCount = 1; bool inSingleQuotes = false; bool inDoubleQuotes = false; // we loop one character past the end on purpose, which will result in a // final -1 char to be processed, which in turn will let us handle the // last character (via lastCharSeen) for (int i = 0; i <= icuPattern.length(); ++i) { UChar currChar = icuPattern.charAt(i); if (lastCharSeen != 0 && currChar == lastCharSeen) { lastCharCount++; continue; } if (!inSingleQuotes && !inDoubleQuotes) { switch (lastCharSeen) { case L'a': posixPattern.append(UnicodeString("%p", "")); break; case L'd': if (lastCharCount == 2) posixPattern.append(UnicodeString("%d", "")); else posixPattern.append(UnicodeString("%e", "")); break; case L'D': posixPattern.append(UnicodeString("%j", "")); break; case L'c': // fall through, to handle 'c' the same as 'e' case L'e': if (lastCharCount == 4) posixPattern.append(UnicodeString("%A", "")); else if (lastCharCount <= 2) posixPattern.append(UnicodeString("%u", "")); else posixPattern.append(UnicodeString("%a", "")); break; case L'E': if (lastCharCount == 4) posixPattern.append(UnicodeString("%A", "")); else posixPattern.append(UnicodeString("%a", "")); break; case L'k': // fall through, to handle 'k' the same as 'h' case L'h': if (lastCharCount == 2) posixPattern.append(UnicodeString("%I", "")); else posixPattern.append(UnicodeString("%l", "")); break; case L'H': if (lastCharCount == 2) posixPattern.append(UnicodeString("%H", "")); else posixPattern.append(UnicodeString("%k", "")); break; case L'm': posixPattern.append(UnicodeString("%M", "")); break; case L'L': // fall through, to handle 'L' the same as 'M' case L'M': if (lastCharCount == 4) posixPattern.append(UnicodeString("%B", "")); else if (lastCharCount == 3) posixPattern.append(UnicodeString("%b", "")); else posixPattern.append(UnicodeString("%m", "")); break; case L's': posixPattern.append(UnicodeString("%S", "")); break; case L'w': posixPattern.append(UnicodeString("%V", "")); break; case L'y': if (lastCharCount == 2) posixPattern.append(UnicodeString("%y", "")); else posixPattern.append(UnicodeString("%Y", "")); break; case L'Y': posixPattern.append(UnicodeString("%G", "")); break; case L'z': posixPattern.append(UnicodeString("%Z", "")); break; case L'Z': posixPattern.append(UnicodeString("%z", "")); break; default: if (lastCharSeen != 0) posixPattern.append(lastCharSeen); } } else { if (lastCharSeen != 0) posixPattern.append(lastCharSeen); } if (currChar == L'"') { inDoubleQuotes = !inDoubleQuotes; lastCharSeen = 0; } else if (currChar == L'\'') { inSingleQuotes = !inSingleQuotes; lastCharSeen = 0; } else lastCharSeen = currChar; lastCharCount = 1; } } return _ConvertUnicodeStringToLocaleconvEntry(posixPattern, destination, destinationSize); }