123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using System;
- using System.Collections.Generic;
- namespace I2.Loc
- {
- public class SpecializationManager : BaseSpecializationManager
- {
- private SpecializationManager()
- {
- this.InitializeSpecializations();
- }
- public static string GetSpecializedText(string text, string specialization = null)
- {
- int num = text.IndexOf("[i2s_");
- if (num < 0)
- {
- return text;
- }
- if (string.IsNullOrEmpty(specialization))
- {
- specialization = SpecializationManager.Singleton.GetCurrentSpecialization();
- }
- while (!string.IsNullOrEmpty(specialization) && specialization != "Any")
- {
- string text2 = "[i2s_" + specialization + "]";
- int num2 = text.IndexOf(text2);
- if (num2 >= 0)
- {
- num2 += text2.Length;
- int num3 = text.IndexOf("[i2s_", num2);
- if (num3 < 0)
- {
- num3 = text.Length;
- }
- return text.Substring(num2, num3 - num2);
- }
- specialization = SpecializationManager.Singleton.GetFallbackSpecialization(specialization);
- }
- return text.Substring(0, num);
- }
- public static string SetSpecializedText(string text, string newText, string specialization)
- {
- if (string.IsNullOrEmpty(specialization))
- {
- specialization = "Any";
- }
- if ((text == null || !text.Contains("[i2s_")) && specialization == "Any")
- {
- return newText;
- }
- Dictionary<string, string> specializations = SpecializationManager.GetSpecializations(text, null);
- specializations[specialization] = newText;
- return SpecializationManager.SetSpecializedText(specializations);
- }
- public static string SetSpecializedText(Dictionary<string, string> specializations)
- {
- string text;
- if (!specializations.TryGetValue("Any", out text))
- {
- text = string.Empty;
- }
- foreach (KeyValuePair<string, string> keyValuePair in specializations)
- {
- if (keyValuePair.Key != "Any" && !string.IsNullOrEmpty(keyValuePair.Value))
- {
- string text2 = text;
- text = string.Concat(new string[]
- {
- text2,
- "[i2s_",
- keyValuePair.Key,
- "]",
- keyValuePair.Value
- });
- }
- }
- return text;
- }
- public static Dictionary<string, string> GetSpecializations(string text, Dictionary<string, string> buffer = null)
- {
- if (buffer == null)
- {
- buffer = new Dictionary<string, string>();
- }
- else
- {
- buffer.Clear();
- }
- if (text == null)
- {
- buffer["Any"] = string.Empty;
- return buffer;
- }
- int num = text.IndexOf("[i2s_");
- if (num < 0)
- {
- num = text.Length;
- }
- buffer["Any"] = text.Substring(0, num);
- for (int i = num; i < text.Length; i = num)
- {
- i += "[i2s_".Length;
- int num2 = text.IndexOf(']', i);
- if (num2 < 0)
- {
- break;
- }
- string key = text.Substring(i, num2 - i);
- i = num2 + 1;
- num = text.IndexOf("[i2s_", i);
- if (num < 0)
- {
- num = text.Length;
- }
- string value = text.Substring(i, num - i);
- buffer[key] = value;
- }
- return buffer;
- }
- public static void AppendSpecializations(string text, List<string> list = null)
- {
- if (text == null)
- {
- return;
- }
- if (list == null)
- {
- list = new List<string>();
- }
- if (!list.Contains("Any"))
- {
- list.Add("Any");
- }
- int i = 0;
- while (i < text.Length)
- {
- i = text.IndexOf("[i2s_", i);
- if (i < 0)
- {
- break;
- }
- i += "[i2s_".Length;
- int num = text.IndexOf(']', i);
- if (num < 0)
- {
- break;
- }
- string item = text.Substring(i, num - i);
- if (!list.Contains(item))
- {
- list.Add(item);
- }
- }
- }
- public static SpecializationManager Singleton = new SpecializationManager();
- }
- }
|