Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: third_party/WebKit/Source/platform/text/LocaleMac.mm

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/text/LocaleMac.h" 31 #include "platform/text/LocaleMac.h"
32 32
33 #import <Foundation/NSDateFormatter.h> 33 #import <Foundation/NSDateFormatter.h>
34 #import <Foundation/NSLocale.h> 34 #import <Foundation/NSLocale.h>
35 #include "platform/Language.h" 35 #include "platform/Language.h"
36 #include "platform/LayoutTestSupport.h" 36 #include "platform/LayoutTestSupport.h"
37 #include "wtf/DateMath.h" 37 #include "wtf/DateMath.h"
38 #include "wtf/PtrUtil.h" 38 #include "wtf/PassOwnPtr.h"
39 #include "wtf/RetainPtr.h" 39 #include "wtf/RetainPtr.h"
40 #include "wtf/text/StringBuilder.h" 40 #include "wtf/text/StringBuilder.h"
41 #include <memory>
42 41
43 namespace blink { 42 namespace blink {
44 43
45 static inline String languageFromLocale(const String& locale) 44 static inline String languageFromLocale(const String& locale)
46 { 45 {
47 String normalizedLocale = locale; 46 String normalizedLocale = locale;
48 normalizedLocale.replace('-', '_'); 47 normalizedLocale.replace('-', '_');
49 size_t separatorPosition = normalizedLocale.find('_'); 48 size_t separatorPosition = normalizedLocale.find('_');
50 if (separatorPosition == kNotFound) 49 if (separatorPosition == kNotFound)
51 return normalizedLocale; 50 return normalizedLocale;
52 return normalizedLocale.left(separatorPosition); 51 return normalizedLocale.left(separatorPosition);
53 } 52 }
54 53
55 static RetainPtr<NSLocale> determineLocale(const String& locale) 54 static RetainPtr<NSLocale> determineLocale(const String& locale)
56 { 55 {
57 if (!LayoutTestSupport::isRunningLayoutTest()) { 56 if (!LayoutTestSupport::isRunningLayoutTest()) {
58 RetainPtr<NSLocale> currentLocale = [NSLocale currentLocale]; 57 RetainPtr<NSLocale> currentLocale = [NSLocale currentLocale];
59 String currentLocaleLanguage = languageFromLocale(String([currentLocale. get() localeIdentifier])); 58 String currentLocaleLanguage = languageFromLocale(String([currentLocale. get() localeIdentifier]));
60 String localeLanguage = languageFromLocale(locale); 59 String localeLanguage = languageFromLocale(locale);
61 if (equalIgnoringCase(currentLocaleLanguage, localeLanguage)) 60 if (equalIgnoringCase(currentLocaleLanguage, localeLanguage))
62 return currentLocale; 61 return currentLocale;
63 } 62 }
64 // It seems initWithLocaleIdentifier accepts dash-separated locale identifie r. 63 // It seems initWithLocaleIdentifier accepts dash-separated locale identifie r.
65 return RetainPtr<NSLocale>(AdoptNS, [[NSLocale alloc] initWithLocaleIdentifi er:locale]); 64 return RetainPtr<NSLocale>(AdoptNS, [[NSLocale alloc] initWithLocaleIdentifi er:locale]);
66 } 65 }
67 66
68 std::unique_ptr<Locale> Locale::create(const String& locale) 67 PassOwnPtr<Locale> Locale::create(const String& locale)
69 { 68 {
70 return LocaleMac::create(determineLocale(locale).get()); 69 return LocaleMac::create(determineLocale(locale).get());
71 } 70 }
72 71
73 static RetainPtr<NSDateFormatter> createDateTimeFormatter(NSLocale* locale, NSCa lendar* calendar, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle ) 72 static RetainPtr<NSDateFormatter> createDateTimeFormatter(NSLocale* locale, NSCa lendar* calendar, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle )
74 { 73 {
75 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 74 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
76 [formatter setLocale:locale]; 75 [formatter setLocale:locale];
77 [formatter setDateStyle:dateStyle]; 76 [formatter setDateStyle:dateStyle];
78 [formatter setTimeStyle:timeStyle]; 77 [formatter setTimeStyle:timeStyle];
(...skipping 12 matching lines...) Expand all
91 NSString* language = [m_locale.get() objectForKey:NSLocaleLanguageCode]; 90 NSString* language = [m_locale.get() objectForKey:NSLocaleLanguageCode];
92 if ([availableLanguages indexOfObject:language] == NSNotFound) 91 if ([availableLanguages indexOfObject:language] == NSNotFound)
93 m_locale.adoptNS([[NSLocale alloc] initWithLocaleIdentifier:defaultLangu age()]); 92 m_locale.adoptNS([[NSLocale alloc] initWithLocaleIdentifier:defaultLangu age()]);
94 [m_gregorianCalendar.get() setLocale:m_locale.get()]; 93 [m_gregorianCalendar.get() setLocale:m_locale.get()];
95 } 94 }
96 95
97 LocaleMac::~LocaleMac() 96 LocaleMac::~LocaleMac()
98 { 97 {
99 } 98 }
100 99
101 std::unique_ptr<LocaleMac> LocaleMac::create(const String& localeIdentifier) 100 PassOwnPtr<LocaleMac> LocaleMac::create(const String& localeIdentifier)
102 { 101 {
103 RetainPtr<NSLocale> locale = [[NSLocale alloc] initWithLocaleIdentifier:loca leIdentifier]; 102 RetainPtr<NSLocale> locale = [[NSLocale alloc] initWithLocaleIdentifier:loca leIdentifier];
104 return wrapUnique(new LocaleMac(locale.get())); 103 return adoptPtr(new LocaleMac(locale.get()));
105 } 104 }
106 105
107 std::unique_ptr<LocaleMac> LocaleMac::create(NSLocale* locale) 106 PassOwnPtr<LocaleMac> LocaleMac::create(NSLocale* locale)
108 { 107 {
109 return wrapUnique(new LocaleMac(locale)); 108 return adoptPtr(new LocaleMac(locale));
110 } 109 }
111 110
112 RetainPtr<NSDateFormatter> LocaleMac::shortDateFormatter() 111 RetainPtr<NSDateFormatter> LocaleMac::shortDateFormatter()
113 { 112 {
114 return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NS DateFormatterShortStyle, NSDateFormatterNoStyle); 113 return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NS DateFormatterShortStyle, NSDateFormatterNoStyle);
115 } 114 }
116 115
117 const Vector<String>& LocaleMac::monthLabels() 116 const Vector<String>& LocaleMac::monthLabels()
118 { 117 {
119 if (!m_monthLabels.isEmpty()) 118 if (!m_monthLabels.isEmpty())
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 ASSERT(symbols.size() == DecimalSymbolsSize); 320 ASSERT(symbols.size() == DecimalSymbolsSize);
322 321
323 String positivePrefix([formatter.get() positivePrefix]); 322 String positivePrefix([formatter.get() positivePrefix]);
324 String positiveSuffix([formatter.get() positiveSuffix]); 323 String positiveSuffix([formatter.get() positiveSuffix]);
325 String negativePrefix([formatter.get() negativePrefix]); 324 String negativePrefix([formatter.get() negativePrefix]);
326 String negativeSuffix([formatter.get() negativeSuffix]); 325 String negativeSuffix([formatter.get() negativeSuffix]);
327 setLocaleData(symbols, positivePrefix, positiveSuffix, negativePrefix, negat iveSuffix); 326 setLocaleData(symbols, positivePrefix, positiveSuffix, negativePrefix, negat iveSuffix);
328 } 327 }
329 328
330 } 329 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/text/LocaleMac.h ('k') | third_party/WebKit/Source/platform/text/LocaleMacTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698