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

[iOS][globalization] Investigate matchLength differences between Apple mobile and other ICU platform returned by (Last)IndexOf, IsSuffix, IsPrefix APIs #112418

Open
matouskozak opened this issue Feb 11, 2025 · 2 comments

Comments

@matouskozak
Copy link
Member

matouskozak commented Feb 11, 2025

matchLength definition:

When this method returns, contains the number of characters of source that matched the desired value. This may be different than the length of value if a linguistic comparison is performed. Set to 0 if value is not found within source.

Due to the applied normalization

NSString *searchStrPrecomposed = searchStrCleaned.precomposedStringWithCanonicalMapping;
NSString *sourceStrPrecomposed = sourceStrCleaned.precomposedStringWithCanonicalMapping;
the matchLength returned by the (Last)IndexOf, IsSuffix, IsPrefix APIs might not be what users expect.

The precomposedStringWithCanonicalMapping converts the string to its NFC form, potentially causing the returned length to be shorter than expected (if a combination of two code points got normalized into a single code point).


Possible solutions:

  • Revisit the implementation of IndexOf and remove the normalization while ensuring correct behavior.
  • Introduce a post-search step, where we would traverse the original source string based on the found index and calculate the matchLength.
Copy link
Contributor

Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant