Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Missing SortKey changes + fix HashCode.
  • Loading branch information
ilonatommy committed Dec 29, 2023
commit 6e72858e44994d37bbfd0e22ef3447bf4ac1eb60
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ private int GetSortKeyCore(ReadOnlySpan<char> source, Span<byte> destination, Co
NlsGetSortKey(source, destination, options) :
#if TARGET_BROWSER
GlobalizationMode.Hybrid ?
throw new PlatformNotSupportedException(GetPNSEText("SortKey")) :
InvariantGetSortKey(source, destination, options)) :
#endif
IcuGetSortKey(source, destination, options);

Expand Down Expand Up @@ -1533,7 +1533,7 @@ private int GetSortKeyLengthCore(ReadOnlySpan<char> source, CompareOptions optio
NlsGetSortKeyLength(source, options) :
#if TARGET_BROWSER
GlobalizationMode.Hybrid ?
throw new PlatformNotSupportedException(GetPNSEText("SortKey")) :
InvariantGetSortKeyLength(source, options) :
#endif
IcuGetSortKeyLength(source, options);

Expand Down Expand Up @@ -1572,7 +1572,12 @@ public int GetHashCode(ReadOnlySpan<char> source, CompareOptions options)
// Pass the flags down to NLS or ICU unless we're running in invariant
// mode, at which point we normalize the flags to Ordinal[IgnoreCase].

#if TARGET_BROWSER
if (!GlobalizationMode.Invariant && !GlobalizationMode.Hybrid)
// JS cannot create locale-sensitive HashCode, use invaraint functions instead
#else
if (!GlobalizationMode.Invariant)
#endif
{
return GetHashCodeOfStringCore(source, options);
}
Expand Down Expand Up @@ -1608,10 +1613,6 @@ public int GetHashCode(ReadOnlySpan<char> source, CompareOptions options)
private unsafe int GetHashCodeOfStringCore(ReadOnlySpan<char> source, CompareOptions options) =>
GlobalizationMode.UseNls ?
NlsGetHashCodeOfString(source, options) :
#if TARGET_BROWSER
GlobalizationMode.Hybrid ?
throw new PlatformNotSupportedException(GetPNSEText("HashCode")) :
#endif
IcuGetHashCodeOfString(source, options);

public override string ToString() => "CompareInfo - " + Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,42 +355,6 @@ public void SortKeyKanaTest(CompareInfo compareInfo, string string1, string stri
SortKeyTest(compareInfo, string1, string2, options, expected);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))]
public void SortKeyTestNotSupported()
{
try
{
s_invariantCompare.GetSortKey("");
AssertNotReached();
}
catch(PlatformNotSupportedException pnse)
{
Assert.Equal(GetPNSEText("SortKey"), pnse.Message);
}
try
{
s_invariantCompare.GetSortKeyLength(ReadOnlySpan<char>.Empty);
AssertNotReached();
}
catch(PlatformNotSupportedException pnse)
{
Assert.Equal(GetPNSEText("SortKey"), pnse.Message);
}

try
{
s_invariantCompare.GetHashCode("", CompareOptions.None);
AssertNotReached();
}
catch(PlatformNotSupportedException pnse)
{
Assert.Equal(GetPNSEText("HashCode"), pnse.Message);
}

string GetPNSEText(string funcName) => $"{funcName} is not supported when HybridGlobalization=true. Disable it to load larger ICU bundle, then use this option.";
void AssertNotReached() => Assert.Fail();
}

[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int CompareStringEx(string lpLocaleName, uint dwCmpFlags, string lpString1, int cchCount1, string lpString2, int cchCount2, IntPtr lpVersionInformation, IntPtr lpReserved, int lParam);
private const int NORM_LINGUISTIC_CASING = 0x08000000; // use linguistic rules for casing
Expand Down