- Revision
- 130242
- Author
- tk...@chromium.org
- Date
- 2012-10-02 18:17:15 -0700 (Tue, 02 Oct 2012)
Log Message
[Chromium-Win] Implement LocaleWin::dateFormat
https://bugs.webkit.org/show_bug.cgi?id=98117
Reviewed by Kentaro Hara.
Source/WebCore:
http://trac.webkit.org/changeset/130127 introduced
Localizer::dateFormat, and this is its implementation for LocaleICU
classs. The code is going to be used when
ENABLE_INPUT_MULTIPLE_FIELDS_UI is enabled.
Tests: Added a new test to WebKit/chromium/tests/LocaleWinTest.cpp.
* platform/text/LocaleWin.cpp:
(WebCore::parseDateFormat):
Fix a continuous apostrophes parsing bug; "abc''''def" produced "abc'''def"
(WebCore::appendAsLDMLLiteral):
A helper function to make a literal string for LDML.
(WebCore::convertWindowsDateFormatToLDML):
Creates an LDML format from a parsed date format tokens.
(WebCore::LocaleWin::dateFormat):
Implemented. This uses convertWindowsDateFormatToLDML.
(WebCore::LocaleWin::dateFormat):
Added for testing. The source windows format is specified as a function
argument.
* platform/text/LocaleWin.h:
(LocaleWin): Declare m_dateFormat and dateFormat().
Source/WebKit/chromium:
* tests/LocaleWinTest.cpp:
(TEST_F): Add tests for LocaleWin::dateFormat.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (130241 => 130242)
--- trunk/Source/WebCore/ChangeLog 2012-10-03 01:09:03 UTC (rev 130241)
+++ trunk/Source/WebCore/ChangeLog 2012-10-03 01:17:15 UTC (rev 130242)
@@ -1,3 +1,32 @@
+2012-10-02 Kent Tamura <tk...@chromium.org>
+
+ [Chromium-Win] Implement LocaleWin::dateFormat
+ https://bugs.webkit.org/show_bug.cgi?id=98117
+
+ Reviewed by Kentaro Hara.
+
+ http://trac.webkit.org/changeset/130127 introduced
+ Localizer::dateFormat, and this is its implementation for LocaleICU
+ classs. The code is going to be used when
+ ENABLE_INPUT_MULTIPLE_FIELDS_UI is enabled.
+
+ Tests: Added a new test to WebKit/chromium/tests/LocaleWinTest.cpp.
+
+ * platform/text/LocaleWin.cpp:
+ (WebCore::parseDateFormat):
+ Fix a continuous apostrophes parsing bug; "abc''''def" produced "abc'''def"
+ (WebCore::appendAsLDMLLiteral):
+ A helper function to make a literal string for LDML.
+ (WebCore::convertWindowsDateFormatToLDML):
+ Creates an LDML format from a parsed date format tokens.
+ (WebCore::LocaleWin::dateFormat):
+ Implemented. This uses convertWindowsDateFormatToLDML.
+ (WebCore::LocaleWin::dateFormat):
+ Added for testing. The source windows format is specified as a function
+ argument.
+ * platform/text/LocaleWin.h:
+ (LocaleWin): Declare m_dateFormat and dateFormat().
+
2012-10-02 Ian Vollick <voll...@chromium.org>
[chromium] Fix spelling of isNVIDIA override in Extensions3DChromium
Modified: trunk/Source/WebCore/platform/text/LocaleWin.cpp (130241 => 130242)
--- trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-10-03 01:09:03 UTC (rev 130241)
+++ trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-10-03 01:17:15 UTC (rev 130242)
@@ -240,14 +240,18 @@
Vector<DateFormatToken> tokens;
StringBuilder literalBuffer;
bool inQuote = false;
+ bool lastQuoteCanBeLiteral = false;
for (unsigned i = 0; i < format.length(); ++i) {
UChar ch = format[i];
if (inQuote) {
if (ch == '\'') {
inQuote = false;
ASSERT(i);
- if (format[i - 1] == '\'')
+ if (lastQuoteCanBeLiteral && format[i - 1] == '\'') {
literalBuffer.append('\'');
+ lastQuoteCanBeLiteral = false;
+ } else
+ lastQuoteCanBeLiteral = true;
} else
literalBuffer.append(ch);
continue;
@@ -255,8 +259,11 @@
if (ch == '\'') {
inQuote = true;
- if (i > 0 && format[i - 1] == '\'')
+ if (lastQuoteCanBeLiteral && i > 0 && format[i - 1] == '\'') {
literalBuffer.append(ch);
+ lastQuoteCanBeLiteral = false;
+ } else
+ lastQuoteCanBeLiteral = true;
} else if (isYearSymbol(ch)) {
commitLiteralToken(literalBuffer, tokens);
unsigned count = countContinuousLetters(format, i);
@@ -677,6 +684,76 @@
#endif
#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
+static void appendAsLDMLLiteral(const String& literal, StringBuilder& buffer)
+{
+ if (literal.length() <= 0)
+ return;
+
+ if (literal.find('\'') == notFound) {
+ buffer.append("'");
+ buffer.append(literal);
+ buffer.append("'");
+ return;
+ }
+
+ for (unsigned i = 0; i < literal.length(); ++i) {
+ if (literal[i] == '\'')
+ buffer.append("''");
+ else {
+ String escaped = literal.substring(i);
+ escaped.replace(ASCIILiteral("'"), ASCIILiteral("''"));
+ buffer.append("'");
+ buffer.append(escaped);
+ buffer.append("'");
+ return;
+ }
+ }
+}
+
+static String convertWindowsDateFormatToLDML(const Vector<DateFormatToken>& tokens)
+{
+ StringBuilder buffer;
+ for (unsigned i = 0; i < tokens.size(); ++i) {
+ switch (tokens[i].type) {
+ case DateFormatToken::Literal:
+ appendAsLDMLLiteral(tokens[i].data, buffer);
+ break;
+
+ case DateFormatToken::Day2:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeDayOfMonth));
+ // Fallthrough.
+ case DateFormatToken::Day1:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeDayOfMonth));
+ break;
+
+ case DateFormatToken::Month4:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+ // Fallthrough.
+ case DateFormatToken::Month3:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+ // Fallthrough.
+ case DateFormatToken::Month2:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+ // Fallthrough.
+ case DateFormatToken::Month1:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeMonth));
+ break;
+
+ case DateFormatToken::Year4:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+ // Fallthrough.
+ case DateFormatToken::Year2:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+ // Fallthrough.
+ case DateFormatToken::Year1:
+ buffer.append(static_cast<char>(DateTimeFormat::FieldTypeYear));
+ break;
+ }
+ }
+ return buffer.toString();
+}
+
static DateTimeFormat::FieldType mapCharacterToDateTimeFieldType(UChar ch)
{
switch (ch) {
@@ -731,10 +808,18 @@
String LocaleWin::dateFormat()
{
- // FIXME: We should have real implementation of LocaleWin::dateFormat().
- return emptyString();
+ if (!m_dateFormat.isEmpty())
+ return m_dateFormat;
+ ensureShortDateTokens();
+ m_dateFormat = convertWindowsDateFormatToLDML(m_shortDateTokens);
+ return m_dateFormat;
}
+String LocaleWin::dateFormat(const String& windowsFormat)
+{
+ return convertWindowsDateFormatToLDML(parseDateFormat(windowsFormat));
+}
+
String LocaleWin::timeFormat()
{
if (m_localizedTimeFormatText.isEmpty())
Modified: trunk/Source/WebCore/platform/text/LocaleWin.h (130241 => 130242)
--- trunk/Source/WebCore/platform/text/LocaleWin.h 2012-10-03 01:09:03 UTC (rev 130241)
+++ trunk/Source/WebCore/platform/text/LocaleWin.h 2012-10-03 01:17:15 UTC (rev 130242)
@@ -67,6 +67,9 @@
double parseDate(const String& format, int baseYear, const String& input);
String formatDate(const String& format, int baseYear, int year, int month, int day);
static String dateFormatText(const String& format, const String& yearText, const String& monthText, const String& dayText);
+#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
+ static String dateFormat(const String&);
+#endif
private:
explicit LocaleWin(LCID);
@@ -94,6 +97,9 @@
Vector<DateFormatToken> m_shortDateTokens;
Vector<String> m_shortMonthLabels;
Vector<String> m_monthLabels;
+#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
+ String m_dateFormat;
+#endif
#if ENABLE(CALENDAR_PICKER)
Vector<String> m_weekDayShortLabels;
unsigned m_firstDayOfWeek;
Modified: trunk/Source/WebKit/chromium/ChangeLog (130241 => 130242)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-10-03 01:09:03 UTC (rev 130241)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-10-03 01:17:15 UTC (rev 130242)
@@ -1 +1,11 @@
+2012-10-02 Kent Tamura <tk...@chromium.org>
+
+ [Chromium-Win] Implement LocaleWin::dateFormat
+ https://bugs.webkit.org/show_bug.cgi?id=98117
+
+ Reviewed by Kentaro Hara.
+
+ * tests/LocaleWinTest.cpp:
+ (TEST_F): Add tests for LocaleWin::dateFormat.
+
== Rolled over to ChangeLog-2012-10-02 ==
Modified: trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp (130241 => 130242)
--- trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-10-03 01:09:03 UTC (rev 130241)
+++ trunk/Source/WebKit/chromium/tests/LocaleWinTest.cpp 2012-10-03 01:17:15 UTC (rev 130242)
@@ -325,6 +325,14 @@
#endif
#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
+TEST_F(LocaleWinTest, dateFormat)
+{
+ EXPECT_STREQ("y'-'M'-'d", LocaleWin::dateFormat("y-M-d").utf8().data());
+ EXPECT_STREQ("''yy'-'''MM'''-'dd", LocaleWin::dateFormat("''yy-''MM''-dd").utf8().data());
+ EXPECT_STREQ("yyyy'-''''-'MMM'''''-'dd", LocaleWin::dateFormat("yyyy-''''-MMM''''-dd").utf8().data());
+ EXPECT_STREQ("yyyy'-'''''MMMM'-'dd", LocaleWin::dateFormat("yyyy-''''MMMM-dd").utf8().data());
+}
+
TEST_F(LocaleWinTest, timeFormat)
{
EXPECT_STREQ("h:mm:ss a", timeFormat(EnglishUS).utf8().data());