Skip to content

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

Open
@matouskozak

Description

@matouskozak

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions