aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/TextEncoding/NLangDetect/Utils/Messages.cs
diff options
context:
space:
mode:
authorcvium <clausvium@gmail.com>2019-01-16 20:50:40 +0100
committerClaus Vium <clausvium@gmail.com>2019-01-20 06:30:50 +0100
commitb35dcbb9f02c27d2d84ee3281a60d654a3fb1259 (patch)
tree12049e17ac9e6cdbe2e7fec5ec7a886cff8a8c6d /Emby.Server.Implementations/TextEncoding/NLangDetect/Utils/Messages.cs
parent3a5e3ade01ab4b4fccca03ba2da969f03d5564f1 (diff)
Remove MediaBrowser.Text since it violates licenses and is overall hacky
Diffstat (limited to 'Emby.Server.Implementations/TextEncoding/NLangDetect/Utils/Messages.cs')
-rw-r--r--Emby.Server.Implementations/TextEncoding/NLangDetect/Utils/Messages.cs88
1 files changed, 0 insertions, 88 deletions
diff --git a/Emby.Server.Implementations/TextEncoding/NLangDetect/Utils/Messages.cs b/Emby.Server.Implementations/TextEncoding/NLangDetect/Utils/Messages.cs
deleted file mode 100644
index 879c0a09b..000000000
--- a/Emby.Server.Implementations/TextEncoding/NLangDetect/Utils/Messages.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text.RegularExpressions;
-
-namespace NLangDetect.Core.Utils
-{
- public static class Messages
- {
- private static readonly Dictionary<string, string> _messages;
-
- static Messages()
- {
- _messages = LoadMessages();
- }
-
- public static string getString(string key)
- {
- return
- _messages.TryGetValue(key, out var value)
- ? value
- : string.Format("!{0}!", key);
- }
-
- private static Dictionary<string, string> LoadMessages()
- {
- var manifestName = typeof(Messages).Assembly.GetManifestResourceNames().FirstOrDefault(i => i.IndexOf("messages.properties", StringComparison.Ordinal) != -1);
-
- var messagesStream =
- typeof(Messages).Assembly
- .GetManifestResourceStream(manifestName);
-
- if (messagesStream == null)
- {
- throw new InternalException(string.Format("Couldn't get embedded resource named '{0}'.", manifestName));
- }
-
- using (messagesStream)
- using (var sr = new StreamReader(messagesStream))
- {
- var messages = new Dictionary<string, string>();
-
- while (!sr.EndOfStream)
- {
- string line = sr.ReadLine();
-
- if (string.IsNullOrEmpty(line))
- {
- continue;
- }
-
- string[] keyValue = line.Split('=');
-
- if (keyValue.Length != 2)
- {
- throw new InternalException(string.Format("Invalid format of the 'Messages.properties' resource. Offending line: '{0}'.", line.Trim()));
- }
-
- string key = keyValue[0];
- string value = UnescapeUnicodeString(keyValue[1]);
-
- messages.Add(key, value);
- }
-
- return messages;
- }
- }
-
- /// <remarks>
- /// Taken from: http://stackoverflow.com/questions/1615559/converting-unicode-strings-to-escaped-ascii-string/1615860#1615860
- /// </remarks>
- private static string UnescapeUnicodeString(string s)
- {
- if (s == null)
- {
- return null;
- }
-
- return
- Regex.Replace(
- s,
- @"\\u(?<Value>[a-zA-Z0-9]{4})",
- match => ((char)int.Parse(match.Groups["Value"].Value, NumberStyles.HexNumber)).ToString());
- }
- }
-}