mirror of
https://github.com/bitwarden/mobile
synced 2026-01-12 05:23:58 +00:00
* Fix ignore diacritics in search This change updates the search function to ignore diacritical marks in search results. Marks are stripped from both the search input and results. * Removed logs, added null or whitespace validation and improved formatting Co-authored-by: aj-rosado <109146700+aj-rosado@users.noreply.github.com> Co-authored-by: Andre Rosado <arosado@bitwarden.com>
35 lines
985 B
C#
35 lines
985 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
|
|
namespace Bit.Core.Utilities
|
|
{
|
|
public static class StringExtensions
|
|
{
|
|
public static string RemoveDiacritics(this string text)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
{
|
|
return text;
|
|
}
|
|
|
|
var normalizedString = text.Normalize(NormalizationForm.FormD);
|
|
var stringBuilder = new StringBuilder(capacity: normalizedString.Length);
|
|
|
|
for (int i = 0; i < normalizedString.Length; i++)
|
|
{
|
|
char c = normalizedString[i];
|
|
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
|
|
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
|
|
{
|
|
stringBuilder.Append(c);
|
|
}
|
|
}
|
|
|
|
return stringBuilder
|
|
.ToString()
|
|
.Normalize(NormalizationForm.FormC);
|
|
}
|
|
}
|
|
}
|