Diff
Modified: trunk/Source/WebCore/ChangeLog (256006 => 256007)
--- trunk/Source/WebCore/ChangeLog 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/ChangeLog 2020-02-07 04:12:39 UTC (rev 256007)
@@ -1,3 +1,25 @@
+2020-02-06 Myles C. Maxfield <mmaxfi...@apple.com>
+
+ [Cocoa] Rename LocaleMac to LocaleCocoa
+ https://bugs.webkit.org/show_bug.cgi?id=207371
+
+ Reviewed by Simon Fraser.
+
+ It's used by all the Cocoa platforms.
+
+ No new tests because there is no behavior change.
+
+ * PlatformMac.cmake:
+ * SourcesCocoa.txt:
+ * WebCore.order:
+ * WebCore.xcodeproj/project.pbxproj:
+ * page/cocoa/MemoryReleaseCocoa.mm:
+ (WebCore::platformReleaseMemory):
+ * platform/graphics/cocoa/FontCocoa.mm:
+ (WebCore::Font::applyTransforms const):
+ * platform/text/cocoa/LocaleCocoa.h: Renamed from Source/WebCore/platform/text/mac/LocaleMac.h.
+ * platform/text/mac/LocaleMac.mm: Removed.
+
2020-02-06 Tim Horton <timothy_hor...@apple.com>
macCatalyst: Unnecessary I-beam over images in editable areas
Modified: trunk/Source/WebCore/PlatformMac.cmake (256006 => 256007)
--- trunk/Source/WebCore/PlatformMac.cmake 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/PlatformMac.cmake 2020-02-07 04:12:39 UTC (rev 256007)
@@ -430,9 +430,10 @@
platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm
platform/network/mac/WebCoreURLResponse.mm
+ platform/text/cocoa/LocaleCocoa.mm
+
platform/text/cf/HyphenationCF.cpp
- platform/text/mac/LocaleMac.mm
platform/text/mac/TextBoundaries.mm
platform/text/mac/TextCheckingMac.mm
platform/text/mac/TextEncodingRegistryMac.mm
Modified: trunk/Source/WebCore/SourcesCocoa.txt (256006 => 256007)
--- trunk/Source/WebCore/SourcesCocoa.txt 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2020-02-07 04:12:39 UTC (rev 256007)
@@ -537,10 +537,11 @@
platform/text/cf/HyphenationCF.cpp
+platform/text/cocoa/LocaleCocoa.mm
+
platform/text/ios/LocalizedDateCache.mm
platform/text/ios/TextEncodingRegistryIOS.mm
-platform/text/mac/LocaleMac.mm
platform/text/mac/TextBoundaries.mm
platform/text/mac/TextCheckingMac.mm
platform/text/mac/TextEncodingRegistryMac.mm
Modified: trunk/Source/WebCore/WebCore.order (256006 => 256007)
--- trunk/Source/WebCore/WebCore.order 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/WebCore.order 2020-02-07 04:12:39 UTC (rev 256007)
@@ -23173,7 +23173,7 @@
__ZTVN7WebCore16LegacyWebArchiveE
__ZTVN7WebCore10LinkLoaderE
__ZTVN7WebCore17LoadableTextTrackE
-__ZTVN7WebCore9LocaleMacE
+__ZTVN7WebCore9LocaleCocoaE
__ZZN7WebCore16scriptNameToCodeERKN3WTF6StringEE18scriptNameCodeList
__ZZN7WebCore34localeToScriptCodeForFontSelectionERKN3WTF6StringEE16localeScriptList
__ZTVN7WebCore18MainResourceLoaderE
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (256006 => 256007)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-02-07 04:12:39 UTC (rev 256007)
@@ -5013,7 +5013,7 @@
F55B3DDC1251F12D003EF269 /* TimeInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F55B3DA81251F12D003EF269 /* TimeInputType.h */; };
F55B3DDE1251F12D003EF269 /* URLInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F55B3DAA1251F12D003EF269 /* URLInputType.h */; };
F55B3DE01251F12D003EF269 /* WeekInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F55B3DAC1251F12D003EF269 /* WeekInputType.h */; };
- F5973DE015CFB2030027F804 /* LocaleMac.h in Headers */ = {isa = PBXBuildFile; fileRef = F5973DDE15CFB2030027F804 /* LocaleMac.h */; };
+ F5973DE015CFB2030027F804 /* LocaleCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = F5973DDE15CFB2030027F804 /* LocaleCocoa.h */; };
F59C96001255B23F000623C0 /* BaseDateAndTimeInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F59C95FE1255B23F000623C0 /* BaseDateAndTimeInputType.h */; };
F5A154281279534D00D0B0C0 /* ValidationMessage.h in Headers */ = {isa = PBXBuildFile; fileRef = F5A154261279534D00D0B0C0 /* ValidationMessage.h */; };
F5C041DB0FFCA7CE00839D4A /* HTMLDataListElement.h in Headers */ = {isa = PBXBuildFile; fileRef = F5C041D80FFCA7CE00839D4A /* HTMLDataListElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -15533,8 +15533,8 @@
F587864902DE3A9A01EA4122 /* CachePolicy.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = CachePolicy.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587866202DE3B1101EA4122 /* SSLKeyGenerator.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = SSLKeyGenerator.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
F587868402DE3B8601EA4122 /* Cursor.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = Cursor.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
- F5973DDE15CFB2030027F804 /* LocaleMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocaleMac.h; sourceTree = "<group>"; };
- F5973DDF15CFB2030027F804 /* LocaleMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocaleMac.mm; sourceTree = "<group>"; };
+ F5973DDE15CFB2030027F804 /* LocaleCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocaleCocoa.h; sourceTree = "<group>"; };
+ F5973DDF15CFB2030027F804 /* LocaleCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = LocaleCocoa.mm; path = "../cocoa/LocaleCocoa.mm"; sourceTree = "<group>"; };
F59C95FD1255B23F000623C0 /* BaseDateAndTimeInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseDateAndTimeInputType.cpp; sourceTree = "<group>"; };
F59C95FE1255B23F000623C0 /* BaseDateAndTimeInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseDateAndTimeInputType.h; sourceTree = "<group>"; };
F5A154251279534D00D0B0C0 /* ValidationMessage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ValidationMessage.cpp; sourceTree = "<group>"; };
@@ -17354,6 +17354,15 @@
name = Products;
sourceTree = "<group>";
};
+ 1C165E4F23ECF55E00B0FCFB /* cocoa */ = {
+ isa = PBXGroup;
+ children = (
+ F5973DDE15CFB2030027F804 /* LocaleCocoa.h */,
+ F5973DDF15CFB2030027F804 /* LocaleCocoa.mm */,
+ );
+ path = cocoa;
+ sourceTree = "<group>";
+ };
1C5FAECA0DCFD8C900D58F78 /* Inspector */ = {
isa = PBXGroup;
children = (
@@ -25142,6 +25151,7 @@
isa = PBXGroup;
children = (
B2B264590D00A77E000ACC1D /* cf */,
+ 1C165E4F23ECF55E00B0FCFB /* cocoa */,
A516E8B2136E04C00076C3C0 /* ios */,
B2C3D9F90D006C1D00EF6F26 /* mac */,
B2C3D9F20D006C1D00EF6F26 /* BidiContext.cpp */,
@@ -25198,8 +25208,6 @@
B2C3D9F90D006C1D00EF6F26 /* mac */ = {
isa = PBXGroup;
children = (
- F5973DDE15CFB2030027F804 /* LocaleMac.h */,
- F5973DDF15CFB2030027F804 /* LocaleMac.mm */,
B2AFFC8C0D00A5DF0030074D /* TextBoundaries.mm */,
CEA84720212622AD00940809 /* TextCheckingMac.mm */,
A1F55DC41F54D3F000EDB75F /* TextEncodingRegistryMac.mm */,
@@ -31350,7 +31358,7 @@
06E81ED70AB5D5E900C87837 /* LocalCurrentGraphicsContext.h in Headers */,
1C43DE6B22AB4B8A001527D9 /* LocalCurrentTraitCollection.h in Headers */,
445775E520472F73008DCE5D /* LocalDefaultSystemAppearance.h in Headers */,
- F5973DE015CFB2030027F804 /* LocaleMac.h in Headers */,
+ F5973DE015CFB2030027F804 /* LocaleCocoa.h in Headers */,
7633A72613D8B33A008501B6 /* LocaleToScriptMapping.h in Headers */,
A516E8B7136E04DB0076C3C0 /* LocalizedDateCache.h in Headers */,
935207BE09BD410A00F2038D /* LocalizedStrings.h in Headers */,
Modified: trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm (256006 => 256007)
--- trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/page/cocoa/MemoryReleaseCocoa.mm 2020-02-07 04:12:39 UTC (rev 256007)
@@ -30,7 +30,7 @@
#import "GCController.h"
#import "IOSurfacePool.h"
#import "LayerPool.h"
-#import "LocaleMac.h"
+#import "LocaleCocoa.h"
#import "SystemFontDatabaseCoreText.h"
#import <notify.h>
#import <pal/spi/ios/GraphicsServicesSPI.h>
@@ -56,7 +56,7 @@
GSFontPurgeFontCache();
#endif
- LocaleMac::releaseMemory();
+ LocaleCocoa::releaseMemory();
for (auto& pool : LayerPool::allLayerPools())
pool->drain();
Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm (256006 => 256007)
--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm 2020-02-07 04:12:39 UTC (rev 256007)
@@ -32,7 +32,7 @@
#import "FontCache.h"
#import "FontCascade.h"
#import "FontDescription.h"
-#import "LocaleMac.h"
+#import "LocaleCocoa.h"
#import "OpenTypeCG.h"
#import "SharedBuffer.h"
#import <CoreText/CoreText.h>
@@ -560,7 +560,7 @@
*newGlyphsPointer = glyphBuffer.glyphs(beginningIndex);
*newAdvancesPointer = glyphBuffer.advances(beginningIndex);
};
- CTFontTransformGlyphsWithLanguage(m_platformData.ctFont(), glyphBuffer.glyphs(beginningIndex), reinterpret_cast<CGSize*>(glyphBuffer.advances(beginningIndex)), glyphBuffer.size() - beginningIndex, options, LocaleMac::canonicalLanguageIdentifierFromString(locale).string().createCFString().get(), handler);
+ CTFontTransformGlyphsWithLanguage(m_platformData.ctFont(), glyphBuffer.glyphs(beginningIndex), reinterpret_cast<CGSize*>(glyphBuffer.advances(beginningIndex)), glyphBuffer.size() - beginningIndex, options, LocaleCocoa::canonicalLanguageIdentifierFromString(locale).string().createCFString().get(), handler);
#else
UNUSED_PARAM(locale);
CTFontTransformGlyphs(m_platformData.ctFont(), glyphBuffer.glyphs(beginningIndex), reinterpret_cast<CGSize*>(glyphBuffer.advances(beginningIndex)), glyphBuffer.size() - beginningIndex, options);
Copied: trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.h (from rev 256006, trunk/Source/WebCore/platform/text/mac/LocaleMac.h) (0 => 256007)
--- trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.h (rev 0)
+++ trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.h 2020-02-07 04:12:39 UTC (rev 256007)
@@ -0,0 +1,100 @@
+/*
+ * 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:
+ *
+ * * 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.
+ */
+
+#pragma once
+
+#include "PlatformLocale.h"
+#include <wtf/Forward.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+OBJC_CLASS NSCalendar;
+OBJC_CLASS NSDateFormatter;
+OBJC_CLASS NSLocale;
+
+namespace WebCore {
+
+class DateComponents;
+
+class LocaleCocoa : public Locale {
+public:
+ explicit LocaleCocoa(NSLocale*);
+ ~LocaleCocoa();
+
+#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
+ String formatDateTime(const DateComponents&, FormatType = FormatTypeUnspecified) override;
+
+ String dateFormat() override;
+ String monthFormat() override;
+ String shortMonthFormat() override;
+ String timeFormat() override;
+ String shortTimeFormat() override;
+ String dateTimeFormatWithSeconds() override;
+ String dateTimeFormatWithoutSeconds() override;
+ const Vector<String>& monthLabels() override;
+ const Vector<String>& shortMonthLabels() override;
+ const Vector<String>& standAloneMonthLabels() override;
+ const Vector<String>& shortStandAloneMonthLabels() override;
+ const Vector<String>& timeAMPMLabels() override;
+#endif
+
+ static AtomString canonicalLanguageIdentifierFromString(const AtomString&);
+ static void releaseMemory();
+
+private:
+ RetainPtr<NSDateFormatter> shortDateFormatter();
+ void initializeLocaleData() override;
+
+ RetainPtr<NSLocale> m_locale;
+ RetainPtr<NSCalendar> m_gregorianCalendar;
+#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
+ Vector<String> m_monthLabels;
+ RetainPtr<NSDateFormatter> timeFormatter();
+ RetainPtr<NSDateFormatter> shortTimeFormatter();
+ RetainPtr<NSDateFormatter> dateTimeFormatterWithSeconds();
+ RetainPtr<NSDateFormatter> dateTimeFormatterWithoutSeconds();
+
+ String m_dateFormat;
+ String m_monthFormat;
+ String m_shortMonthFormat;
+ String m_timeFormatWithSeconds;
+ String m_timeFormatWithoutSeconds;
+ String m_dateTimeFormatWithSeconds;
+ String m_dateTimeFormatWithoutSeconds;
+ Vector<String> m_shortMonthLabels;
+ Vector<String> m_standAloneMonthLabels;
+ Vector<String> m_shortStandAloneMonthLabels;
+ Vector<String> m_timeAMPMLabels;
+#endif
+ bool m_didInitializeNumberData;
+};
+
+} // namespace WebCore
Copied: trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.mm (from rev 256006, trunk/Source/WebCore/platform/text/mac/LocaleMac.mm) (0 => 256007)
--- trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.mm (rev 0)
+++ trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.mm 2020-02-07 04:12:39 UTC (rev 256007)
@@ -0,0 +1,332 @@
+/*
+ * 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:
+ *
+ * * 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 "LocaleCocoa.h"
+
+#import "LocalizedStrings.h"
+#import <Foundation/NSDateFormatter.h>
+#import <Foundation/NSLocale.h>
+#import <wtf/DateMath.h>
+#import <wtf/HashMap.h>
+#import <wtf/Language.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/text/AtomStringHash.h>
+
+#if PLATFORM(IOS_FAMILY)
+#import "LocalizedDateCache.h"
+#endif
+
+namespace WebCore {
+
+static inline String languageFromLocale(const String& locale)
+{
+ String normalizedLocale = locale;
+ normalizedLocale.replace('-', '_');
+ size_t separatorPosition = normalizedLocale.find('_');
+ if (separatorPosition == notFound)
+ return normalizedLocale;
+ return normalizedLocale.left(separatorPosition);
+}
+
+static RetainPtr<NSLocale> determineLocale(const String& locale)
+{
+ RetainPtr<NSLocale> currentLocale = [NSLocale currentLocale];
+ String currentLocaleLanguage = languageFromLocale(String([currentLocale.get() localeIdentifier]));
+ String localeLanguage = languageFromLocale(locale);
+ if (equalIgnoringASCIICase(currentLocaleLanguage, localeLanguage))
+ return currentLocale;
+ // It seems initWithLocaleIdentifier accepts dash-separated locale identifier.
+ return adoptNS([[NSLocale alloc] initWithLocaleIdentifier:locale]);
+}
+
+std::unique_ptr<Locale> Locale::create(const AtomString& locale)
+{
+ return makeUnique<LocaleCocoa>(determineLocale(locale.string()).get());
+}
+
+static RetainPtr<NSDateFormatter> createDateTimeFormatter(NSLocale* locale, NSCalendar* calendar, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle)
+{
+ NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+ [formatter setLocale:locale];
+ [formatter setDateStyle:dateStyle];
+ [formatter setTimeStyle:timeStyle];
+ [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
+ [formatter setCalendar:calendar];
+ return adoptNS(formatter);
+}
+
+LocaleCocoa::LocaleCocoa(NSLocale* locale)
+ : m_locale(locale)
+ , m_gregorianCalendar(adoptNS([[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]))
+ , m_didInitializeNumberData(false)
+{
+ NSArray* availableLanguages = [NSLocale ISOLanguageCodes];
+ // NSLocale returns a lower case NSLocaleLanguageCode so we don't have care about case.
+ NSString* language = [m_locale.get() objectForKey:NSLocaleLanguageCode];
+ if ([availableLanguages indexOfObject:language] == NSNotFound)
+ m_locale = adoptNS([[NSLocale alloc] initWithLocaleIdentifier:defaultLanguage()]);
+ [m_gregorianCalendar.get() setLocale:m_locale.get()];
+}
+
+LocaleCocoa::~LocaleCocoa()
+{
+}
+
+RetainPtr<NSDateFormatter> LocaleCocoa::shortDateFormatter()
+{
+ return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterShortStyle, NSDateFormatterNoStyle);
+}
+
+#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
+String LocaleCocoa::formatDateTime(const DateComponents& dateComponents, FormatType)
+{
+ double msec = dateComponents.millisecondsSinceEpoch();
+ DateComponents::Type type = dateComponents.type();
+
+ // "week" type not supported.
+ ASSERT(type != DateComponents::Invalid);
+ if (type == DateComponents::Week)
+ return String();
+
+ // Incoming msec value is milliseconds since 1970-01-01 00:00:00 UTC. The 1970 epoch.
+ NSTimeInterval secondsSince1970 = (msec / 1000);
+ NSDate *date = [NSDate dateWithTimeIntervalSince1970:secondsSince1970];
+
+ // Return a formatted string.
+ NSDateFormatter *dateFormatter = localizedDateCache().formatterForDateType(type);
+ return [dateFormatter stringFromDate:date];
+}
+
+const Vector<String>& LocaleCocoa::monthLabels()
+{
+ if (!m_monthLabels.isEmpty())
+ return m_monthLabels;
+ m_monthLabels.reserveCapacity(12);
+ NSArray *array = [shortDateFormatter().get() monthSymbols];
+ if ([array count] == 12) {
+ for (unsigned i = 0; i < 12; ++i)
+ m_monthLabels.append(String([array objectAtIndex:i]));
+ return m_monthLabels;
+ }
+ for (auto& name : WTF::monthFullName)
+ m_monthLabels.append(name);
+ return m_monthLabels;
+}
+
+RetainPtr<NSDateFormatter> LocaleCocoa::timeFormatter()
+{
+ return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterNoStyle, NSDateFormatterMediumStyle);
+}
+
+RetainPtr<NSDateFormatter> LocaleCocoa::shortTimeFormatter()
+{
+ return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterNoStyle, NSDateFormatterShortStyle);
+}
+
+RetainPtr<NSDateFormatter> LocaleCocoa::dateTimeFormatterWithSeconds()
+{
+ return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterShortStyle, NSDateFormatterMediumStyle);
+}
+
+RetainPtr<NSDateFormatter> LocaleCocoa::dateTimeFormatterWithoutSeconds()
+{
+ return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterShortStyle, NSDateFormatterShortStyle);
+}
+
+String LocaleCocoa::dateFormat()
+{
+ if (!m_dateFormat.isNull())
+ return m_dateFormat;
+ m_dateFormat = [shortDateFormatter().get() dateFormat];
+ return m_dateFormat;
+}
+
+String LocaleCocoa::monthFormat()
+{
+ if (!m_monthFormat.isNull())
+ return m_monthFormat;
+ // Gets a format for "MMMM" because Windows API always provides formats for
+ // "MMMM" in some locales.
+ m_monthFormat = [NSDateFormatter dateFormatFromTemplate:@"yyyyMMMM" options:0 locale:m_locale.get()];
+ return m_monthFormat;
+}
+
+String LocaleCocoa::shortMonthFormat()
+{
+ if (!m_shortMonthFormat.isNull())
+ return m_shortMonthFormat;
+ m_shortMonthFormat = [NSDateFormatter dateFormatFromTemplate:@"yyyyMMM" options:0 locale:m_locale.get()];
+ return m_shortMonthFormat;
+}
+
+String LocaleCocoa::timeFormat()
+{
+ if (!m_timeFormatWithSeconds.isNull())
+ return m_timeFormatWithSeconds;
+ m_timeFormatWithSeconds = [timeFormatter().get() dateFormat];
+ return m_timeFormatWithSeconds;
+}
+
+String LocaleCocoa::shortTimeFormat()
+{
+ if (!m_timeFormatWithoutSeconds.isNull())
+ return m_timeFormatWithoutSeconds;
+ m_timeFormatWithoutSeconds = [shortTimeFormatter().get() dateFormat];
+ return m_timeFormatWithoutSeconds;
+}
+
+String LocaleCocoa::dateTimeFormatWithSeconds()
+{
+ if (!m_dateTimeFormatWithSeconds.isNull())
+ return m_dateTimeFormatWithSeconds;
+ m_dateTimeFormatWithSeconds = [dateTimeFormatterWithSeconds().get() dateFormat];
+ return m_dateTimeFormatWithSeconds;
+}
+
+String LocaleCocoa::dateTimeFormatWithoutSeconds()
+{
+ if (!m_dateTimeFormatWithoutSeconds.isNull())
+ return m_dateTimeFormatWithoutSeconds;
+ m_dateTimeFormatWithoutSeconds = [dateTimeFormatterWithoutSeconds().get() dateFormat];
+ return m_dateTimeFormatWithoutSeconds;
+}
+
+const Vector<String>& LocaleCocoa::shortMonthLabels()
+{
+ if (!m_shortMonthLabels.isEmpty())
+ return m_shortMonthLabels;
+ m_shortMonthLabels.reserveCapacity(12);
+ NSArray *array = [shortDateFormatter().get() shortMonthSymbols];
+ if ([array count] == 12) {
+ for (unsigned i = 0; i < 12; ++i)
+ m_shortMonthLabels.append([array objectAtIndex:i]);
+ return m_shortMonthLabels;
+ }
+ for (auto& name : WTF::monthName)
+ m_shortMonthLabels.append(name);
+ return m_shortMonthLabels;
+}
+
+const Vector<String>& LocaleCocoa::standAloneMonthLabels()
+{
+ if (!m_standAloneMonthLabels.isEmpty())
+ return m_standAloneMonthLabels;
+ NSArray *array = [shortDateFormatter().get() standaloneMonthSymbols];
+ if ([array count] == 12) {
+ m_standAloneMonthLabels.reserveCapacity(12);
+ for (unsigned i = 0; i < 12; ++i)
+ m_standAloneMonthLabels.append([array objectAtIndex:i]);
+ return m_standAloneMonthLabels;
+ }
+ m_standAloneMonthLabels = shortMonthLabels();
+ return m_standAloneMonthLabels;
+}
+
+const Vector<String>& LocaleCocoa::shortStandAloneMonthLabels()
+{
+ if (!m_shortStandAloneMonthLabels.isEmpty())
+ return m_shortStandAloneMonthLabels;
+ NSArray *array = [shortDateFormatter().get() shortStandaloneMonthSymbols];
+ if ([array count] == 12) {
+ m_shortStandAloneMonthLabels.reserveCapacity(12);
+ for (unsigned i = 0; i < 12; ++i)
+ m_shortStandAloneMonthLabels.append([array objectAtIndex:i]);
+ return m_shortStandAloneMonthLabels;
+ }
+ m_shortStandAloneMonthLabels = shortMonthLabels();
+ return m_shortStandAloneMonthLabels;
+}
+
+const Vector<String>& LocaleCocoa::timeAMPMLabels()
+{
+ if (!m_timeAMPMLabels.isEmpty())
+ return m_timeAMPMLabels;
+ m_timeAMPMLabels.reserveCapacity(2);
+ RetainPtr<NSDateFormatter> formatter = shortTimeFormatter();
+ m_timeAMPMLabels.append([formatter.get() AMSymbol]);
+ m_timeAMPMLabels.append([formatter.get() PMSymbol]);
+ return m_timeAMPMLabels;
+}
+
+#endif
+
+using CanonicalLocaleMap = HashMap<AtomString, AtomString>;
+
+static CanonicalLocaleMap& canonicalLocaleMap()
+{
+ static NeverDestroyed<CanonicalLocaleMap> canonicalLocaleMap;
+ return canonicalLocaleMap.get();
+}
+
+AtomString LocaleCocoa::canonicalLanguageIdentifierFromString(const AtomString& string)
+{
+ return canonicalLocaleMap().ensure(string, [&] {
+ return [NSLocale canonicalLanguageIdentifierFromString:string];
+ }).iterator->value;
+}
+
+void LocaleCocoa::releaseMemory()
+{
+ canonicalLocaleMap().clear();
+}
+
+void LocaleCocoa::initializeLocaleData()
+{
+ if (m_didInitializeNumberData)
+ return;
+ m_didInitializeNumberData = true;
+
+ RetainPtr<NSNumberFormatter> formatter = adoptNS([[NSNumberFormatter alloc] init]);
+ [formatter.get() setLocale:m_locale.get()];
+ [formatter.get() setNumberStyle:NSNumberFormatterDecimalStyle];
+ [formatter.get() setUsesGroupingSeparator:NO];
+
+ RetainPtr<NSNumber> sampleNumber = adoptNS([[NSNumber alloc] initWithDouble:9876543210]);
+ String nineToZero([formatter.get() stringFromNumber:sampleNumber.get()]);
+ if (nineToZero.length() != 10)
+ return;
+ Vector<String, DecimalSymbolsSize> symbols;
+ for (unsigned i = 0; i < 10; ++i)
+ symbols.append(nineToZero.substring(9 - i, 1));
+ ASSERT(symbols.size() == DecimalSeparatorIndex);
+ symbols.append([formatter.get() decimalSeparator]);
+ ASSERT(symbols.size() == GroupSeparatorIndex);
+ symbols.append([formatter.get() groupingSeparator]);
+ ASSERT(symbols.size() == DecimalSymbolsSize);
+
+ String positivePrefix([formatter.get() positivePrefix]);
+ String positiveSuffix([formatter.get() positiveSuffix]);
+ String negativePrefix([formatter.get() negativePrefix]);
+ String negativeSuffix([formatter.get() negativeSuffix]);
+ setLocaleData(symbols, positivePrefix, positiveSuffix, negativePrefix, negativeSuffix);
+}
+
+}
Deleted: trunk/Source/WebCore/platform/text/mac/LocaleMac.h (256006 => 256007)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.h 2020-02-07 04:12:39 UTC (rev 256007)
@@ -1,102 +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:
- *
- * * 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.
- */
-
-#ifndef LocaleMac_h
-#define LocaleMac_h
-
-#include "PlatformLocale.h"
-#include <wtf/Forward.h>
-#include <wtf/RetainPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
-
-OBJC_CLASS NSCalendar;
-OBJC_CLASS NSDateFormatter;
-OBJC_CLASS NSLocale;
-
-namespace WebCore {
-
-class DateComponents;
-
-class LocaleMac : public Locale {
-public:
- explicit LocaleMac(NSLocale*);
- ~LocaleMac();
-
-#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
- String formatDateTime(const DateComponents&, FormatType = FormatTypeUnspecified) override;
-
- String dateFormat() override;
- String monthFormat() override;
- String shortMonthFormat() override;
- String timeFormat() override;
- String shortTimeFormat() override;
- String dateTimeFormatWithSeconds() override;
- String dateTimeFormatWithoutSeconds() override;
- const Vector<String>& monthLabels() override;
- const Vector<String>& shortMonthLabels() override;
- const Vector<String>& standAloneMonthLabels() override;
- const Vector<String>& shortStandAloneMonthLabels() override;
- const Vector<String>& timeAMPMLabels() override;
-#endif
-
- static AtomString canonicalLanguageIdentifierFromString(const AtomString&);
- static void releaseMemory();
-
-private:
- RetainPtr<NSDateFormatter> shortDateFormatter();
- void initializeLocaleData() override;
-
- RetainPtr<NSLocale> m_locale;
- RetainPtr<NSCalendar> m_gregorianCalendar;
-#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
- Vector<String> m_monthLabels;
- RetainPtr<NSDateFormatter> timeFormatter();
- RetainPtr<NSDateFormatter> shortTimeFormatter();
- RetainPtr<NSDateFormatter> dateTimeFormatterWithSeconds();
- RetainPtr<NSDateFormatter> dateTimeFormatterWithoutSeconds();
-
- String m_dateFormat;
- String m_monthFormat;
- String m_shortMonthFormat;
- String m_timeFormatWithSeconds;
- String m_timeFormatWithoutSeconds;
- String m_dateTimeFormatWithSeconds;
- String m_dateTimeFormatWithoutSeconds;
- Vector<String> m_shortMonthLabels;
- Vector<String> m_standAloneMonthLabels;
- Vector<String> m_shortStandAloneMonthLabels;
- Vector<String> m_timeAMPMLabels;
-#endif
- bool m_didInitializeNumberData;
-};
-
-} // namespace WebCore
-#endif
Deleted: trunk/Source/WebCore/platform/text/mac/LocaleMac.mm (256006 => 256007)
--- trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2020-02-07 03:45:12 UTC (rev 256006)
+++ trunk/Source/WebCore/platform/text/mac/LocaleMac.mm 2020-02-07 04:12:39 UTC (rev 256007)
@@ -1,332 +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:
- *
- * * 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 "LocaleMac.h"
-
-#import "LocalizedStrings.h"
-#import <Foundation/NSDateFormatter.h>
-#import <Foundation/NSLocale.h>
-#import <wtf/DateMath.h>
-#import <wtf/HashMap.h>
-#import <wtf/Language.h>
-#import <wtf/RetainPtr.h>
-#import <wtf/text/AtomStringHash.h>
-
-#if PLATFORM(IOS_FAMILY)
-#import "LocalizedDateCache.h"
-#endif
-
-namespace WebCore {
-
-static inline String languageFromLocale(const String& locale)
-{
- String normalizedLocale = locale;
- normalizedLocale.replace('-', '_');
- size_t separatorPosition = normalizedLocale.find('_');
- if (separatorPosition == notFound)
- return normalizedLocale;
- return normalizedLocale.left(separatorPosition);
-}
-
-static RetainPtr<NSLocale> determineLocale(const String& locale)
-{
- RetainPtr<NSLocale> currentLocale = [NSLocale currentLocale];
- String currentLocaleLanguage = languageFromLocale(String([currentLocale.get() localeIdentifier]));
- String localeLanguage = languageFromLocale(locale);
- if (equalIgnoringASCIICase(currentLocaleLanguage, localeLanguage))
- return currentLocale;
- // It seems initWithLocaleIdentifier accepts dash-separated locale identifier.
- return adoptNS([[NSLocale alloc] initWithLocaleIdentifier:locale]);
-}
-
-std::unique_ptr<Locale> Locale::create(const AtomString& locale)
-{
- return makeUnique<LocaleMac>(determineLocale(locale.string()).get());
-}
-
-static RetainPtr<NSDateFormatter> createDateTimeFormatter(NSLocale* locale, NSCalendar* calendar, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle)
-{
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
- [formatter setLocale:locale];
- [formatter setDateStyle:dateStyle];
- [formatter setTimeStyle:timeStyle];
- [formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
- [formatter setCalendar:calendar];
- return adoptNS(formatter);
-}
-
-LocaleMac::LocaleMac(NSLocale* locale)
- : m_locale(locale)
- , m_gregorianCalendar(adoptNS([[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]))
- , m_didInitializeNumberData(false)
-{
- NSArray* availableLanguages = [NSLocale ISOLanguageCodes];
- // NSLocale returns a lower case NSLocaleLanguageCode so we don't have care about case.
- NSString* language = [m_locale.get() objectForKey:NSLocaleLanguageCode];
- if ([availableLanguages indexOfObject:language] == NSNotFound)
- m_locale = adoptNS([[NSLocale alloc] initWithLocaleIdentifier:defaultLanguage()]);
- [m_gregorianCalendar.get() setLocale:m_locale.get()];
-}
-
-LocaleMac::~LocaleMac()
-{
-}
-
-RetainPtr<NSDateFormatter> LocaleMac::shortDateFormatter()
-{
- return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterShortStyle, NSDateFormatterNoStyle);
-}
-
-#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
-String LocaleMac::formatDateTime(const DateComponents& dateComponents, FormatType)
-{
- double msec = dateComponents.millisecondsSinceEpoch();
- DateComponents::Type type = dateComponents.type();
-
- // "week" type not supported.
- ASSERT(type != DateComponents::Invalid);
- if (type == DateComponents::Week)
- return String();
-
- // Incoming msec value is milliseconds since 1970-01-01 00:00:00 UTC. The 1970 epoch.
- NSTimeInterval secondsSince1970 = (msec / 1000);
- NSDate *date = [NSDate dateWithTimeIntervalSince1970:secondsSince1970];
-
- // Return a formatted string.
- NSDateFormatter *dateFormatter = localizedDateCache().formatterForDateType(type);
- return [dateFormatter stringFromDate:date];
-}
-
-const Vector<String>& LocaleMac::monthLabels()
-{
- if (!m_monthLabels.isEmpty())
- return m_monthLabels;
- m_monthLabels.reserveCapacity(12);
- NSArray *array = [shortDateFormatter().get() monthSymbols];
- if ([array count] == 12) {
- for (unsigned i = 0; i < 12; ++i)
- m_monthLabels.append(String([array objectAtIndex:i]));
- return m_monthLabels;
- }
- for (auto& name : WTF::monthFullName)
- m_monthLabels.append(name);
- return m_monthLabels;
-}
-
-RetainPtr<NSDateFormatter> LocaleMac::timeFormatter()
-{
- return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterNoStyle, NSDateFormatterMediumStyle);
-}
-
-RetainPtr<NSDateFormatter> LocaleMac::shortTimeFormatter()
-{
- return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterNoStyle, NSDateFormatterShortStyle);
-}
-
-RetainPtr<NSDateFormatter> LocaleMac::dateTimeFormatterWithSeconds()
-{
- return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterShortStyle, NSDateFormatterMediumStyle);
-}
-
-RetainPtr<NSDateFormatter> LocaleMac::dateTimeFormatterWithoutSeconds()
-{
- return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterShortStyle, NSDateFormatterShortStyle);
-}
-
-String LocaleMac::dateFormat()
-{
- if (!m_dateFormat.isNull())
- return m_dateFormat;
- m_dateFormat = [shortDateFormatter().get() dateFormat];
- return m_dateFormat;
-}
-
-String LocaleMac::monthFormat()
-{
- if (!m_monthFormat.isNull())
- return m_monthFormat;
- // Gets a format for "MMMM" because Windows API always provides formats for
- // "MMMM" in some locales.
- m_monthFormat = [NSDateFormatter dateFormatFromTemplate:@"yyyyMMMM" options:0 locale:m_locale.get()];
- return m_monthFormat;
-}
-
-String LocaleMac::shortMonthFormat()
-{
- if (!m_shortMonthFormat.isNull())
- return m_shortMonthFormat;
- m_shortMonthFormat = [NSDateFormatter dateFormatFromTemplate:@"yyyyMMM" options:0 locale:m_locale.get()];
- return m_shortMonthFormat;
-}
-
-String LocaleMac::timeFormat()
-{
- if (!m_timeFormatWithSeconds.isNull())
- return m_timeFormatWithSeconds;
- m_timeFormatWithSeconds = [timeFormatter().get() dateFormat];
- return m_timeFormatWithSeconds;
-}
-
-String LocaleMac::shortTimeFormat()
-{
- if (!m_timeFormatWithoutSeconds.isNull())
- return m_timeFormatWithoutSeconds;
- m_timeFormatWithoutSeconds = [shortTimeFormatter().get() dateFormat];
- return m_timeFormatWithoutSeconds;
-}
-
-String LocaleMac::dateTimeFormatWithSeconds()
-{
- if (!m_dateTimeFormatWithSeconds.isNull())
- return m_dateTimeFormatWithSeconds;
- m_dateTimeFormatWithSeconds = [dateTimeFormatterWithSeconds().get() dateFormat];
- return m_dateTimeFormatWithSeconds;
-}
-
-String LocaleMac::dateTimeFormatWithoutSeconds()
-{
- if (!m_dateTimeFormatWithoutSeconds.isNull())
- return m_dateTimeFormatWithoutSeconds;
- m_dateTimeFormatWithoutSeconds = [dateTimeFormatterWithoutSeconds().get() dateFormat];
- return m_dateTimeFormatWithoutSeconds;
-}
-
-const Vector<String>& LocaleMac::shortMonthLabels()
-{
- if (!m_shortMonthLabels.isEmpty())
- return m_shortMonthLabels;
- m_shortMonthLabels.reserveCapacity(12);
- NSArray *array = [shortDateFormatter().get() shortMonthSymbols];
- if ([array count] == 12) {
- for (unsigned i = 0; i < 12; ++i)
- m_shortMonthLabels.append([array objectAtIndex:i]);
- return m_shortMonthLabels;
- }
- for (auto& name : WTF::monthName)
- m_shortMonthLabels.append(name);
- return m_shortMonthLabels;
-}
-
-const Vector<String>& LocaleMac::standAloneMonthLabels()
-{
- if (!m_standAloneMonthLabels.isEmpty())
- return m_standAloneMonthLabels;
- NSArray *array = [shortDateFormatter().get() standaloneMonthSymbols];
- if ([array count] == 12) {
- m_standAloneMonthLabels.reserveCapacity(12);
- for (unsigned i = 0; i < 12; ++i)
- m_standAloneMonthLabels.append([array objectAtIndex:i]);
- return m_standAloneMonthLabels;
- }
- m_standAloneMonthLabels = shortMonthLabels();
- return m_standAloneMonthLabels;
-}
-
-const Vector<String>& LocaleMac::shortStandAloneMonthLabels()
-{
- if (!m_shortStandAloneMonthLabels.isEmpty())
- return m_shortStandAloneMonthLabels;
- NSArray *array = [shortDateFormatter().get() shortStandaloneMonthSymbols];
- if ([array count] == 12) {
- m_shortStandAloneMonthLabels.reserveCapacity(12);
- for (unsigned i = 0; i < 12; ++i)
- m_shortStandAloneMonthLabels.append([array objectAtIndex:i]);
- return m_shortStandAloneMonthLabels;
- }
- m_shortStandAloneMonthLabels = shortMonthLabels();
- return m_shortStandAloneMonthLabels;
-}
-
-const Vector<String>& LocaleMac::timeAMPMLabels()
-{
- if (!m_timeAMPMLabels.isEmpty())
- return m_timeAMPMLabels;
- m_timeAMPMLabels.reserveCapacity(2);
- RetainPtr<NSDateFormatter> formatter = shortTimeFormatter();
- m_timeAMPMLabels.append([formatter.get() AMSymbol]);
- m_timeAMPMLabels.append([formatter.get() PMSymbol]);
- return m_timeAMPMLabels;
-}
-
-#endif
-
-using CanonicalLocaleMap = HashMap<AtomString, AtomString>;
-
-static CanonicalLocaleMap& canonicalLocaleMap()
-{
- static NeverDestroyed<CanonicalLocaleMap> canonicalLocaleMap;
- return canonicalLocaleMap.get();
-}
-
-AtomString LocaleMac::canonicalLanguageIdentifierFromString(const AtomString& string)
-{
- return canonicalLocaleMap().ensure(string, [&] {
- return [NSLocale canonicalLanguageIdentifierFromString:string];
- }).iterator->value;
-}
-
-void LocaleMac::releaseMemory()
-{
- canonicalLocaleMap().clear();
-}
-
-void LocaleMac::initializeLocaleData()
-{
- if (m_didInitializeNumberData)
- return;
- m_didInitializeNumberData = true;
-
- RetainPtr<NSNumberFormatter> formatter = adoptNS([[NSNumberFormatter alloc] init]);
- [formatter.get() setLocale:m_locale.get()];
- [formatter.get() setNumberStyle:NSNumberFormatterDecimalStyle];
- [formatter.get() setUsesGroupingSeparator:NO];
-
- RetainPtr<NSNumber> sampleNumber = adoptNS([[NSNumber alloc] initWithDouble:9876543210]);
- String nineToZero([formatter.get() stringFromNumber:sampleNumber.get()]);
- if (nineToZero.length() != 10)
- return;
- Vector<String, DecimalSymbolsSize> symbols;
- for (unsigned i = 0; i < 10; ++i)
- symbols.append(nineToZero.substring(9 - i, 1));
- ASSERT(symbols.size() == DecimalSeparatorIndex);
- symbols.append([formatter.get() decimalSeparator]);
- ASSERT(symbols.size() == GroupSeparatorIndex);
- symbols.append([formatter.get() groupingSeparator]);
- ASSERT(symbols.size() == DecimalSymbolsSize);
-
- String positivePrefix([formatter.get() positivePrefix]);
- String positiveSuffix([formatter.get() positiveSuffix]);
- String negativePrefix([formatter.get() negativePrefix]);
- String negativeSuffix([formatter.get() negativeSuffix]);
- setLocaleData(symbols, positivePrefix, positiveSuffix, negativePrefix, negativeSuffix);
-}
-
-}