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

PS-1174 - Allowing to search items with diacritics #2269

Closed

Conversation

aj-rosado
Copy link
Contributor

@aj-rosado aj-rosado commented Dec 28, 2022

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Items with diacritics should be returned on searches that match their name or subtitles without diacritics

Code changes

Added a method to remove diacritics from a string and validated if the cipher item name and subtitle matches the search

  • SearchService.cs: Added RemoveDiacritics method to normalize the strings without diacritics. Added new checks to the SearchCiphersBasic to validate if the item normalized name matches the search

Screenshots

Android
Android search on name with diacritics Android search on subtitle with diacritics

iOS
Android search on subtitle with diacritics iOS search on name with diacritics

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

Comment on lines +179 to +199
private string RemoveDiacritics(string text)
{
if (string.IsNullOrWhiteSpace(text))
{
return null;
}

string formD = text.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();

foreach (char ch in formD)
{
UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(ch);
if (uc != UnicodeCategory.NonSpacingMark)
{
sb.Append(ch);
}
}

return sb.ToString().Normalize(NormalizationForm.FormC);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be an extension method of String. It's easier to find it afterwards and to reuse if needed in other places.

@aj-rosado
Copy link
Contributor Author

aj-rosado commented Jan 5, 2023

Duplicates [PS-1352 Fix ignore diacritics in search](#2044)

@aj-rosado aj-rosado closed this Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants