public void AddRange() { var set = new SortedSet <int>(); Assert.Equals(set.AddRange(new[] { 1, 2, 3 }), 3); Assert.IsTrueWith(set.SequenceEqual(new[] { 1, 2, 3 }), set); Assert.Equals(set.AddRange(new[] { 3, 4, 5 }), 2); Assert.IsTrueWith(set.SequenceEqual(new[] { 1, 2, 3, 4, 5 }), set); }
private void SetWordPattern() { SortedSet <char> letterSet = new SortedSet <char>(); foreach (var w in _hyphenatedWords.Keys) { letterSet.AddRange(w.ToCharArray()); } var pattern = string.Empty; var before = "["; const string except = @"[]|\"; const string spaces = " \t\r\n"; foreach (char c in letterSet) { var s = c.ToString(); if (spaces.Contains(s)) { continue; } if (except.Contains(s)) { pattern += before + @"\" + c; } else { pattern += before + c; } before = "|"; } pattern += "]+"; _wordPattern = new Regex(pattern, RegexOptions.Compiled); }
private void GetRegExesForSplittingQuotes() { IList <string> splitters; var quoteChars = new SortedSet <char>(new QuoteCharComparer()); var regexExpressions = new List <string>(m_quoteSystem.NormalLevels.Count); // At level x, we need continuer x, closer x, opener x+1. Continuer must be first. for (int level = 0; level < m_quoteSystem.NormalLevels.Count; level++) { splitters = new List <string>(); if (level > 0) { var quoteSystemLevelMinusOne = m_quoteSystem.NormalLevels[level - 1]; if (!string.IsNullOrWhiteSpace(quoteSystemLevelMinusOne.Continue)) { splitters.Add(quoteSystemLevelMinusOne.Continue); } splitters.Add(quoteSystemLevelMinusOne.Close); } splitters.Add(m_quoteSystem.NormalLevels[level].Open); if (level <= 0) { AddQuotationDashes(splitters); } regexExpressions.Add(BuildQuoteMatcherRegex(splitters)); } // Final regex handles when we are inside the innermost level splitters = new List <string>(); splitters.Add(m_quoteSystem.NormalLevels.Last().Close); splitters.Add(m_quoteSystem.NormalLevels.Last().Continue); if (m_quoteSystem.NormalLevels.Count == 1) { AddQuotationDashes(splitters); } regexExpressions.Add(BuildQuoteMatcherRegex(splitters)); // Get all unique characters which make up all quote marks StringBuilder sbAllCharacters = new StringBuilder(); foreach (var quoteSystemLevel in m_quoteSystem.AllLevels) { sbAllCharacters.Append(quoteSystemLevel.Open); sbAllCharacters.Append(quoteSystemLevel.Close); if (!String.IsNullOrWhiteSpace(quoteSystemLevel.Continue)) { sbAllCharacters.Append(quoteSystemLevel.Continue); } } quoteChars.AddRange(sbAllCharacters.ToString().Where(c => !char.IsWhiteSpace(c))); foreach (var expr in regexExpressions) { m_regexes.Add(new Regex(String.Format(expr, Regex.Escape(string.Join(string.Empty, quoteChars)), Regex.Escape(@"(\[\{")), RegexOptions.Compiled)); } }
public void AddRange() { var actual = new SortedSet <string>(); var expected = new[] { "hello", "i", "am", "a", "set" }; actual.AddRange(expected); CollectionAssert.AreEquivalent(expected, actual); }
public void AddRange() { var actual = new SortedSet<string>(); var expected = new[] { "hello", "i", "am", "a", "set" }; actual.AddRange(expected); CollectionAssert.AreEquivalent(expected, actual); }
private static SortedSet <string> GetFiles(string path) { var files = new SortedSet <string>(StringComparer.OrdinalIgnoreCase); using (var stream = File.OpenRead(path)) using (var zip = new ZipArchive(stream)) { files.AddRange(zip.Entries.Select(e => e.FullName)); } return(files); }
/// <summary> /// Convert inputs to a set of nupkg files. /// </summary> private static SortedSet <string> GetPackages(params string[] inputs) { var files = new SortedSet <string>(StringComparer.Ordinal); foreach (var input in inputs) { if (IsGlobbingPattern(input)) { // Resolver globbing pattern files.AddRange(ResolveGlobbingPattern(input)); } else { // Resolve file or directory var inputFile = Path.GetFullPath(input); if (Directory.Exists(inputFile)) { var directoryFiles = Directory.GetFiles(inputFile, "*.nupkg", SearchOption.AllDirectories).ToList(); files.UnionWith(directoryFiles); } else if (inputFile.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase)) { if (File.Exists(inputFile)) { files.Add(inputFile); } else { throw new FileNotFoundException($"Unable to find '{inputFile}'."); } } } } return(files); }
public static ICollection <Village> GenerateFakes(this World world, ICollection <int> allyAllies, ICollection <int> allyPlayers, ICollection <int> allyVillages, ICollection <int> enemyAllies, ICollection <int> enemyPlayers, ICollection <int> enemyVillages, double maximumDistance) { var aPlayers = new SortedSet <int>(allyPlayers ?? new int[0]); var ePlayers = new SortedSet <int>(enemyPlayers ?? new int[0]); if (allyAllies != null) { aPlayers.AddRange(world.Players.Where(player => allyAllies.Contains(player.AllyId)) .Select(player => player.Id)); } if (enemyAllies != null) { ePlayers.AddRange(world.Players.Where(player => enemyAllies.Contains(player.AllyId)) .Select(player => player.Id)); } var aVillages = new SortedSet <Village>(); aVillages.AddRange(world.Villages.Where(village => aPlayers.Contains(village.PlayerId) || allyVillages != null && allyVillages.Contains(village.Id))); var output = new List <Village>(); output.AddRange(world.Villages.Where(village => { return(ePlayers.Contains(village.PlayerId) && aVillages.Any(allyVillage => Geometry.Distance(village.Coords, allyVillage.Coords) <= maximumDistance) || enemyVillages != null && enemyVillages.Contains(village.Id) && aVillages.Any(allyVillage => Geometry.Distance(allyVillage.Coords, village.Coords) <= maximumDistance)); })); return(output); }
private static void WriteUsings( IndentingTextWriter writer, IReadOnlyList<UsingDirectiveSyntax> declaredUsings ) { Contract.Requires( writer != null ); Contract.Requires( declaredUsings != null ); var usings = new SortedSet<UsingDirectiveSyntax>( UsingDirectiveComparer.Instance ); // merge sorted, distinct list of required and declared usings usings.AddRange( RequiredUsings ); usings.AddRange( declaredUsings ); // write out required usings foreach ( var @using in usings ) writer.WriteLine( @using ); }
/// <summary> /// re-creates the list of project items and the list of available item types /// </summary> internal void CreateItemsListFromMSBuild() { WorkbenchSingleton.AssertMainThread(); using (var c = OpenCurrentConfiguration()) { foreach (ProjectItem item in items) { item.Dispose(); } items.Clear(); itemsReadOnly = null; // remove readonly variant of item list - will regenerate on next Items call SortedSet<ItemType> availableFileItemTypes = new SortedSet<ItemType>(); availableFileItemTypes.AddRange(ItemType.DefaultFileItems); foreach (var item in c.Project.GetItems("AvailableItemName")) { availableFileItemTypes.Add(new ItemType(item.EvaluatedInclude)); } this.availableFileItemTypes = availableFileItemTypes.AsReadOnly(); foreach (var item in c.Project.AllEvaluatedItems) { if (item.IsImported) continue; items.Add(CreateProjectItem(new MSBuildItemWrapper(this, item))); } ClearFindFileCache(); } }
private void DuplicateCurrentObjectsAndIndices(List<FPGameObject> currentObjects, SortedSet<int> currentIndices) { currentObjects.Clear(); foreach (var gameObject in gameObjects) { var duplicate = gameObject.Duplicate(0.0f, 0.0f); if (duplicate != null) { currentObjects.Add(duplicate); } else // elevator end { var parentInGameObjects = gameObject.NextPart; var parentInOldObjects = currentObjects[gameObjects.IndexOf(parentInGameObjects)]; var nextPart = parentInOldObjects.NextPart; currentObjects.Add(nextPart); } } currentIndices.Clear(); currentIndices.AddRange(selectedIndices); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { //Load the relationship attribute var rels = new SortedSet <string>(StringComparer.OrdinalIgnoreCase); if (output.Attributes.ContainsName("rel")) { rels.AddRange(output.Attributes["rel"].Value.ToStringOrEmpty().SplitI(";, ")); } var isDownload = false; if (output.Attributes.ContainsName("download")) { var download = output.Attributes["download"].Value.ToString(); if (download.EqualsI("false")) { output.Attributes.RemoveAll("download"); } else { isDownload = true; output.Attributes.RemoveAll("download"); output.Attributes.Insert(0, new TagHelperAttribute("download", null, HtmlAttributeValueStyle.Minimized)); } } var isExternal = false; if (output.Attributes.ContainsName("href")) { var href = output.Attributes["href"].Value.ToStringOrEmpty().TrimI(" \\/."); if (!string.IsNullOrWhiteSpace(href) && !href.StartsWithI("mailto:", "javascript:", "ftp:", "file:", "#")) { //Check if the link is external isExternal = ViewContext.HttpContext.GetIsExternalUrl(href); //If external then if (isExternal) { //Indicates that the referenced document is not part of the same site as the current document rels.Add("external"); //Prevent google from following the link rels.Add("nofollow"); //Never send the referrer or allow opening of tabs rels.AddRange("noreferrer", "noopener"); } } } #region Google Analytics Tracking ///Change category andtrack category to data-track-category ReplaceTrack("category", "action", "label", "options"); void ReplaceTrack(params string[] fieldNames) { Parallel.ForEach( fieldNames, fieldName => { foreach (var fn in new[] { $"track-{fieldName}", fieldName }) { var i = output.Attributes.IndexOfName(fn); if (i > -1) { if (output.Attributes.ContainsName($"data-track-{fieldName}")) { throw new ArgumentException($"data-track-{fieldName}", "Duplicate tracking field"); } var newAttribute = new TagHelperAttribute( $"data-track-{fieldName}", output.Attributes[i].Value, output.Attributes[i].ValueStyle); output.Attributes.RemoveAt(i); output.Attributes.Insert(i, newAttribute); } } }); } //Check if link should be tracked //TODO check what these fields mean var isTracked = output.Attributes.ContainsName("data-track-category") || output.Attributes.ContainsName("data-track-action") || output.Attributes.ContainsName("data-track-label") || output.Attributes.ContainsName("data-track-options"); //Add the track relationship if (isTracked) { rels.Add("track"); } //Ensure we have at least a category when tracking if (!output.Attributes.ContainsName("data-track-category") && rels.Contains("track")) { throw new ArgumentNullException("data-track-category", "You must specify a category for tracking"); } #endregion //Make sure we open in new tab unless otherwise stated if ((isDownload || isExternal) && !output.Attributes.ContainsName("target")) { output.Attributes.SetAttribute("target", "_blank"); } //Save the relationship attribute changes if (rels.Any()) { output.Attributes.SetAttribute("rel", rels.ToDelimitedString(" ")); } else if (output.Attributes.ContainsName("rel")) { output.Attributes.RemoveAll("rel"); } }
/// <summary> /// re-creates the list of project items and the list of available item types /// </summary> internal void CreateItemsListFromMSBuild() { WorkbenchSingleton.AssertMainThread(); using (var c = OpenCurrentConfiguration()) { foreach (ProjectItem item in items) { item.Dispose(); } items.Clear(); itemsReadOnly = null; // remove readonly variant of item list - will regenerate on next Items call SortedSet<ItemType> availableFileItemTypes = new SortedSet<ItemType>(); availableFileItemTypes.AddRange(ItemType.DefaultFileItems); foreach (var item in c.Project.GetItems("AvailableItemName")) { availableFileItemTypes.Add(new ItemType(item.EvaluatedInclude)); } this.availableFileItemTypes = availableFileItemTypes.AsReadOnly(); foreach (var item in c.Project.AllEvaluatedItems) { if (item.IsImported) continue; items.Add(CreateProjectItem(new MSBuildItemWrapper(this, item))); } ClearFindFileCache(); } // refresh project browser to make sure references and other project items are still valid // after TargetFramework or other properties changed. Fixes SD-1876 if (!isLoading) ProjectBrowserPad.RefreshViewAsync(); }