Skip to content

[iOS][globalization] Implement IgnoreSymbols compare option for string collation APIs on iOS #111895

Open
@matouskozak

Description

@matouskozak

Based on the current documentation

As there is no IgnoreSymbols equivalent in NSStringCompareOptions all CompareOptions combinations that include IgnoreSymbols throw PlatformNotSupportedException.

private static void AssertComparisonSupported(CompareOptions options)
{
if ((options | SupportedCompareOptions) != SupportedCompareOptions)
throw new PlatformNotSupportedException(GetPNSE(options));
}
private const CompareOptions SupportedCompareOptions = CompareOptions.None | CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace |
CompareOptions.IgnoreWidth | CompareOptions.StringSort | CompareOptions.IgnoreKanaType;
private static string GetPNSE(CompareOptions options) =>
SR.Format(SR.PlatformNotSupported_HybridGlobalizationWithCompareOptions, options);
}

We should remove the exception throw for IndexOf and other APIs using IgnoreSymbols compare option and implement a workaround to enable this API. Due to no NSStringCompareOptions that would mimic the same behavior as .NET IgnoreSymbols we will likely need to:

  1. Preprocess the strings by removing the symbols (comma, period, colon, etc.).
  2. Calculate the range on the preprocessed strings.
  3. Map the range from preprocessed strings back to the input string to get correct index and matchLength.

Add more test cases:

if (PlatformDetection.IsNotHybridGlobalizationOnApplePlatform) // IgnoreSymbols are not supported
yield return new object[] { s_invariantCompare, "More Test's", "Tests", 0, 11, CompareOptions.IgnoreSymbols, 5, 6 };

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions