summaryrefslogtreecommitdiff
path: root/Source/WebCore/platform/text/LocaleICU.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/text/LocaleICU.cpp')
-rw-r--r--Source/WebCore/platform/text/LocaleICU.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/Source/WebCore/platform/text/LocaleICU.cpp b/Source/WebCore/platform/text/LocaleICU.cpp
index ce5f0afc4..e1a1eb17b 100644
--- a/Source/WebCore/platform/text/LocaleICU.cpp
+++ b/Source/WebCore/platform/text/LocaleICU.cpp
@@ -33,6 +33,7 @@
#include "LocalizedStrings.h"
#include <limits>
+#include <unicode/udatpg.h>
#include <unicode/uloc.h>
#include <wtf/DateMath.h>
#include <wtf/PassOwnPtr.h>
@@ -398,6 +399,36 @@ String LocaleICU::dateFormat()
return m_dateFormat;
}
+static String getFormatForSkeleton(const char* locale, const String& skeleton)
+{
+ String format = ASCIILiteral("yyyy-MM");
+ UErrorCode status = U_ZERO_ERROR;
+ UDateTimePatternGenerator* patternGenerator = udatpg_open(locale, &status);
+ if (!patternGenerator)
+ return format;
+ status = U_ZERO_ERROR;
+ int32_t length = udatpg_getBestPattern(patternGenerator, skeleton.characters(), skeleton.length(), 0, 0, &status);
+ if (status == U_BUFFER_OVERFLOW_ERROR && length) {
+ Vector<UChar> buffer(length);
+ status = U_ZERO_ERROR;
+ udatpg_getBestPattern(patternGenerator, skeleton.characters(), skeleton.length(), buffer.data(), length, &status);
+ if (U_SUCCESS(status))
+ format = String::adopt(buffer);
+ }
+ udatpg_close(patternGenerator);
+ return format;
+}
+
+String LocaleICU::monthFormat()
+{
+ if (!m_monthFormat.isNull())
+ return m_monthFormat;
+ // Gets a format for "MMM", not "MM" because Windows API always provides
+ // formats for "MMM".
+ m_monthFormat = getFormatForSkeleton(m_locale.data(), ASCIILiteral("yyyyMMM"));
+ return m_monthFormat;
+}
+
String LocaleICU::timeFormat()
{
initializeDateTimeFormat();
@@ -410,6 +441,36 @@ String LocaleICU::shortTimeFormat()
return m_localizedShortTimeFormatText;
}
+const Vector<String>& LocaleICU::shortMonthLabels()
+{
+ if (!m_shortMonthLabels.isEmpty())
+ return m_shortMonthLabels;
+ if (initializeShortDateFormat()) {
+ if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_SHORT_MONTHS, UCAL_JANUARY, 12)) {
+ m_shortMonthLabels = *labels;
+ return m_shortMonthLabels;
+ }
+ }
+ m_shortMonthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthName));
+ for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i)
+ m_shortMonthLabels.append(WTF::monthName[i]);
+ return m_shortMonthLabels;
+}
+
+const Vector<String>& LocaleICU::shortStandAloneMonthLabels()
+{
+ if (!m_shortStandAloneMonthLabels.isEmpty())
+ return m_shortStandAloneMonthLabels;
+ if (initializeShortDateFormat()) {
+ if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_STANDALONE_SHORT_MONTHS, UCAL_JANUARY, 12)) {
+ m_shortStandAloneMonthLabels = *labels;
+ return m_shortStandAloneMonthLabels;
+ }
+ }
+ m_shortStandAloneMonthLabels = shortMonthLabels();
+ return m_shortStandAloneMonthLabels;
+}
+
const Vector<String>& LocaleICU::timeAMPMLabels()
{
initializeDateTimeFormat();