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

Add overloads to RemoveDiacritics and IsDiacritics extension methods to pass a IDiacriticsMapper #34

Open
toburger opened this issue Apr 17, 2021 · 0 comments

Comments

@toburger
Copy link

If you want to use the extension methods of the library you have to register a global default diacritics mapper.
This is not very pure and it does not allow to have different mappings for different strings without switching the global mapper.

StaticDiacritics.SetDefaultMapper(() =>
    new DiacriticsMapper(
        new MyGermanAccentMapping(),
        new GermanAccentsMapping(),
        new ItalianAccentsMapping(),
        new ArabicAccentsMapping()
    )
);

"Thöni".RemoveDiacritics() // "Thoeni"

The current "pure" approach is to instantiate a DiacriticsMapper with accent mappings and use the methods form this instance.

var myMapper = new DiacriticsMapper(
    new MyGermanAccentMapping(),
    new GermanAccentsMapping(),
    new ItalianAccentsMapping(),
    new ArabicAccentsMapping());

myMapper.RemoveDiacritics() // "Thoeni"

This is fine.
But it would be convenient to have an overload for the extensions methods where the mapper (or single accent mappings) could be passed:

"Thöni".RemoveDiacritics(myMapper) // "Thoeni"

or simply as a params array:

"Thöni".RemoveDiacritics(new MyGermanAccentMapping()) // "Thoeni"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant