2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "DateComponents.h"
35 #include <unicode/udat.h>
36 #include <unicode/unum.h>
37 #include <wtf/Forward.h>
38 #include <wtf/OwnPtr.h>
39 #include <wtf/text/CString.h>
40 #include <wtf/text/WTFString.h>
44 // We should use this class only for LocalizedNumberICU.cpp, LocalizedDateICU.cpp,
45 // LocalizedCalendarICU.cpp, and LocalizedNumberICUTest.cpp.
48 static PassOwnPtr<ICULocale> create(const char* localeString);
49 static ICULocale* currentLocale();
52 // For LocalizedNumber
53 String convertToLocalizedNumber(const String&);
54 String convertFromLocalizedNumber(const String&);
57 double parseLocalizedDate(const String&);
58 String formatLocalizedDate(const DateComponents&);
60 #if ENABLE(CALENDAR_PICKER)
61 // For LocalizedCalendar
62 const Vector<String>& monthLabels();
63 const Vector<String>& weekDayShortLabels();
64 unsigned firstDayOfWeek();
68 static PassOwnPtr<ICULocale> createForCurrentLocale();
69 explicit ICULocale(const char*);
70 void setDecimalSymbol(unsigned index, UNumberFormatSymbol);
71 void setDecimalTextAttribute(String&, UNumberFormatTextAttribute);
72 void initializeDecimalFormat();
74 bool detectSignAndGetDigitRange(const String& input, bool& isNegative, unsigned& startIndex, unsigned& endIndex);
75 unsigned matchedDecimalSymbolIndex(const String& input, unsigned& position);
77 bool initializeShortDateFormat();
79 #if ENABLE(CALENDAR_PICKER)
80 PassOwnPtr<Vector<String> > createLabelVector(UDateFormatSymbolType, int32_t startIndex, int32_t size);
81 void initializeCalendar();
85 UNumberFormat* m_numberFormat;
86 UDateFormat* m_shortDateFormat;
89 DecimalSeparatorIndex = 10,
90 GroupSeparatorIndex = 11,
93 String m_decimalSymbols[DecimalSymbolsSize];
94 String m_positivePrefix;
95 String m_positiveSuffix;
96 String m_negativePrefix;
97 String m_negativeSuffix;
98 bool m_didCreateDecimalFormat;
99 bool m_didCreateShortDateFormat;
101 #if ENABLE(CALENDAR_PICKER)
102 OwnPtr<Vector<String> > m_monthLabels;
103 OwnPtr<Vector<String> > m_weekDayShortLabels;
104 unsigned m_firstDayOfWeek;