This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporary Workarounds for CoreLib Surface Area
The UAP System.Private.CoreLib is missing two recent changes and we are blocked consuming it until we get CoreFX UAP. To unbreak the cycle, paper over a couple recent breaking surface area changes in System.Private.CoreLib until we get a new UAP package containing it. At that point, this commit can be reverted.
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/System.Runtime.Extensions/src/System/Globalization/Extensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace System.Globalization | ||
{ | ||
public static class GlobalizationExtensions | ||
{ | ||
public static StringComparer GetStringComparer(this CompareInfo compareInfo, CompareOptions options) | ||
{ | ||
if (compareInfo == null) | ||
{ | ||
throw new ArgumentNullException(nameof(compareInfo)); | ||
} | ||
|
||
if (options == CompareOptions.Ordinal) | ||
{ | ||
return StringComparer.Ordinal; | ||
} | ||
|
||
if (options == CompareOptions.OrdinalIgnoreCase) | ||
{ | ||
return StringComparer.OrdinalIgnoreCase; | ||
} | ||
|
||
if ((options & CultureAwareComparer.ValidCompareMaskOffFlags) != 0) | ||
{ | ||
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options)); | ||
} | ||
|
||
return new CultureAwareComparer(compareInfo, options); | ||
} | ||
} | ||
|
||
internal sealed class CultureAwareComparer : StringComparer | ||
{ | ||
internal const CompareOptions ValidCompareMaskOffFlags = | ||
~(CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace | | ||
CompareOptions.IgnoreWidth | CompareOptions.IgnoreKanaType | CompareOptions.StringSort); | ||
|
||
private readonly CompareInfo _compareInfo; | ||
private readonly CompareOptions _options; | ||
|
||
internal CultureAwareComparer(CompareInfo compareInfo, CompareOptions options) | ||
{ | ||
Debug.Assert((options & ValidCompareMaskOffFlags) == 0); | ||
_compareInfo = compareInfo; | ||
_options = options; | ||
} | ||
|
||
public override int Compare(string x, string y) | ||
{ | ||
if (Object.ReferenceEquals(x, y)) return 0; | ||
if (x == null) return -1; | ||
if (y == null) return 1; | ||
return _compareInfo.Compare(x, y, _options); | ||
} | ||
|
||
public override bool Equals(string x, string y) | ||
{ | ||
if (Object.ReferenceEquals(x, y)) return true; | ||
if (x == null || y == null) return false; | ||
|
||
return (_compareInfo.Compare(x, y, _options) == 0); | ||
} | ||
|
||
public override int GetHashCode(string obj) | ||
{ | ||
if (obj == null) | ||
{ | ||
throw new ArgumentNullException(nameof(obj)); | ||
} | ||
|
||
// StringSort used in compare operation and not with the hashing | ||
return _compareInfo.GetHashCode(obj, _options & (~CompareOptions.StringSort)); | ||
} | ||
|
||
// Equals method for the comparer itself. | ||
public override bool Equals(object obj) | ||
{ | ||
CultureAwareComparer comparer = obj as CultureAwareComparer; | ||
return | ||
comparer != null && | ||
_options == comparer._options && | ||
_compareInfo.Equals(comparer._compareInfo); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return _compareInfo.GetHashCode() ^ ((int)_options & 0x7FFFFFFF); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters