| OLD | NEW |
| (Empty) |
| 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 | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND | |
| 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE | |
| 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | |
| 23 * DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #ifndef PlatformLocale_h | |
| 27 #define PlatformLocale_h | |
| 28 | |
| 29 #include "platform/DateComponents.h" | |
| 30 #include "platform/Language.h" | |
| 31 #include "public/platform/WebLocalizedString.h" | |
| 32 #include "wtf/PassOwnPtr.h" | |
| 33 #include "wtf/text/WTFString.h" | |
| 34 | |
| 35 namespace WebCore { | |
| 36 | |
| 37 class Locale { | |
| 38 WTF_MAKE_NONCOPYABLE(Locale); | |
| 39 | |
| 40 public: | |
| 41 static PassOwnPtr<Locale> create(const AtomicString& localeIdentifier); | |
| 42 // Never returns 0. | |
| 43 static Locale* defaultLocale(); | |
| 44 | |
| 45 String queryString(WebKit::WebLocalizedString::Name); | |
| 46 String queryString(WebKit::WebLocalizedString::Name, const String& parameter
); | |
| 47 String queryString(WebKit::WebLocalizedString::Name, const String& parameter
1, const String& parameter2); | |
| 48 String validationMessageTooLongText(unsigned valueLength, int maxLength); | |
| 49 | |
| 50 // Converts the specified number string to another number string localized | |
| 51 // for this Locale locale. The input string must conform to HTML | |
| 52 // floating-point numbers, and is not empty. | |
| 53 String convertToLocalizedNumber(const String&); | |
| 54 | |
| 55 // Converts the specified localized number string to a number string in the | |
| 56 // HTML floating-point number format. The input string is provided by a end | |
| 57 // user, and might not be a number string. It's ok that the function returns | |
| 58 // a string which is not conforms to the HTML floating-point number format, | |
| 59 // callers of this function are responsible to check the format of the | |
| 60 // resultant string. | |
| 61 String convertFromLocalizedNumber(const String&); | |
| 62 | |
| 63 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) | |
| 64 // Returns localized decimal separator, e.g. "." for English, "," for French
. | |
| 65 String localizedDecimalSeparator(); | |
| 66 #endif | |
| 67 | |
| 68 // Returns date format in Unicode TR35 LDML[1] containing day of month, | |
| 69 // month, and year, e.g. "dd/mm/yyyy" | |
| 70 // [1] LDML http://unicode.org/reports/tr35/#Date_Format_Patterns | |
| 71 virtual String dateFormat() = 0; | |
| 72 | |
| 73 // Returns a year-month format in Unicode TR35 LDML. | |
| 74 virtual String monthFormat() = 0; | |
| 75 | |
| 76 // Returns a year-month format using short month lanel in Unicode TR35 LDML. | |
| 77 virtual String shortMonthFormat() = 0; | |
| 78 | |
| 79 // Returns time format in Unicode TR35 LDML[1] containing hour, minute, and | |
| 80 // second with optional period(AM/PM), e.g. "h:mm:ss a" | |
| 81 // [1] LDML http://unicode.org/reports/tr35/#Date_Format_Patterns | |
| 82 virtual String timeFormat() = 0; | |
| 83 | |
| 84 // Returns time format in Unicode TR35 LDML containing hour, and minute | |
| 85 // with optional period(AM/PM), e.g. "h:mm a" | |
| 86 // Note: Some platforms return same value as timeFormat(). | |
| 87 virtual String shortTimeFormat() = 0; | |
| 88 | |
| 89 // Returns a date-time format in Unicode TR35 LDML. It should have a seconds | |
| 90 // field. | |
| 91 virtual String dateTimeFormatWithSeconds() = 0; | |
| 92 | |
| 93 // Returns a date-time format in Unicode TR35 LDML. It should have no second
s | |
| 94 // field. | |
| 95 virtual String dateTimeFormatWithoutSeconds() = 0; | |
| 96 | |
| 97 // weekFormatInLDML() returns week and year format in LDML, Unicode | |
| 98 // technical standard 35, Locale Data Markup Language, e.g. "'Week' ww, yyyy
" | |
| 99 String weekFormatInLDML(); | |
| 100 | |
| 101 // Returns a vector of string of which size is 12. The first item is a | |
| 102 // localized string of Jan and the last item is a localized string of | |
| 103 // Dec. These strings should be short. | |
| 104 virtual const Vector<String>& shortMonthLabels() = 0; | |
| 105 | |
| 106 // Returns a vector of string of which size is 12. The first item is a | |
| 107 // stand-alone localized string of January and the last item is a | |
| 108 // stand-alone localized string of December. These strings should not be | |
| 109 // abbreviations. | |
| 110 virtual const Vector<String>& standAloneMonthLabels() = 0; | |
| 111 | |
| 112 // Stand-alone month version of shortMonthLabels. | |
| 113 virtual const Vector<String>& shortStandAloneMonthLabels() = 0; | |
| 114 | |
| 115 // Returns localized period field(AM/PM) strings. | |
| 116 virtual const Vector<String>& timeAMPMLabels() = 0; | |
| 117 | |
| 118 // Returns a vector of string of which size is 12. The first item is a | |
| 119 // localized string of January, and the last item is a localized string of | |
| 120 // December. These strings should not be abbreviations. | |
| 121 virtual const Vector<String>& monthLabels() = 0; | |
| 122 | |
| 123 #if ENABLE(CALENDAR_PICKER) | |
| 124 // Returns a vector of string of which size is 7. The first item is a | |
| 125 // localized short string of Monday, and the last item is a localized | |
| 126 // short string of Saturday. These strings should be short. | |
| 127 virtual const Vector<String>& weekDayShortLabels() = 0; | |
| 128 | |
| 129 // The first day of a week. 0 is Sunday, and 6 is Saturday. | |
| 130 virtual unsigned firstDayOfWeek() = 0; | |
| 131 | |
| 132 // Returns true if people use right-to-left writing in the locale for this | |
| 133 // object. | |
| 134 virtual bool isRTL() = 0; | |
| 135 #endif | |
| 136 | |
| 137 enum FormatType { FormatTypeUnspecified, FormatTypeShort, FormatTypeMedium }
; | |
| 138 | |
| 139 // Serializes the specified date into a formatted date string to | |
| 140 // display to the user. If an implementation doesn't support | |
| 141 // localized dates the function should return an empty string. | |
| 142 // FormatType can be used to specify if you want the short format. | |
| 143 String formatDateTime(const DateComponents&, FormatType = FormatTypeUnspecif
ied); | |
| 144 | |
| 145 virtual ~Locale(); | |
| 146 | |
| 147 protected: | |
| 148 enum { | |
| 149 // 0-9 for digits. | |
| 150 DecimalSeparatorIndex = 10, | |
| 151 GroupSeparatorIndex = 11, | |
| 152 DecimalSymbolsSize | |
| 153 }; | |
| 154 | |
| 155 Locale() : m_hasLocaleData(false) { } | |
| 156 virtual void initializeLocaleData() = 0; | |
| 157 void setLocaleData(const Vector<String, DecimalSymbolsSize>&, const String&
positivePrefix, const String& positiveSuffix, const String& negativePrefix, cons
t String& negativeSuffix); | |
| 158 | |
| 159 private: | |
| 160 bool detectSignAndGetDigitRange(const String& input, bool& isNegative, unsig
ned& startIndex, unsigned& endIndex); | |
| 161 unsigned matchedDecimalSymbolIndex(const String& input, unsigned& position); | |
| 162 | |
| 163 String m_decimalSymbols[DecimalSymbolsSize]; | |
| 164 String m_positivePrefix; | |
| 165 String m_positiveSuffix; | |
| 166 String m_negativePrefix; | |
| 167 String m_negativeSuffix; | |
| 168 bool m_hasLocaleData; | |
| 169 }; | |
| 170 | |
| 171 } | |
| 172 #endif | |
| OLD | NEW |