-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS][non-icu] HybridGlobalization implement normalization functions (#…
…90582) [iOS] HybridGlobalization implement normalization functions
- Loading branch information
Showing
13 changed files
with
192 additions
and
36 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/libraries/Common/src/Interop/Interop.Normalization.iOS.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,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Globalization | ||
{ | ||
[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_IsNormalizedNative", StringMarshalling = StringMarshalling.Utf16)] | ||
internal static unsafe partial int IsNormalizedNative(NormalizationForm normalizationForm, char* src, int srcLen); | ||
|
||
[LibraryImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_NormalizeStringNative", StringMarshalling = StringMarshalling.Utf16)] | ||
internal static unsafe partial int NormalizeStringNative(NormalizationForm normalizationForm, char* src, int srcLen, char* buffer, int bufferLength); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...em.Globalization.Extensions/tests/Hybrid/System.Globalization.Extensions.iOS.Tests.csproj
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-maccatalyst</TargetFrameworks> | ||
<TestRuntime>true</TestRuntime> | ||
<HybridGlobalization>true</HybridGlobalization> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="..\Normalization\StringNormalizationTests.cs" /> | ||
<Compile Include="..\Normalization\NormalizationAll.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="..\Normalization\Data\win8.txt"> | ||
<LogicalName>NormalizationDataWin8</LogicalName> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="..\Normalization\Data\win7.txt"> | ||
<LogicalName>NormalizationDataWin7</LogicalName> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
</Project> |
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
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
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
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
87 changes: 87 additions & 0 deletions
87
src/native/libs/System.Globalization.Native/pal_normalization.m
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,87 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// | ||
|
||
#include "pal_errors.h" | ||
#include "pal_icushim_internal.h" | ||
#include "pal_normalization.h" | ||
#import <Foundation/Foundation.h> | ||
|
||
#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS) | ||
static NSString* GetNormalizedStringForForm(NormalizationForm normalizationForm, NSString* sourceString) | ||
{ | ||
switch (normalizationForm) | ||
{ | ||
case FormC: | ||
return sourceString.precomposedStringWithCanonicalMapping; | ||
case FormD: | ||
return sourceString.decomposedStringWithCanonicalMapping; | ||
case FormKC: | ||
return sourceString.precomposedStringWithCompatibilityMapping; | ||
case FormKD: | ||
return sourceString.decomposedStringWithCompatibilityMapping; | ||
default: | ||
return NULL; | ||
} | ||
} | ||
|
||
/* | ||
Function: | ||
IsNormalized | ||
Used by System.StringNormalizationExtensions.IsNormalized to detect if a string | ||
is in a certain Unicode Normalization Form. | ||
Return values: | ||
0: lpStr is not normalized. | ||
1: lpStr is normalized. | ||
-1: internal error during normalization. | ||
*/ | ||
int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationForm, const uint16_t* lpStr, int32_t cwStrLength) | ||
{ | ||
@autoreleasepool | ||
{ | ||
NSString *sourceString = [NSString stringWithCharacters: lpStr length: cwStrLength]; | ||
NSString *normalizedString = GetNormalizedStringForForm(normalizationForm, sourceString); | ||
|
||
return normalizedString == NULL ? -1 : [sourceString isEqualToString: normalizedString]; | ||
} | ||
} | ||
|
||
/* | ||
Function: | ||
NormalizeString | ||
Used by System.StringNormalizationExtensions.Normalize to normalize a string | ||
into a certain Unicode Normalization Form. | ||
Return values: | ||
0: internal error during normalization. | ||
>0: the length of the normalized string (not counting the null terminator). | ||
*/ | ||
int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizationForm, const uint16_t* lpSource, int32_t cwSourceLength, uint16_t* lpDst, int32_t cwDstLength) | ||
{ | ||
@autoreleasepool | ||
{ | ||
NSString *sourceString = [NSString stringWithCharacters: lpSource length: cwSourceLength]; | ||
NSString *normalizedString = GetNormalizedStringForForm(normalizationForm, sourceString); | ||
|
||
if (normalizedString == NULL || normalizedString.length == 0) | ||
{ | ||
return 0; | ||
} | ||
|
||
int32_t index = 0, dstIdx = 0, isError = 0; | ||
uint16_t dstCodepoint; | ||
while (index < normalizedString.length) | ||
{ | ||
dstCodepoint = [normalizedString characterAtIndex: index]; | ||
Append(lpDst, dstIdx, cwDstLength, dstCodepoint, isError); | ||
index++; | ||
} | ||
|
||
return !isError ? [normalizedString length] : 0; | ||
} | ||
} | ||
#endif | ||
|