mirror of
https://github.com/bitwarden/mobile.git
synced 2024-06-25 10:26:02 +02:00
* PM-6655 Added fallback "Unknown account" to passkey username and moved it so it can be shared with Android * PM-6655 Improved code lines formatting
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
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);
|
|
}
|
|
|
|
public static string FallbackOnNullOrWhiteSpace(this string s, string fallback) => string.IsNullOrWhiteSpace(s) ? fallback : s;
|
|
}
|
|
}
|