Open
Description
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
runtime/src/native/libs/System.Globalization.Native/pal_collation.m
Lines 185 to 186 in ec118c7
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 thematchLength
.