diff options
| author | Bond_009 <bond.009@outlook.com> | 2019-01-27 10:20:05 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2019-01-27 10:36:05 +0100 |
| commit | 51edd5d067c919800f504bfa9fe1708279faaa3f (patch) | |
| tree | fe8be0fae8e493710fec0354a0fcc730a2ae7e0b /Emby.Server.Implementations/Localization/TextLocalizer.cs | |
| parent | e3b19c22a7506d6e03d6519b50797c1f49c70034 (diff) | |
Reworked LocalizationManager to load data async
Diffstat (limited to 'Emby.Server.Implementations/Localization/TextLocalizer.cs')
| -rw-r--r-- | Emby.Server.Implementations/Localization/TextLocalizer.cs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/Emby.Server.Implementations/Localization/TextLocalizer.cs b/Emby.Server.Implementations/Localization/TextLocalizer.cs deleted file mode 100644 index 96591e5e6..000000000 --- a/Emby.Server.Implementations/Localization/TextLocalizer.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace Emby.Server.Implementations.Localization -{ - public class TextLocalizer : ITextLocalizer - { - public string RemoveDiacritics(string text) - { - if (text == null) - { - throw new ArgumentNullException(nameof(text)); - } - - var chars = Normalize(text, NormalizationForm.FormD) - .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != UnicodeCategory.NonSpacingMark); - - return Normalize(string.Concat(chars), NormalizationForm.FormC); - } - - private static string Normalize(string text, NormalizationForm form, bool stripStringOnFailure = true) - { - if (stripStringOnFailure) - { - try - { - return text.Normalize(form); - } - catch (ArgumentException) - { - // will throw if input contains invalid unicode chars - // https://mnaoumov.wordpress.com/2014/06/14/stripping-invalid-characters-from-utf-16-strings/ - text = StripInvalidUnicodeCharacters(text); - return Normalize(text, form, false); - } - } - - try - { - return text.Normalize(form); - } - catch (ArgumentException) - { - // if it still fails, return the original text - return text; - } - } - - private static string StripInvalidUnicodeCharacters(string str) - { - var invalidCharactersRegex = new Regex("([\ud800-\udbff](?![\udc00-\udfff]))|((?<![\ud800-\udbff])[\udc00-\udfff])"); - return invalidCharactersRegex.Replace(str, ""); - } - - public string NormalizeFormKD(string text) - { - return text.Normalize(NormalizationForm.FormKD); - } - } -} |
