aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Core/Localization/TextLocalizer.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-08-09 15:56:38 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-08-09 15:56:38 -0400
commit40442f887ba717ae47620b152315f21b252fe049 (patch)
tree340be082fd2296f19aed17b24b22b5095e3815a7 /Emby.Server.Core/Localization/TextLocalizer.cs
parent52aeb3c40b3e2f0fdc377ac7c793714add2be0ef (diff)
consolidate emby.server.core into emby.server.implementations
Diffstat (limited to 'Emby.Server.Core/Localization/TextLocalizer.cs')
-rw-r--r--Emby.Server.Core/Localization/TextLocalizer.cs64
1 files changed, 0 insertions, 64 deletions
diff --git a/Emby.Server.Core/Localization/TextLocalizer.cs b/Emby.Server.Core/Localization/TextLocalizer.cs
deleted file mode 100644
index 1e8ccbbfa..000000000
--- a/Emby.Server.Core/Localization/TextLocalizer.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using System;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
-using Emby.Server.Implementations.Localization;
-
-namespace Emby.Server.Core.Localization
-{
- public class TextLocalizer : ITextLocalizer
- {
- public string RemoveDiacritics(string text)
- {
- if (text == null)
- {
- throw new ArgumentNullException("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);
- }
- }
-}