diff options
| author | Joshua M. Boniface <joshua@boniface.me> | 2019-02-03 22:08:20 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-03 22:08:20 -0500 |
| commit | 56dcc45dc04de6be775551f14d1ad0bb235d72f9 (patch) | |
| tree | 427766dd086822efd96ba31460960145f3c1e409 /Emby.Server.Implementations/Localization/TextLocalizer.cs | |
| parent | 3ac75313854c6109b71d542e492594e434cb39ba (diff) | |
| parent | cabb824f2a095115ebbe79ca7fdfbcbab4db1e5f (diff) | |
Merge pull request #732 from Bond-009/locale
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); - } - } -} |
