1 | /* |
2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions are |
6 | * met: |
7 | * |
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 |
13 | * distribution. |
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. |
17 | * |
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. |
29 | */ |
30 | |
31 | #ifndef LocaleICU_h |
32 | #define LocaleICU_h |
33 | |
34 | #include "PlatformLocale.h" |
35 | #include <unicode/udat.h> |
36 | #include <unicode/unum.h> |
37 | #include <wtf/Forward.h> |
38 | #include <wtf/text/CString.h> |
39 | #include <wtf/text/WTFString.h> |
40 | |
41 | namespace WebCore { |
42 | |
43 | // We should use this class only for LocalizedNumberICU.cpp, LocalizedDateICU.cpp, |
44 | // and LocalizedNumberICUTest.cpp. |
45 | class LocaleICU : public Locale { |
46 | public: |
47 | explicit LocaleICU(const char*); |
48 | virtual ~LocaleICU(); |
49 | |
50 | #if ENABLE(DATE_AND_TIME_INPUT_TYPES) |
51 | String dateFormat() override; |
52 | String monthFormat() override; |
53 | String shortMonthFormat() override; |
54 | String timeFormat() override; |
55 | String shortTimeFormat() override; |
56 | String dateTimeFormatWithSeconds() override; |
57 | String dateTimeFormatWithoutSeconds() override; |
58 | const Vector<String>& monthLabels() override; |
59 | const Vector<String>& shortMonthLabels() override; |
60 | const Vector<String>& standAloneMonthLabels() override; |
61 | const Vector<String>& shortStandAloneMonthLabels() override; |
62 | const Vector<String>& timeAMPMLabels() override; |
63 | #endif |
64 | |
65 | private: |
66 | #if !UCONFIG_NO_FORMATTING |
67 | String decimalSymbol(UNumberFormatSymbol); |
68 | String decimalTextAttribute(UNumberFormatTextAttribute); |
69 | #endif |
70 | void initializeLocaleData() override; |
71 | |
72 | #if ENABLE(DATE_AND_TIME_INPUT_TYPES) |
73 | bool initializeShortDateFormat(); |
74 | UDateFormat* openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const; |
75 | |
76 | std::unique_ptr<Vector<String>> createLabelVector(const UDateFormat*, UDateFormatSymbolType, int32_t startIndex, int32_t size); |
77 | void initializeDateTimeFormat(); |
78 | #endif |
79 | |
80 | CString m_locale; |
81 | |
82 | #if !UCONFIG_NO_FORMATTING |
83 | UNumberFormat* m_numberFormat { nullptr }; |
84 | bool m_didCreateDecimalFormat { false }; |
85 | #endif |
86 | |
87 | #if ENABLE(DATE_AND_TIME_INPUT_TYPES) |
88 | std::unique_ptr<Vector<String>> m_monthLabels; |
89 | String m_dateFormat; |
90 | String m_monthFormat; |
91 | String m_shortMonthFormat; |
92 | String m_timeFormatWithSeconds; |
93 | String m_timeFormatWithoutSeconds; |
94 | String m_dateTimeFormatWithSeconds; |
95 | String m_dateTimeFormatWithoutSeconds; |
96 | UDateFormat* m_shortDateFormat { nullptr }; |
97 | UDateFormat* m_mediumTimeFormat { nullptr }; |
98 | UDateFormat* m_shortTimeFormat { nullptr }; |
99 | Vector<String> m_shortMonthLabels; |
100 | Vector<String> m_standAloneMonthLabels; |
101 | Vector<String> m_shortStandAloneMonthLabels; |
102 | Vector<String> m_timeAMPMLabels; |
103 | bool m_didCreateShortDateFormat { false }; |
104 | bool m_didCreateTimeFormat { false }; |
105 | #endif |
106 | }; |
107 | |
108 | } // namespace WebCore |
109 | #endif |
110 | |