Bug 152715

Summary: TextBreakIterator uses an internal implementation detail of NSLocale
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, darin, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch none

Description Myles C. Maxfield 2016-01-04 15:24:46 PST
TextBreakIterator uses an internal implementation detail of NSLocale
Comment 1 Myles C. Maxfield 2016-01-04 15:25:37 PST
Created attachment 268241 [details]
Patch
Comment 2 Myles C. Maxfield 2016-01-04 15:26:10 PST
Created attachment 268242 [details]
Patch
Comment 3 Myles C. Maxfield 2016-01-04 15:26:39 PST
<rdar://problem/23775121>
Comment 4 WebKit Commit Bot 2016-01-04 16:42:59 PST
Comment on attachment 268242 [details]
Patch

Clearing flags on attachment: 268242

Committed r194566: <http://trac.webkit.org/changeset/194566>
Comment 5 WebKit Commit Bot 2016-01-04 16:43:03 PST
All reviewed patches have been landed.  Closing bug.
Comment 6 Darin Adler 2016-01-13 08:53:58 PST
Comment on attachment 268242 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=268242&action=review

> Source/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm:41
> +    NSArray *languagesArray = [NSLocale preferredLanguages];

To be consistent with the usage in the rest of this file it would be better to call CFLocaleCopyPreferredLanguages rather than [NSLocale preferredLanguages].

There is a change in behavior here: the NSLocale/CFLocale functions create a new array with the result of CFLocaleCreateCanonicalLanguageIdentifierFromString on each item in the array. That means that:

1) The code in this function that checks if the item from the array is an NSString is no longer needed since the NSLocale/CFLocale function guarantees it will return an array of strings, with no objects of other types.
2) The code below in two different functions that calls canonicalLanguageIdentifier on the result of this function is no longer needed; the result of this function is already guaranteed to be a canonical language identifier. I suggest moving the call to CFLocaleCreateCanonicalLanguageIdentifierFromString into the textBreakLocalePreference function and removing the canonicalLanguageIdentifier function entirely.
Comment 7 Myles C. Maxfield 2016-01-13 16:30:30 PST
Comment on attachment 268242 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=268242&action=review

>> Source/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm:41
>> +    NSArray *languagesArray = [NSLocale preferredLanguages];
> 
> To be consistent with the usage in the rest of this file it would be better to call CFLocaleCopyPreferredLanguages rather than [NSLocale preferredLanguages].
> 
> There is a change in behavior here: the NSLocale/CFLocale functions create a new array with the result of CFLocaleCreateCanonicalLanguageIdentifierFromString on each item in the array. That means that:
> 
> 1) The code in this function that checks if the item from the array is an NSString is no longer needed since the NSLocale/CFLocale function guarantees it will return an array of strings, with no objects of other types.
> 2) The code below in two different functions that calls canonicalLanguageIdentifier on the result of this function is no longer needed; the result of this function is already guaranteed to be a canonical language identifier. I suggest moving the call to CFLocaleCreateCanonicalLanguageIdentifierFromString into the textBreakLocalePreference function and removing the canonicalLanguageIdentifier function entirely.

http://trac.webkit.org/changeset/195001
Comment 8 Myles C. Maxfield 2016-01-13 22:22:59 PST
Comment on attachment 268242 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=268242&action=review

>>> Source/WebCore/platform/text/mac/TextBreakIteratorInternalICUMac.mm:41
>>> +    NSArray *languagesArray = [NSLocale preferredLanguages];
>> 
>> To be consistent with the usage in the rest of this file it would be better to call CFLocaleCopyPreferredLanguages rather than [NSLocale preferredLanguages].
>> 
>> There is a change in behavior here: the NSLocale/CFLocale functions create a new array with the result of CFLocaleCreateCanonicalLanguageIdentifierFromString on each item in the array. That means that:
>> 
>> 1) The code in this function that checks if the item from the array is an NSString is no longer needed since the NSLocale/CFLocale function guarantees it will return an array of strings, with no objects of other types.
>> 2) The code below in two different functions that calls canonicalLanguageIdentifier on the result of this function is no longer needed; the result of this function is already guaranteed to be a canonical language identifier. I suggest moving the call to CFLocaleCreateCanonicalLanguageIdentifierFromString into the textBreakLocalePreference function and removing the canonicalLanguageIdentifier function entirely.
> 
> http://trac.webkit.org/changeset/195001

http://trac.webkit.org/changeset/195006