public void Start() { Console.WriteLine("============Search Demo============"); // initialize datas uint[] ids = createIDs(10); string idstr = ids[0].ToString(); for (int i = 1; i < ids.Length; i++) { idstr += " " + ids[i].ToString(); } // add KeyedList <uint, DemoItem> list = new KeyedList <uint, DemoItem>(); for (int i = 0; i < ids.Length; i++) { var item = new DemoItem(ids[i], $"Item_{ids[i]}"); list.Add(item); } // search demo string itemStr = list.FindByKey(ids[0]).Data.ToString(); for (int i = 1; i < ids.Length; i++) { itemStr += ", " + list.FindByKey(ids[i]).Data.ToString(); } Console.WriteLine($"Search by ({idstr}) :"); Console.WriteLine(itemStr); }
public SparseConditionalConstantPropagation(BasicBlocks basicBlocks, ITraceFactory traceFactory) { this.TraceFactory = traceFactory; this.BasicBlocks = basicBlocks; MainTrace = CreateTrace("SparseConditionalConstantPropagation"); // Method is empty - must be a plugged method if (BasicBlocks.HeadBlocks.Count == 0) return; blockStates = new bool[BasicBlocks.Count]; for (int i = 0; i < BasicBlocks.Count; i++) { blockStates[i] = false; } // Initialize foreach (var block in BasicBlocks.HeadBlocks) { AddExecutionBlock(block); } while (blockWorklist.Count > 0 || instructionWorkList.Count > 0) { ProcessBlocks(); ProcessInstructions(); } DumpTrace(); // Release phiStatements = null; }
public void Start() { Console.WriteLine("==========Add/Remove Demo=========="); // initialize datas uint[] ids = createIDs(10); string idstr = ids[0].ToString(); for (int i = 1; i < ids.Length; i++) { idstr += " " + ids[i].ToString(); } Console.WriteLine("Before add : "); Console.WriteLine(idstr); // add demo KeyedList <uint, DemoItem> list = new KeyedList <uint, DemoItem>(); for (int i = 0; i < ids.Length; i++) { var item = new DemoItem(ids[i], $"Item_{ids[i]}"); list.Add(item); } Console.WriteLine("After add : "); print(list); // remove demo for (int i = 0; i < ids.Length / 2; i++) { list.RemoveByKey(ids[i]); } Console.WriteLine("After remove : "); print(list); }
public LanguagePair(string sourceLanguageTag, string targetLanguageTag, string configDir) { SourceLanguageTag = sourceLanguageTag; TargetLanguageTag = targetLanguageTag; ConfigDirectory = configDir; Projects = new KeyedList <string, Project>(p => p.Id); }
public KeyedList Combine(KeyedList other) { var otherKeys = new HashSet <string>(other.keyedValues.Where(k => k.HasKey()).Select(k => k.Key).Distinct()); var uniqueKeyedVariables = keyedValues.Where(k => !k.HasKey() || !otherKeys.Contains(k.Key)).ToList(); return(new KeyedList(uniqueKeyedVariables.Concat(other.GetValues()).ToArray())); }
public void Start() { Console.WriteLine("============Except Demo============"); // initialize datas uint[] ids = createIDs(10); string idstr = ids[0].ToString(); for (int i = 1; i < ids.Length; i++) { idstr += " " + ids[i].ToString(); } // add KeyedList <uint, DemoItem> list = new KeyedList <uint, DemoItem>(); KeyedList <uint, DemoItem> subList = new KeyedList <uint, DemoItem>(); for (int i = 0; i < ids.Length; i++) { var item = new DemoItem(ids[i], $"Item_{ids[i]}"); list.Add(item); if (i < ids.Length / 2) { subList.Add(item); } } Console.WriteLine("Before Except:"); print(list); Console.WriteLine("Sub List:"); print(subList); Console.WriteLine("After Except"); list = KeyedList <uint, DemoItem> .Except(list, subList); print(list); }
public PlayerManager() { serialPID = 0; waitingQueue = new List <Player>(); playingList = new KeyedList <int, Player>(); leavingList = new List <Player>(); }
static Country() { foreach (Country c in Countries) { if (GeographicRegion.IsSupported(c.Code)) { c.DisplayName = new GeographicRegion(c.Code).DisplayName; } else { c.DisplayName = c.Name; } } var alphabet = "abcdefghijklmnopqrstuvwxyz"; var list = new List <KeyedList <string, Country> >(alphabet.Length); var dictionary = new Dictionary <string, KeyedList <string, Country> >(); for (int i = 0; i < alphabet.Length; i++) { var key = alphabet[i].ToString(); var group = new KeyedList <string, Country>(key); list.Add(group); dictionary[key] = group; } foreach (var country in Countries) { dictionary[country.GetKey()].Add(country); } GroupedCountries = list; }
public KeyedList Remove(KeyedList other) { KeyedList copy = new KeyedList(keyedValues.Select(v => new KeyedVariable(v.Key, v.Value)).ToArray()); other.keyedValues.ForEach(v => copy.SetValue(v.GetValue(), null)); return(new KeyedList(copy.keyedValues.Where(k => k.Value != null).ToArray())); }
public void Setup() { _items = 0; _keyedList = new KeyedList <int, int>(i => i * i); _keyedList.Added += KeyedList_Added; _keyedList.Removed += KeyedList_Removed; _keyedList.Cleared += KeyedList_Cleared; _keyedList.AddRange(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); }
public SearchUsersCollection(IProtoService protoService, string query) { _protoService = protoService; _query = query; _local = new KeyedList <string, object>(null as string); _remote = new KeyedList <string, object>(Strings.Resources.GlobalSearch); Add(_local); Add(_remote); }
public void Can_Do_Simple_Adds_Like_A_Regular_List() { var list = new KeyedList <Subject>(); list.Add(new Subject("a")); list.Add(new Subject("b")); list.Add(new Subject("c")); list.Add(new Subject("d")); Assert.That(list.Count, Is.EqualTo(4)); }
public void Can_Do_Simple_Adds_Like_A_Regular_List() { var list = new KeyedList<Subject>(); list.Add(new Subject("a")); list.Add(new Subject("b")); list.Add(new Subject("c")); list.Add(new Subject("d")); Assert.That(list.Count, Is.EqualTo(4)); }
private void print(KeyedList <uint, DemoItem> list) { if (list.Count > 0) { string str = list[0].Key.ToString(); for (int i = 1; i < list.Count; i++) { str += " " + list[i].Key; } Console.WriteLine(str); } }
public void AddRange_Is_Treated_As_Many_Adds() { var list = new KeyedList <Subject>(); var a = new Subject("a"); var b = new Subject("b"); var c = new Subject("c"); var d = new Subject("d"); list.AddRange(a, b, c, d); Assert.That(list.Count, Is.EqualTo(4)); Assert.That(list["b"], Is.EqualTo(b)); }
public void AddRange_Is_Treated_As_Many_Adds() { var list = new KeyedList<Subject>(); var a = new Subject("a"); var b = new Subject("b"); var c = new Subject("c"); var d = new Subject("d"); list.AddRange(a, b, c, d); Assert.That(list.Count, Is.EqualTo(4)); Assert.That(list["b"], Is.EqualTo(b)); }
public void Indexers_Are_Treated_As_Add() { var list = new KeyedList<Subject>(); list["a"] = new Subject("a"); list["b"] = new Subject("b"); list["b"] = new Subject("b"); var b = new Subject("b"); list["b"] = b; list["c"] = new Subject("c"); list["d"] = new Subject("d"); Assert.That(list.Count, Is.EqualTo(4)); Assert.That(list["b"], Is.EqualTo(b)); }
/// <summary> /// Creates <see cref="PlayerValuable.GeneratePlayerValuableEvent"/>s that increment simple counters. /// </summary> /// <param name="playerValuables"></param> /// <returns>A dictionary linking <see cref="ValuableType"/>s to the number of times their respective <see cref="PlayerValuable.GeneratePlayerValuableEvent"/>s were triggered (<see cref="ValuableGenerationCounter.Events"/>) and the number of <see cref="PlayerValuable"/>s that were generated by those events (<see cref="ValuableGenerationCounter.Amount"/>)</returns> private static Dictionary <ValuableType, ValuableGenerationCounter> CreateValuableGenerationCounters( KeyedList <ValuableType, PlayerValuable> playerValuables) { var generateCounters = playerValuables.ToDictionary( playerValuable => playerValuable.ValuableType, playerValuable => new ValuableGenerationCounter() ); PlayerValuable.GeneratePlayerValuableEvent += (valuable, amount) => { generateCounters[valuable.ValuableType].Events += 1; generateCounters[valuable.ValuableType].Amount += amount; }; return(generateCounters); }
public void Duplicates_Are_Treated_As_Last_One_Wins() { var list = new KeyedList<Subject>(); list.Add(new Subject("a")); list.Add(new Subject("b")); list.Add(new Subject("b")); var b = new Subject("b"); list.Add(b); list.Add(new Subject("c")); list.Add(new Subject("d")); Assert.That(list.Count, Is.EqualTo(4)); Assert.That(list["b"], Is.EqualTo(b)); }
public SparseConditionalConstantPropagation(BasicBlocks basicBlocks, ITraceFactory traceFactory) { // Method is empty - must be a plugged method if (basicBlocks.HeadBlocks.Count == 0) { return; } TraceFactory = traceFactory; BasicBlocks = basicBlocks; variableStates = new Dictionary <Operand, VariableState>(); instructionWorkList = new Stack <InstructionNode>(); blockWorklist = new Stack <BasicBlock>(); phiStatements = new KeyedList <BasicBlock, InstructionNode>(); executedStatements = new HashSet <InstructionNode>(); MainTrace = CreateTrace("SparseConditionalConstantPropagation", 5); blockStates = new bool[BasicBlocks.Count]; for (int i = 0; i < BasicBlocks.Count; i++) { blockStates[i] = false; } // Initialize foreach (var block in BasicBlocks.HeadBlocks) { AddExecutionBlock(block); } foreach (var block in BasicBlocks.HandlerHeadBlocks) { AddExecutionBlock(block); } while (blockWorklist.Count > 0 || instructionWorkList.Count > 0) { ProcessBlocks(); ProcessInstructions(); } DumpTrace(); // Release phiStatements = null; }
public void Indexers_Are_Treated_As_Add() { var list = new KeyedList <Subject>(); list["a"] = new Subject("a"); list["b"] = new Subject("b"); list["b"] = new Subject("b"); var b = new Subject("b"); list["b"] = b; list["c"] = new Subject("c"); list["d"] = new Subject("d"); Assert.That(list.Count, Is.EqualTo(4)); Assert.That(list["b"], Is.EqualTo(b)); }
public void Duplicates_Are_Treated_As_Last_One_Wins() { var list = new KeyedList <Subject>(); list.Add(new Subject("a")); list.Add(new Subject("b")); list.Add(new Subject("b")); var b = new Subject("b"); list.Add(b); list.Add(new Subject("c")); list.Add(new Subject("d")); Assert.That(list.Count, Is.EqualTo(4)); Assert.That(list["b"], Is.EqualTo(b)); }
private static bool IsSortedTest(KeyedList <string, int> kList, bool Ascending) { for (int i = 1; i < kList.Count; ++i) { int dif = String.Compare(kList[i - 1].Key, kList[i].Key, StringComparison.Ordinal); if (!Ascending) { dif = -dif; } if (dif > 0) { return(false); } } return(true); }
public GameSourceManager(PhysicEngineProxy physicEngine, IDebugger debugger) { serialSID = 0; GSList = new KeyedList <uint, GameSource>(); added = new List <GameSource>(); removed = new List <GameSource>(); temp_adding = new List <GameSource>(); temp_remove = new List <GameSource>(); temp_stateRefresh = new List <GameSource>(); PhysicEngine = physicEngine; Debugger = debugger; }
private static IKeyedCollection <string, SldrLanguageTagInfo> DeriveTagsFromJsonEntries(List <AllTagEntry> rootObject) { var tags = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase); foreach (AllTagEntry entry in rootObject) { // tags starting with x- have undefined structure so ignoring them // tags starting with _ showed up in buggy data so we'll drop them also if (!entry.tag.StartsWith("x-") && !entry.tag.StartsWith("_")) { LanguageSubtag languageTag; if (!entry.deprecated && !StandardSubtags.RegisteredLanguages.TryGet(entry.tag.Split('-')[0], out languageTag)) { if (entry.iso639_3 == null) { StandardSubtags.AddLanguage(entry.tag.Split('-')[0], entry.name, false, entry.tag.Split('-')[0]); } else if (!StandardSubtags.RegisteredLanguages.TryGet(entry.iso639_3, out languageTag)) { StandardSubtags.AddLanguage(entry.iso639_3, entry.name, false, entry.iso639_3); } } string implicitStringCode = null; // the script is always in the full tag string scriptCode = entry.full.Split('-')[1]; if (scriptCode.Length == 4) { var tagComponents = entry.tag.Split('-'); ScriptSubtag scriptTag; if (!StandardSubtags.RegisteredScripts.TryGet(scriptCode, out scriptTag)) { StandardSubtags.AddScript(scriptCode, scriptCode); } // if the script is also in the tag then it is explicit not implicit if (tagComponents.Length == 1 || tagComponents[1] != scriptCode) { implicitStringCode = scriptCode; } } tags.Add(new SldrLanguageTagInfo(entry.tag, implicitStringCode, entry.tag, entry.sldr)); } } return(tags); }
private Repository ToRepository(MRepository mRepository) { Timing t = new Timing(); KeyedList <string, Branch> rBranches = new KeyedList <string, Branch>(b => b.Id); Dictionary <CommitId, Commit> rCommits = new Dictionary <CommitId, Commit>(); Branch currentBranch = null; Commit currentCommit = null; CommitId rootCommitId = mRepository.RootCommitId; Repository repository = new Repository( mRepository, new Lazy <IReadOnlyKeyedList <string, Branch> >(() => rBranches), new Lazy <IReadOnlyDictionary <CommitId, Commit> >(() => rCommits), new Lazy <Branch>(() => currentBranch), new Lazy <Commit>(() => currentCommit), commitsDetailsService, mRepository.Status, rootCommitId, mRepository.Uncommitted?.Id ?? CommitId.None); foreach (var mCommit in mRepository.Commits.Values) { Commit commit = Converter.ToCommit(repository, mCommit); rCommits[commit.Id] = commit; if (mCommit == mRepository.CurrentCommit) { currentCommit = commit; } } foreach (var mBranch in mRepository.Branches) { Branch branch = Converter.ToBranch(repository, mBranch.Value); rBranches.Add(branch); if (mBranch.Value == mRepository.CurrentBranch) { currentBranch = branch; } } t.Log($"Created repository {repository.Commits.Count} commits"); return(repository); }
public object Create(object parent, object configContext, XmlNode section) { Dictionary <string, ConverterConfig> converters = new KeyedList <string, ConverterConfig>(); XmlNodeList converterList = section.SelectNodes("Converter"); foreach (XmlNode converterNode in converterList) { XmlNode currentConverterNode = converterNode; ConverterConfig cc = new ConverterConfig(); cc.Type = XML.GetAttribute(ref currentConverterNode, "Type").ToUpper(); cc.Assembly = XML.GetAttribute(ref currentConverterNode, "Assembly"); cc.Class = XML.GetAttribute(ref currentConverterNode, "Class"); converters[cc.Type] = cc; } return(converters); }
public SparseConditionalConstantPropagation(BasicBlocks basicBlocks, ITraceFactory traceFactory) { TraceFactory = traceFactory; BasicBlocks = basicBlocks; MainTrace = CreateTrace("SparseConditionalConstantPropagation"); // Method is empty - must be a plugged method if (BasicBlocks.HeadBlocks.Count == 0) { return; } blockStates = new bool[BasicBlocks.Count]; for (int i = 0; i < BasicBlocks.Count; i++) { blockStates[i] = false; } // Initialize foreach (var block in BasicBlocks.HeadBlocks) { AddExecutionBlock(block); } foreach (var block in BasicBlocks.HandlerHeadBlocks) { AddExecutionBlock(block); } while (blockWorklist.Count > 0 || instructionWorkList.Count > 0) { ProcessBlocks(); ProcessInstructions(); } DumpTrace(); // Release phiStatements = null; }
public void Start() { Console.WriteLine("=============Union Demo============"); // initialize datas uint[] ids = createIDs(10); string idstr = ids[0].ToString(); for (int i = 1; i < ids.Length; i++) { idstr += " " + ids[i].ToString(); } // add KeyedList <uint, DemoItem> list = new KeyedList <uint, DemoItem>(); KeyedList <uint, DemoItem> list1 = new KeyedList <uint, DemoItem>(); KeyedList <uint, DemoItem> list2 = new KeyedList <uint, DemoItem>(); for (int i = 0; i < ids.Length; i++) { var item = new DemoItem(ids[i], $"Item_{ids[i]}"); if (i < ids.Length / 2) { list1.Add(item); } else { list2.Add(item); } } Console.WriteLine("List1:"); print(list1); Console.WriteLine("List2:"); print(list2); Console.WriteLine("After Union"); list = KeyedList <uint, DemoItem> .Union(list1, list2); print(list); }
public async Task <KeyedList <int, TLDocument> > GetSavedGifs() { var count = DatabaseContext.Current.Count("Gifs"); var hash = count > 0 ? SettingsHelper.GifsHash : 0; var response = await _protoService.GetSavedGifsAsync(hash); if (response.IsSucceeded) { var result = response.Result as TLMessagesSavedGifs; if (result != null) { var gifs = new KeyedList <int, TLDocument>(result.Hash, result.Gifs.OfType <TLDocument>()); SettingsHelper.GifsHash = result.Hash; DatabaseContext.Current.InsertDocuments("Gifs", gifs, true); return(gifs); } else { var cached = DatabaseContext.Current.SelectDocuments("Gifs"); if (cached.Count > 0) { return(new KeyedList <int, TLDocument>(SettingsHelper.GifsHash, cached)); } } } else { var cached = DatabaseContext.Current.SelectDocuments("Gifs"); if (cached.Count > 0) { return(new KeyedList <int, TLDocument>(SettingsHelper.GifsHash, cached)); } } return(new KeyedList <int, TLDocument>(0)); }
static Country() { var alphabet = "abcdefghijklmnopqrstuvwxyz"; var list = new List <KeyedList <string, Country> >(alphabet.Length); var dictionary = new Dictionary <string, KeyedList <string, Country> >(); for (int i = 0; i < alphabet.Length; i++) { var key = alphabet[i].ToString(); var group = new KeyedList <string, Country>(key); list.Add(group); dictionary[key] = group; } foreach (var country in Countries) { dictionary[country.GetKey()].Add(country); } GroupedCountries = list; }
private async Task <KeyedList <string, TLObject> > SearchGlobalAsync(string query) { if (query.Length < 5) { return(null); } var result = await ProtoService.SearchAsync(query, 100); if (result.IsSucceeded) { if (result.Result.Results.Count > 0) { var parent = new KeyedList <string, TLObject>("Global search results"); CacheService.SyncUsersAndChats(result.Result.Users, result.Result.Chats, tuple => { result.Result.Users = tuple.Item1; result.Result.Chats = tuple.Item2; foreach (var peer in result.Result.Results) { var item = result.Result.Users.FirstOrDefault(x => x.Id == peer.Id); if (item != null) { parent.Add(item); } } }); return(parent); } } return(null); }
internal static IKeyedCollection <string, SldrLanguageTagInfo> ParseAllTags(string allTagsContent) { string[] allTags = allTagsContent.Replace("\r\n", "\n").Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); var tags = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase); foreach (string line in allTags) { string tagsStr = line; // trim off the explicit inheritance relationship information, we don't care about inheritance int index = line.LastIndexOf('>'); if (index != -1) { tagsStr = line.Substring(0, index).Trim(); } // split the the line into groups of equivalent language tags // the bar character is used to show implicit inheritance relationships between tags, // we don't care about inheritance string[] equivalentTagsStrs = tagsStr.Split('|'); foreach (string equivalentTagsStr in equivalentTagsStrs) { // split each group of equivalent language tags into individual language tags string[] tagStrs = equivalentTagsStr.Split('='); for (int i = 0; i < tagStrs.Length; i++) { tagStrs[i] = tagStrs[i].Trim(); } // check if language tag is available in the SLDR bool isAvailable = tagStrs[0].StartsWith("*"); if (isAvailable) { tagStrs[0] = tagStrs[0].Substring(1); } string sldrLangTag = tagStrs[0]; // check if a tag with a script code is equivalent to a tag without a script code // this tells us that the script is implicit string langTag, implicitStringCode; if (equivalentTagsStrs.Length == 1 && tagStrs.Length == 1) { // special case where there is a single tag on a line // if it contains a script code, then the script is implicit string[] components = tagStrs[0].Split('-'); if (components.Length == 2 && components[1].Length == 4) { langTag = components[0]; implicitStringCode = components[1]; } else { langTag = tagStrs[0]; implicitStringCode = null; } } else { var minTag = tagStrs.Select(t => new { Tag = t, Components = t.Split('-') }).MinBy(t => t.Components.Length); langTag = minTag.Tag; implicitStringCode = null; // only look for an implicit script code if the minimal tag has no script code if (minTag.Components.Length < 2 || minTag.Components[1].Length != 4) { foreach (string tagStr in tagStrs) { string[] components = tagStr.Split('-'); if (components.Length == minTag.Components.Length + 1 && components[1].Length == 4) { implicitStringCode = components[1]; } } } } SldrLanguageTagInfo existingTag; if (tags.TryGet(langTag, out existingTag)) { // alltags.txt can contain multiple lines that contain the same language tag. // if one of the lines contains information on an implicit script for a language tag, // we don't want to lose that information, so we preserve it by not replacing the // SldrLanguageTagInfo object for this language tag. if (existingTag.ImplicitScriptCode != null) { continue; } tags.Remove(langTag); } tags.Add(new SldrLanguageTagInfo(langTag, implicitStringCode, sldrLangTag, isAvailable)); } } return(tags); }
public TestWritingSystemFactory() { _writingSystems = new KeyedList<string, WritingSystemDefinition>(ws => ws.LanguageTag); }
internal static IKeyedCollection<string, SldrLanguageTagInfo> ParseAllTags(string allTagsContent) { string[] allTags = allTagsContent.Replace("\r\n", "\n").Split(new[] {"\n"}, StringSplitOptions.RemoveEmptyEntries); var tags = new KeyedList<string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase); foreach (string line in allTags) { string tagsStr = line; // trim off the explicit inheritance relationship information, we don't care about inheritance int index = line.LastIndexOf('>'); if (index != -1) tagsStr = line.Substring(0, index).Trim(); // split the the line into groups of equivalent language tags // the bar character is used to show implicit inheritance relationships between tags, // we don't care about inheritance string[] equivalentTagsStrs = tagsStr.Split('|'); foreach (string equivalentTagsStr in equivalentTagsStrs) { // split each group of equivalent language tags into individual language tags string[] tagStrs = equivalentTagsStr.Split('='); for (int i = 0; i < tagStrs.Length; i++) tagStrs[i] = tagStrs[i].Trim(); // check if language tag is available in the SLDR bool isAvailable = tagStrs[0].StartsWith("*"); if (isAvailable) tagStrs[0] = tagStrs[0].Substring(1); string sldrLangTag = tagStrs[0]; // check if a tag with a script code is equivalent to a tag without a script code // this tells us that the script is implicit string langTag, implicitStringCode; if (equivalentTagsStrs.Length == 1 && tagStrs.Length == 1) { // special case where there is a single tag on a line // if it contains a script code, then the script is implicit string[] components = tagStrs[0].Split('-'); if (components.Length == 2 && components[1].Length == 4) { langTag = components[0]; implicitStringCode = components[1]; } else { langTag = tagStrs[0]; implicitStringCode = null; } } else { var minTag = tagStrs.Select(t => new {Tag = t, Components = t.Split('-')}).MinBy(t => t.Components.Length); langTag = minTag.Tag; implicitStringCode = null; // only look for an implicit script code if the minimal tag has no script code if (minTag.Components.Length < 2 || minTag.Components[1].Length != 4) { foreach (string tagStr in tagStrs) { string[] components = tagStr.Split('-'); if (components.Length == minTag.Components.Length + 1 && components[1].Length == 4) implicitStringCode = components[1]; } } } SldrLanguageTagInfo existingTag; if (tags.TryGet(langTag, out existingTag)) { // alltags.txt can contain multiple lines that contain the same language tag. // if one of the lines contains information on an implicit script for a language tag, // we don't want to lose that information, so we preserve it by not replacing the // SldrLanguageTagInfo object for this language tag. if (existingTag.ImplicitScriptCode != null) continue; tags.Remove(langTag); } tags.Add(new SldrLanguageTagInfo(langTag, implicitStringCode, sldrLangTag, isAvailable)); } } return tags; }
private KeyboardController() { _keyboards = new KeyedList <string, KeyboardDescription>(kd => kd.Id); _eventHandlers = new Dictionary <Control, object>(); _adaptors = new Dictionary <KeyboardAdaptorType, IKeyboardRetrievingAdaptor>(); }
internal static IKeyedCollection <string, SldrLanguageTagInfo> ParseAllTagsJson(string allTagsContent) { // read in the json file /* { * "full": "aa-Latn-ET", * "name": "Afar", * "names": [ * "Adal", * ... * ], * "sldr": true, * "tag": "aa", * "tags": [ * "aa-ET", * "aa-Latn" * ] * },*/ // for each entry // tag -> langtag which is same as sldrtag // sldr -> isAvailable // tags -> process to find implicitScript var tags = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase); List <AllTagEntry> rootObject = JsonConvert.DeserializeObject <List <AllTagEntry> >(allTagsContent); foreach (AllTagEntry entry in rootObject) { if (!entry.tag.StartsWith("x-")) // tags starting with x- have undefined structure so ignoring them { LanguageSubtag languageTag; if (!entry.deprecated && !StandardSubtags.RegisteredLanguages.TryGet(entry.tag.Split('-')[0], out languageTag)) { if (entry.iso639_3 == null) { StandardSubtags.AddLanguage(entry.tag.Split('-')[0], entry.name, false, entry.tag.Split('-')[0]); } else if (!StandardSubtags.RegisteredLanguages.TryGet(entry.iso639_3, out languageTag)) { StandardSubtags.AddLanguage(entry.iso639_3, entry.name, false, entry.iso639_3); } } string implicitStringCode = null; // the script is always in the full tag string scriptCode = entry.full.Split('-')[1]; if (scriptCode.Length == 4) { var tagComponents = entry.tag.Split('-'); ScriptSubtag scriptTag; if (!StandardSubtags.RegisteredScripts.TryGet(scriptCode, out scriptTag)) { StandardSubtags.AddScript(scriptCode, scriptCode); } // if the script is also in the tag then it is explicit not implicit if (tagComponents.Length == 1 || tagComponents[1] != scriptCode) { implicitStringCode = scriptCode; } } tags.Add(new SldrLanguageTagInfo(entry.tag, implicitStringCode, entry.tag, entry.sldr)); } } return(tags); }
private KeyboardController() { _keyboards = new KeyedList<string, KeyboardDescription>(kd => kd.Id); _eventHandlers = new Dictionary<Control, object>(); _adaptors = new Dictionary<KeyboardAdaptorType, IKeyboardRetrievingAdaptor>(); }