OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 121 } |
122 | 122 |
123 static LCID LCIDFromLocaleInternal(LCID userDefaultLCID, const String& userDefau
ltLanguageCode, LocaleNameToLCIDPtr localeNameToLCID, const String& locale) | 123 static LCID LCIDFromLocaleInternal(LCID userDefaultLCID, const String& userDefau
ltLanguageCode, LocaleNameToLCIDPtr localeNameToLCID, const String& locale) |
124 { | 124 { |
125 String localeLanguageCode = extractLanguageCode(locale); | 125 String localeLanguageCode = extractLanguageCode(locale); |
126 if (equalIgnoringCase(localeLanguageCode, userDefaultLanguageCode)) | 126 if (equalIgnoringCase(localeLanguageCode, userDefaultLanguageCode)) |
127 return userDefaultLCID; | 127 return userDefaultLCID; |
128 return localeNameToLCID(locale.charactersWithNullTermination().data(), 0); | 128 return localeNameToLCID(locale.charactersWithNullTermination().data(), 0); |
129 } | 129 } |
130 | 130 |
131 static LCID LCIDFromLocale(const AtomicString& locale, bool defaultsForLocale) | 131 static LCID LCIDFromLocale(const String& locale, bool defaultsForLocale) |
132 { | 132 { |
133 // LocaleNameToLCID() is available since Windows Vista. | 133 // LocaleNameToLCID() is available since Windows Vista. |
134 LocaleNameToLCIDPtr localeNameToLCID = reinterpret_cast<LocaleNameToLCIDPtr>
(::GetProcAddress(::GetModuleHandle(L"kernel32"), "LocaleNameToLCID")); | 134 LocaleNameToLCIDPtr localeNameToLCID = reinterpret_cast<LocaleNameToLCIDPtr>
(::GetProcAddress(::GetModuleHandle(L"kernel32"), "LocaleNameToLCID")); |
135 if (!localeNameToLCID) | 135 if (!localeNameToLCID) |
136 localeNameToLCID = convertLocaleNameToLCID; | 136 localeNameToLCID = convertLocaleNameToLCID; |
137 | 137 |
138 // According to MSDN, 9 is enough for LOCALE_SISO639LANGNAME. | 138 // According to MSDN, 9 is enough for LOCALE_SISO639LANGNAME. |
139 const size_t languageCodeBufferSize = 9; | 139 const size_t languageCodeBufferSize = 9; |
140 WCHAR lowercaseLanguageCode[languageCodeBufferSize]; | 140 WCHAR lowercaseLanguageCode[languageCodeBufferSize]; |
141 ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME | (defaultsForLo
cale ? LOCALE_NOUSEROVERRIDE : 0), lowercaseLanguageCode, languageCodeBufferSize
); | 141 ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME | (defaultsForLo
cale ? LOCALE_NOUSEROVERRIDE : 0), lowercaseLanguageCode, languageCodeBufferSize
); |
142 String userDefaultLanguageCode = String(lowercaseLanguageCode); | 142 String userDefaultLanguageCode = String(lowercaseLanguageCode); |
143 | 143 |
144 LCID lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageC
ode, localeNameToLCID, String(locale)); | 144 LCID lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageC
ode, localeNameToLCID, locale); |
145 if (!lcid) | 145 if (!lcid) |
146 lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageCo
de, localeNameToLCID, defaultLanguage()); | 146 lcid = LCIDFromLocaleInternal(LOCALE_USER_DEFAULT, userDefaultLanguageCo
de, localeNameToLCID, defaultLanguage()); |
147 return lcid; | 147 return lcid; |
148 } | 148 } |
149 | 149 |
150 PassOwnPtr<Locale> Locale::create(const AtomicString& locale) | 150 PassOwnPtr<Locale> Locale::create(const String& locale) |
151 { | 151 { |
152 // Whether the default settings for the locale should be used, ignoring user
overrides. | 152 // Whether the default settings for the locale should be used, ignoring user
overrides. |
153 bool defaultsForLocale = isRunningLayoutTest(); | 153 bool defaultsForLocale = isRunningLayoutTest(); |
154 return LocaleWin::create(LCIDFromLocale(locale, defaultsForLocale), defaults
ForLocale); | 154 return LocaleWin::create(LCIDFromLocale(locale, defaultsForLocale), defaults
ForLocale); |
155 } | 155 } |
156 | 156 |
157 inline LocaleWin::LocaleWin(LCID lcid, bool defaultsForLocale) | 157 inline LocaleWin::LocaleWin(LCID lcid, bool defaultsForLocale) |
158 : m_lcid(lcid) | 158 : m_lcid(lcid) |
159 , m_didInitializeNumberData(false) | 159 , m_didInitializeNumberData(false) |
160 , m_defaultsForLocale(defaultsForLocale) | 160 , m_defaultsForLocale(defaultsForLocale) |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 case NegativeFormatSignPrefix: // Fall through. | 577 case NegativeFormatSignPrefix: // Fall through. |
578 default: | 578 default: |
579 negativePrefix = negativeSign; | 579 negativePrefix = negativeSign; |
580 break; | 580 break; |
581 } | 581 } |
582 m_didInitializeNumberData = true; | 582 m_didInitializeNumberData = true; |
583 setLocaleData(symbols, emptyString(), emptyString(), negativePrefix, negativ
eSuffix); | 583 setLocaleData(symbols, emptyString(), emptyString(), negativePrefix, negativ
eSuffix); |
584 } | 584 } |
585 | 585 |
586 } | 586 } |
OLD | NEW |