Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetNormalizedLength on iOS and similar platforms #110723

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public static IEnumerable<object[]> NormalizeTestData()
}

[Theory]
[ActiveIssue("https://github.com/dotnet/runtime/issues/110720", TestPlatforms.tvOS | TestPlatforms.iOS | TestPlatforms.MacCatalyst)]
[MemberData(nameof(NormalizeTestData))]
public void Normalize(string value, NormalizationForm normalizationForm, string expected)
{
Expand Down
13 changes: 10 additions & 3 deletions src/native/libs/System.Globalization.Native/pal_normalization.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,23 @@ int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizatio
return 0;
}

int32_t index = 0, dstIdx = 0, isError = 0;
// Calling with empty or null destination buffer to get the required buffer size.
if (lpDst == NULL || cwDstLength == 0)
{
return (int32_t)[normalizedString length];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part is no longer necessary, but I prefer to keep it so that it is clear what happens when destination buffer is 0.


ResultCode isError = Success;
int32_t index = 0, dstIdx = 0;
uint16_t dstCodepoint;
while ((NSUInteger)index < normalizedString.length)
while ((NSUInteger)index < normalizedString.length && isError == Success)
{
dstCodepoint = [normalizedString characterAtIndex: (NSUInteger)index];
Append(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
index++;
}

return !isError ? (int32_t)[normalizedString length] : 0;
return (isError == Success || isError == InsufficientBuffer) ? (int32_t)[normalizedString length] : 0;
}
}
#endif
Expand Down
Loading