Diff
Modified: trunk/Source/WebCore/ChangeLog (128146 => 128147)
--- trunk/Source/WebCore/ChangeLog 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/ChangeLog 2012-09-11 05:17:56 UTC (rev 128147)
@@ -1,3 +1,43 @@
+2012-09-10 Keishi Hattori <[email protected]>
+
+ Rename NumberLocalizer to Localizer
+ https://bugs.webkit.org/show_bug.cgi?id=96350
+
+ Reviewed by Kent Tamura.
+
+ Renaming NumberLocalizer to Localizer so we can unify our localization methods into this class in the future.
+
+ No new tests. No behavior change.
+
+ * WebCore.gypi:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/text/LocaleICU.cpp:
+ (WebCore::LocaleICU::initializeLocalizerData):
+ * platform/text/LocaleICU.h:
+ (LocaleICU):
+ * platform/text/LocaleWin.cpp:
+ (WebCore::LocaleWin::initializeLocalizerData):
+ * platform/text/LocaleWin.h:
+ (LocaleWin):
+ * platform/text/Localizer.cpp: Renamed from Source/WebCore/platform/text/NumberLocalizer.cpp.
+ (WebCore):
+ (WebCore::Localizer::~Localizer):
+ (WebCore::Localizer::setLocalizerData):
+ (WebCore::Localizer::convertToLocalizedNumber):
+ (WebCore::matches):
+ (WebCore::Localizer::detectSignAndGetDigitRange):
+ (WebCore::Localizer::matchedDecimalSymbolIndex):
+ (WebCore::Localizer::convertFromLocalizedNumber):
+ (WebCore::Localizer::localizedDecimalSeparator):
+ * platform/text/Localizer.h: Renamed from Source/WebCore/platform/text/NumberLocalizer.h.
+ (WebCore):
+ (Localizer):
+ (WebCore::Localizer::Localizer):
+ * platform/text/mac/LocaleMac.h:
+ (LocaleMac):
+ * platform/text/mac/LocaleMac.mm:
+ (WebCore::LocaleMac::initializeLocalizerData):
+
2012-09-10 Dan Bernstein <[email protected]>
Use an API symbol instead of a hardcoded string for the TIFF uniform type identifier.
Modified: trunk/Source/WebCore/WebCore.gypi (128146 => 128147)
--- trunk/Source/WebCore/WebCore.gypi 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/WebCore.gypi 2012-09-11 05:17:56 UTC (rev 128147)
@@ -5677,8 +5677,8 @@
'platform/text/LocalizedNumber.h',
'platform/text/LocalizedNumberICU.cpp',
'platform/text/LocalizedNumberNone.cpp',
- 'platform/text/NumberLocalizer.cpp',
- 'platform/text/NumberLocalizer.h',
+ 'platform/text/Localizer.cpp',
+ 'platform/text/Localizer.h',
'platform/text/ParserUtilities.h',
'platform/text/QuotedPrintable.h',
'platform/text/QuotedPrintable.cpp',
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (128146 => 128147)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2012-09-11 05:17:56 UTC (rev 128147)
@@ -6230,8 +6230,8 @@
F5122C901547FA1B0028A93B /* PagePopupDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = F5122C8F1547FA1B0028A93B /* PagePopupDriver.h */; };
F5142C69123F12B000F5BD4C /* LocalizedNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = F5142C68123F12B000F5BD4C /* LocalizedNumber.h */; };
F52AD5E41534245F0059FBE6 /* EmptyClients.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F52AD5E31534245F0059FBE6 /* EmptyClients.cpp */; };
- F544F78815CFB2A800AF33A8 /* NumberLocalizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F544F78615CFB2A800AF33A8 /* NumberLocalizer.cpp */; };
- F544F78915CFB2A800AF33A8 /* NumberLocalizer.h in Headers */ = {isa = PBXBuildFile; fileRef = F544F78715CFB2A800AF33A8 /* NumberLocalizer.h */; };
+ F544F78815CFB2A800AF33A8 /* Localizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F544F78615CFB2A800AF33A8 /* Localizer.cpp */; };
+ F544F78915CFB2A800AF33A8 /* Localizer.h in Headers */ = {isa = PBXBuildFile; fileRef = F544F78715CFB2A800AF33A8 /* Localizer.h */; };
F55B3DAD1251F12D003EF269 /* BaseTextInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F55B3D791251F12D003EF269 /* BaseTextInputType.cpp */; };
F55B3DAE1251F12D003EF269 /* BaseTextInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F55B3D7A1251F12D003EF269 /* BaseTextInputType.h */; };
F55B3DAF1251F12D003EF269 /* ButtonInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F55B3D7B1251F12D003EF269 /* ButtonInputType.cpp */; };
@@ -13625,8 +13625,8 @@
F523D30302DE4476018635CA /* Range.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Range.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F523D30402DE4476018635CA /* Range.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = Range.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F52AD5E31534245F0059FBE6 /* EmptyClients.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EmptyClients.cpp; sourceTree = "<group>"; };
- F544F78615CFB2A800AF33A8 /* NumberLocalizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NumberLocalizer.cpp; sourceTree = "<group>"; };
- F544F78715CFB2A800AF33A8 /* NumberLocalizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NumberLocalizer.h; sourceTree = "<group>"; };
+ F544F78615CFB2A800AF33A8 /* Localizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Localizer.cpp; sourceTree = "<group>"; };
+ F544F78715CFB2A800AF33A8 /* Localizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Localizer.h; sourceTree = "<group>"; };
F55B3D791251F12D003EF269 /* BaseTextInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseTextInputType.cpp; sourceTree = "<group>"; };
F55B3D7A1251F12D003EF269 /* BaseTextInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseTextInputType.h; sourceTree = "<group>"; };
F55B3D7B1251F12D003EF269 /* ButtonInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ButtonInputType.cpp; sourceTree = "<group>"; };
@@ -20010,8 +20010,8 @@
A5732B0C136A16C4005C8D7C /* LocalizedDate.h */,
A5732B0E136A1715005C8D7C /* LocalizedDateNone.cpp */,
F5142C68123F12B000F5BD4C /* LocalizedNumber.h */,
- F544F78615CFB2A800AF33A8 /* NumberLocalizer.cpp */,
- F544F78715CFB2A800AF33A8 /* NumberLocalizer.h */,
+ F544F78615CFB2A800AF33A8 /* Localizer.cpp */,
+ F544F78715CFB2A800AF33A8 /* Localizer.h */,
BC76AC110DD7AD5C00415F34 /* ParserUtilities.h */,
379E371413736A6600B9E919 /* QuotedPrintable.cpp */,
379E371513736A6600B9E919 /* QuotedPrintable.h */,
@@ -24387,6 +24387,7 @@
A5732B0D136A16C4005C8D7C /* LocalizedDate.h in Headers */,
F5142C69123F12B000F5BD4C /* LocalizedNumber.h in Headers */,
935207BE09BD410A00F2038D /* LocalizedStrings.h in Headers */,
+ F544F78915CFB2A800AF33A8 /* Localizer.h in Headers */,
BCE1C41B0D982980003B02F2 /* Location.h in Headers */,
A8239E0109B3CF8A00B60641 /* Logging.h in Headers */,
656D37410ADBA5DE00A4554D /* MainResourceLoader.h in Headers */,
@@ -24504,7 +24505,6 @@
1A927FD41416A15B003A83C8 /* nptypes.h in Headers */,
93500F3213FDE3BE0099EC24 /* NSScrollerImpDetails.h in Headers */,
F55B3DC81251F12D003EF269 /* NumberInputType.h in Headers */,
- F544F78915CFB2A800AF33A8 /* NumberLocalizer.h in Headers */,
1A569D120D7E2B82007C3983 /* objc_class.h in Headers */,
1A569D140D7E2B82007C3983 /* objc_header.h in Headers */,
1A569D150D7E2B82007C3983 /* objc_instance.h in Headers */,
@@ -27694,6 +27694,7 @@
F5CC42DC12F801CA00D5F7E3 /* LocalizedNumberMac.mm in Sources */,
C046E1AC1208A9FE00BA2CF7 /* LocalizedStrings.cpp in Sources */,
BC25B52A131C6D3900180E10 /* LocalizedStringsMac.cpp in Sources */,
+ F544F78815CFB2A800AF33A8 /* Localizer.cpp in Sources */,
BCE1C41C0D982981003B02F2 /* Location.cpp in Sources */,
A8239E0009B3CF8A00B60641 /* Logging.cpp in Sources */,
1402645E0AFDC19B005919E2 /* LoggingMac.mm in Sources */,
@@ -27788,7 +27789,6 @@
1A569D0D0D7E2B82007C3983 /* npruntime.cpp in Sources */,
52F52E1114A0134F00ACC397 /* NSScrollerImpDetails.mm in Sources */,
F55B3DC71251F12D003EF269 /* NumberInputType.cpp in Sources */,
- F544F78815CFB2A800AF33A8 /* NumberLocalizer.cpp in Sources */,
1A569D130D7E2B82007C3983 /* objc_class.mm in Sources */,
1A569D160D7E2B82007C3983 /* objc_instance.mm in Sources */,
1A569D180D7E2B82007C3983 /* objc_runtime.mm in Sources */,
Modified: trunk/Source/WebCore/platform/text/LocaleICU.cpp (128146 => 128147)
--- trunk/Source/WebCore/platform/text/LocaleICU.cpp 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/LocaleICU.cpp 2012-09-11 05:17:56 UTC (rev 128147)
@@ -112,7 +112,7 @@
return String::adopt(buffer);
}
-void LocaleICU::initializeNumberLocalizerData()
+void LocaleICU::initializeLocalizerData()
{
if (m_didCreateDecimalFormat)
return;
@@ -136,7 +136,7 @@
symbols.append(decimalSymbol(UNUM_DECIMAL_SEPARATOR_SYMBOL));
symbols.append(decimalSymbol(UNUM_GROUPING_SEPARATOR_SYMBOL));
ASSERT(symbols.size() == DecimalSymbolsSize);
- setNumberLocalizerData(symbols, decimalTextAttribute(UNUM_POSITIVE_PREFIX), decimalTextAttribute(UNUM_POSITIVE_SUFFIX), decimalTextAttribute(UNUM_NEGATIVE_PREFIX), decimalTextAttribute(UNUM_NEGATIVE_SUFFIX));
+ setLocalizerData(symbols, decimalTextAttribute(UNUM_POSITIVE_PREFIX), decimalTextAttribute(UNUM_POSITIVE_SUFFIX), decimalTextAttribute(UNUM_NEGATIVE_PREFIX), decimalTextAttribute(UNUM_NEGATIVE_SUFFIX));
}
bool LocaleICU::initializeShortDateFormat()
Modified: trunk/Source/WebCore/platform/text/LocaleICU.h (128146 => 128147)
--- trunk/Source/WebCore/platform/text/LocaleICU.h 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/LocaleICU.h 2012-09-11 05:17:56 UTC (rev 128147)
@@ -32,7 +32,7 @@
#define LocaleICU_h
#include "DateComponents.h"
-#include "NumberLocalizer.h"
+#include "Localizer.h"
#include <unicode/udat.h>
#include <unicode/unum.h>
#include <wtf/Forward.h>
@@ -44,7 +44,7 @@
// We should use this class only for LocalizedNumberICU.cpp, LocalizedDateICU.cpp,
// and LocalizedNumberICUTest.cpp.
-class LocaleICU : public NumberLocalizer {
+class LocaleICU : public Localizer {
public:
static PassOwnPtr<LocaleICU> create(const char* localeString);
static LocaleICU* currentLocale();
@@ -72,7 +72,7 @@
explicit LocaleICU(const char*);
String decimalSymbol(UNumberFormatSymbol);
String decimalTextAttribute(UNumberFormatTextAttribute);
- virtual void initializeNumberLocalizerData() OVERRIDE;
+ virtual void initializeLocalizerData() OVERRIDE;
bool detectSignAndGetDigitRange(const String& input, bool& isNegative, unsigned& startIndex, unsigned& endIndex);
unsigned matchedDecimalSymbolIndex(const String& input, unsigned& position);
Modified: trunk/Source/WebCore/platform/text/LocaleWin.cpp (128146 => 128147)
--- trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/LocaleWin.cpp 2012-09-11 05:17:56 UTC (rev 128147)
@@ -723,7 +723,7 @@
}
#endif
-void LocaleWin::initializeNumberLocalizerData()
+void LocaleWin::initializeLocalizerData()
{
if (m_didInitializeNumberData)
return;
@@ -791,7 +791,7 @@
break;
}
m_didInitializeNumberData = true;
- setNumberLocalizerData(symbols, emptyString(), emptyString(), negativePrefix, negativeSuffix);
+ setLocalizerData(symbols, emptyString(), emptyString(), negativePrefix, negativeSuffix);
}
}
Modified: trunk/Source/WebCore/platform/text/LocaleWin.h (128146 => 128147)
--- trunk/Source/WebCore/platform/text/LocaleWin.h 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/LocaleWin.h 2012-09-11 05:17:56 UTC (rev 128147)
@@ -31,7 +31,7 @@
#ifndef LocaleWin_h
#define LocaleWin_h
-#include "NumberLocalizer.h"
+#include "Localizer.h"
#include <windows.h>
#include <wtf/Forward.h>
#include <wtf/Vector.h>
@@ -42,7 +42,7 @@
class DateComponents;
struct DateFormatToken;
-class LocaleWin : public NumberLocalizer {
+class LocaleWin : public Localizer {
public:
static PassOwnPtr<LocaleWin> create(LCID);
static LocaleWin* currentLocale();
@@ -85,8 +85,8 @@
#if ENABLE(CALENDAR_PICKER)
void ensureWeekDayShortLabels();
#endif
- // NumberLocalizer function:
- virtual void initializeNumberLocalizerData() OVERRIDE;
+ // Localizer function:
+ virtual void initializeLocalizerData() OVERRIDE;
LCID m_lcid;
int m_baseYear;
Copied: trunk/Source/WebCore/platform/text/Localizer.cpp (from rev 128146, trunk/Source/WebCore/platform/text/NumberLocalizer.cpp) (0 => 128147)
--- trunk/Source/WebCore/platform/text/Localizer.cpp (rev 0)
+++ trunk/Source/WebCore/platform/text/Localizer.cpp 2012-09-11 05:17:56 UTC (rev 128147)
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2011,2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "Localizer.h"
+
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+Localizer::~Localizer()
+{
+}
+
+void Localizer::setLocalizerData(const Vector<String, DecimalSymbolsSize>& symbols, const String& positivePrefix, const String& positiveSuffix, const String& negativePrefix, const String& negativeSuffix)
+{
+ for (size_t i = 0; i < symbols.size(); ++i) {
+ ASSERT(!symbols[i].isEmpty());
+ m_decimalSymbols[i] = symbols[i];
+ }
+ m_positivePrefix = positivePrefix;
+ m_positiveSuffix = positiveSuffix;
+ m_negativePrefix = negativePrefix;
+ m_negativeSuffix = negativeSuffix;
+ ASSERT(!m_positivePrefix.isEmpty() || !m_positiveSuffix.isEmpty() || !m_negativePrefix.isEmpty() || !m_negativeSuffix.isEmpty());
+ m_hasLocalizerData = true;
+}
+
+String Localizer::convertToLocalizedNumber(const String& input)
+{
+ initializeLocalizerData();
+ if (!m_hasLocalizerData || input.isEmpty())
+ return input;
+
+ unsigned i = 0;
+ bool isNegative = false;
+ StringBuilder builder;
+ builder.reserveCapacity(input.length());
+
+ if (input[0] == '-') {
+ ++i;
+ isNegative = true;
+ builder.append(m_negativePrefix);
+ } else
+ builder.append(m_positivePrefix);
+
+ for (; i < input.length(); ++i) {
+ switch (input[i]) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ builder.append(m_decimalSymbols[input[i] - '0']);
+ break;
+ case '.':
+ builder.append(m_decimalSymbols[DecimalSeparatorIndex]);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ }
+
+ builder.append(isNegative ? m_negativeSuffix : m_positiveSuffix);
+
+ return builder.toString();
+}
+
+static bool matches(const String& text, unsigned position, const String& part)
+{
+ if (part.isEmpty())
+ return true;
+ if (position + part.length() > text.length())
+ return false;
+ for (unsigned i = 0; i < part.length(); ++i) {
+ if (text[position + i] != part[i])
+ return false;
+ }
+ return true;
+}
+
+bool Localizer::detectSignAndGetDigitRange(const String& input, bool& isNegative, unsigned& startIndex, unsigned& endIndex)
+{
+ startIndex = 0;
+ endIndex = input.length();
+ if (m_negativePrefix.isEmpty() && m_negativeSuffix.isEmpty()) {
+ if (input.startsWith(m_positivePrefix) && input.endsWith(m_positiveSuffix)) {
+ isNegative = false;
+ startIndex = m_positivePrefix.length();
+ endIndex -= m_positiveSuffix.length();
+ } else
+ isNegative = true;
+ } else {
+ if (input.startsWith(m_negativePrefix) && input.endsWith(m_negativeSuffix)) {
+ isNegative = true;
+ startIndex = m_negativePrefix.length();
+ endIndex -= m_negativeSuffix.length();
+ } else {
+ isNegative = false;
+ if (input.startsWith(m_positivePrefix) && input.endsWith(m_positiveSuffix)) {
+ startIndex = m_positivePrefix.length();
+ endIndex -= m_positiveSuffix.length();
+ } else
+ return false;
+ }
+ }
+ return true;
+}
+
+unsigned Localizer::matchedDecimalSymbolIndex(const String& input, unsigned& position)
+{
+ for (unsigned symbolIndex = 0; symbolIndex < DecimalSymbolsSize; ++symbolIndex) {
+ if (m_decimalSymbols[symbolIndex].length() && matches(input, position, m_decimalSymbols[symbolIndex])) {
+ position += m_decimalSymbols[symbolIndex].length();
+ return symbolIndex;
+ }
+ }
+ return DecimalSymbolsSize;
+}
+
+String Localizer::convertFromLocalizedNumber(const String& localized)
+{
+ initializeLocalizerData();
+ String input = localized.stripWhiteSpace();
+ if (!m_hasLocalizerData || input.isEmpty())
+ return input;
+
+ bool isNegative;
+ unsigned startIndex;
+ unsigned endIndex;
+ if (!detectSignAndGetDigitRange(input, isNegative, startIndex, endIndex)) {
+ // Input is broken. Returning an invalid number string.
+ return "*";
+ }
+
+ StringBuilder builder;
+ builder.reserveCapacity(input.length());
+ if (isNegative)
+ builder.append("-");
+ for (unsigned i = startIndex; i < endIndex;) {
+ unsigned symbolIndex = matchedDecimalSymbolIndex(input, i);
+ if (symbolIndex >= DecimalSymbolsSize)
+ return "*";
+ if (symbolIndex == DecimalSeparatorIndex)
+ builder.append('.');
+ else if (symbolIndex == GroupSeparatorIndex) {
+ // Ignore group separators.
+
+ } else
+ builder.append(static_cast<UChar>('0' + symbolIndex));
+ }
+ return builder.toString();
+}
+
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+String Localizer::localizedDecimalSeparator()
+{
+ initializeLocalizerData();
+ return m_decimalSymbols[DecimalSeparatorIndex];
+}
+#endif
+
+}
Copied: trunk/Source/WebCore/platform/text/Localizer.h (from rev 128146, trunk/Source/WebCore/platform/text/NumberLocalizer.h) (0 => 128147)
--- trunk/Source/WebCore/platform/text/Localizer.h (rev 0)
+++ trunk/Source/WebCore/platform/text/Localizer.h 2012-09-11 05:17:56 UTC (rev 128147)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+#ifndef Localizer_h
+#define Localizer_h
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class Localizer {
+public:
+ String convertToLocalizedNumber(const String&);
+ String convertFromLocalizedNumber(const String&);
+#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
+ String localizedDecimalSeparator();
+#endif
+ virtual ~Localizer();
+
+protected:
+ enum {
+ // 0-9 for digits.
+ DecimalSeparatorIndex = 10,
+ GroupSeparatorIndex = 11,
+ DecimalSymbolsSize
+ };
+
+ Localizer() : m_hasLocalizerData(false) { }
+ virtual void initializeLocalizerData() = 0;
+ void setLocalizerData(const Vector<String, DecimalSymbolsSize>&, const String& positivePrefix, const String& positiveSuffix, const String& negativePrefix, const String& negativeSuffix);
+
+private:
+ bool detectSignAndGetDigitRange(const String& input, bool& isNegative, unsigned& startIndex, unsigned& endIndex);
+ unsigned matchedDecimalSymbolIndex(const String& input, unsigned& position);
+
+ String m_decimalSymbols[DecimalSymbolsSize];
+ String m_positivePrefix;
+ String m_positiveSuffix;
+ String m_negativePrefix;
+ String m_negativeSuffix;
+ bool m_hasLocalizerData;
+};
+
+}
+#endif
Deleted: trunk/Source/WebCore/platform/text/NumberLocalizer.cpp (128146 => 128147)
--- trunk/Source/WebCore/platform/text/NumberLocalizer.cpp 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/NumberLocalizer.cpp 2012-09-11 05:17:56 UTC (rev 128147)
@@ -1,195 +0,0 @@
-/*
- * Copyright (C) 2011,2012 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "NumberLocalizer.h"
-
-#include <wtf/text/StringBuilder.h>
-
-namespace WebCore {
-
-NumberLocalizer::~NumberLocalizer()
-{
-}
-
-void NumberLocalizer::setNumberLocalizerData(const Vector<String, DecimalSymbolsSize>& symbols, const String& positivePrefix, const String& positiveSuffix, const String& negativePrefix, const String& negativeSuffix)
-{
- for (size_t i = 0; i < symbols.size(); ++i) {
- ASSERT(!symbols[i].isEmpty());
- m_decimalSymbols[i] = symbols[i];
- }
- m_positivePrefix = positivePrefix;
- m_positiveSuffix = positiveSuffix;
- m_negativePrefix = negativePrefix;
- m_negativeSuffix = negativeSuffix;
- ASSERT(!m_positivePrefix.isEmpty() || !m_positiveSuffix.isEmpty() || !m_negativePrefix.isEmpty() || !m_negativeSuffix.isEmpty());
- m_hasNumberLocalizerData = true;
-}
-
-String NumberLocalizer::convertToLocalizedNumber(const String& input)
-{
- initializeNumberLocalizerData();
- if (!m_hasNumberLocalizerData || input.isEmpty())
- return input;
-
- unsigned i = 0;
- bool isNegative = false;
- StringBuilder builder;
- builder.reserveCapacity(input.length());
-
- if (input[0] == '-') {
- ++i;
- isNegative = true;
- builder.append(m_negativePrefix);
- } else
- builder.append(m_positivePrefix);
-
- for (; i < input.length(); ++i) {
- switch (input[i]) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- builder.append(m_decimalSymbols[input[i] - '0']);
- break;
- case '.':
- builder.append(m_decimalSymbols[DecimalSeparatorIndex]);
- break;
- default:
- ASSERT_NOT_REACHED();
- }
- }
-
- builder.append(isNegative ? m_negativeSuffix : m_positiveSuffix);
-
- return builder.toString();
-}
-
-static bool matches(const String& text, unsigned position, const String& part)
-{
- if (part.isEmpty())
- return true;
- if (position + part.length() > text.length())
- return false;
- for (unsigned i = 0; i < part.length(); ++i) {
- if (text[position + i] != part[i])
- return false;
- }
- return true;
-}
-
-bool NumberLocalizer::detectSignAndGetDigitRange(const String& input, bool& isNegative, unsigned& startIndex, unsigned& endIndex)
-{
- startIndex = 0;
- endIndex = input.length();
- if (m_negativePrefix.isEmpty() && m_negativeSuffix.isEmpty()) {
- if (input.startsWith(m_positivePrefix) && input.endsWith(m_positiveSuffix)) {
- isNegative = false;
- startIndex = m_positivePrefix.length();
- endIndex -= m_positiveSuffix.length();
- } else
- isNegative = true;
- } else {
- if (input.startsWith(m_negativePrefix) && input.endsWith(m_negativeSuffix)) {
- isNegative = true;
- startIndex = m_negativePrefix.length();
- endIndex -= m_negativeSuffix.length();
- } else {
- isNegative = false;
- if (input.startsWith(m_positivePrefix) && input.endsWith(m_positiveSuffix)) {
- startIndex = m_positivePrefix.length();
- endIndex -= m_positiveSuffix.length();
- } else
- return false;
- }
- }
- return true;
-}
-
-unsigned NumberLocalizer::matchedDecimalSymbolIndex(const String& input, unsigned& position)
-{
- for (unsigned symbolIndex = 0; symbolIndex < DecimalSymbolsSize; ++symbolIndex) {
- if (m_decimalSymbols[symbolIndex].length() && matches(input, position, m_decimalSymbols[symbolIndex])) {
- position += m_decimalSymbols[symbolIndex].length();
- return symbolIndex;
- }
- }
- return DecimalSymbolsSize;
-}
-
-String NumberLocalizer::convertFromLocalizedNumber(const String& localized)
-{
- initializeNumberLocalizerData();
- String input = localized.stripWhiteSpace();
- if (!m_hasNumberLocalizerData || input.isEmpty())
- return input;
-
- bool isNegative;
- unsigned startIndex;
- unsigned endIndex;
- if (!detectSignAndGetDigitRange(input, isNegative, startIndex, endIndex)) {
- // Input is broken. Returning an invalid number string.
- return "*";
- }
-
- StringBuilder builder;
- builder.reserveCapacity(input.length());
- if (isNegative)
- builder.append("-");
- for (unsigned i = startIndex; i < endIndex;) {
- unsigned symbolIndex = matchedDecimalSymbolIndex(input, i);
- if (symbolIndex >= DecimalSymbolsSize)
- return "*";
- if (symbolIndex == DecimalSeparatorIndex)
- builder.append('.');
- else if (symbolIndex == GroupSeparatorIndex) {
- // Ignore group separators.
-
- } else
- builder.append(static_cast<UChar>('0' + symbolIndex));
- }
- return builder.toString();
-}
-
-#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
-String NumberLocalizer::localizedDecimalSeparator()
-{
- initializeNumberLocalizerData();
- return m_decimalSymbols[DecimalSeparatorIndex];
-}
-#endif
-
-}
Deleted: trunk/Source/WebCore/platform/text/NumberLocalizer.h (128146 => 128147)
--- trunk/Source/WebCore/platform/text/NumberLocalizer.h 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/NumberLocalizer.h 2012-09-11 05:17:56 UTC (rev 128147)
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-#ifndef NumberLocalizer_h
-#define NumberLocalizer_h
-
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-class NumberLocalizer {
-public:
- String convertToLocalizedNumber(const String&);
- String convertFromLocalizedNumber(const String&);
-#if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
- String localizedDecimalSeparator();
-#endif
- virtual ~NumberLocalizer();
-
-protected:
- enum {
- // 0-9 for digits.
- DecimalSeparatorIndex = 10,
- GroupSeparatorIndex = 11,
- DecimalSymbolsSize
- };
-
- NumberLocalizer() : m_hasNumberLocalizerData(false) { }
- virtual void initializeNumberLocalizerData() = 0;
- void setNumberLocalizerData(const Vector<String, DecimalSymbolsSize>&, const String& positivePrefix, const String& positiveSuffix, const String& negativePrefix, const String& negativeSuffix);
-
-private:
- bool detectSignAndGetDigitRange(const String& input, bool& isNegative, unsigned& startIndex, unsigned& endIndex);
- unsigned matchedDecimalSymbolIndex(const String& input, unsigned& position);
-
- String m_decimalSymbols[DecimalSymbolsSize];
- String m_positivePrefix;
- String m_positiveSuffix;
- String m_negativePrefix;
- String m_negativeSuffix;
- bool m_hasNumberLocalizerData;
-};
-
-}
-#endif
Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.h (128146 => 128147)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2012-09-11 05:17:56 UTC (rev 128147)
@@ -31,7 +31,7 @@
#ifndef LocaleMac_h
#define LocaleMac_h
-#include "NumberLocalizer.h"
+#include "Localizer.h"
#include <wtf/Forward.h>
#include <wtf/RetainPtr.h>
#include <wtf/Vector.h>
@@ -44,7 +44,7 @@
class DateComponents;
-class LocaleMac : public NumberLocalizer {
+class LocaleMac : public Localizer {
public:
static PassOwnPtr<LocaleMac> create(const String&);
static LocaleMac* currentLocale();
@@ -69,7 +69,7 @@
explicit LocaleMac(NSLocale*);
explicit LocaleMac(const String&);
NSDateFormatter *createShortDateFormatter();
- virtual void initializeNumberLocalizerData() OVERRIDE;
+ virtual void initializeLocalizerData() OVERRIDE;
RetainPtr<NSLocale> m_locale;
#if ENABLE(CALENDAR_PICKER)
Modified: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (128146 => 128147)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2012-09-11 05:05:53 UTC (rev 128146)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2012-09-11 05:17:56 UTC (rev 128147)
@@ -270,7 +270,7 @@
}
#endif
-void LocaleMac::initializeNumberLocalizerData()
+void LocaleMac::initializeLocalizerData()
{
if (m_didInitializeNumberData)
return;
@@ -298,7 +298,7 @@
String positiveSuffix([formatter.get() positiveSuffix]);
String negativePrefix([formatter.get() negativePrefix]);
String negativeSuffix([formatter.get() negativeSuffix]);
- setNumberLocalizerData(symbols, positivePrefix, positiveSuffix, negativePrefix, negativeSuffix);
+ setLocalizerData(symbols, positivePrefix, positiveSuffix, negativePrefix, negativeSuffix);
}
}