Ejemplo n.º 1
0
    void DispatchAnotherRound()
    {
        numberOfBeerUnitsLeftInTheRound = numberOfBeerUnitsPerRound;

        // position beer units initialy and give them sprites
        for (int i = 0; i < numberOfBeerUnitsPerRound; i++)
        {
            GameObject beerUnitInstance = Instantiate(beerUnitPrefab) as GameObject;
            beerUnitInstance.transform.position = new Vector2(0.0f, i);
            beerUnitInstance.GetComponent <SpriteRenderer>().sprite = beerColorSprites[beerColorIndex];
            beerUnitInstance.tag = TagResolver.GetNameByIndex(beerColorIndex);
            BeerHandler beerHandler = beerUnitInstance.GetComponent <BeerHandler>();

            /* set callback for BeerHandler which will notify
             * the BeerSpawner that the beer is destroyed */
            beerHandler.SetBeforeDestroyCallback(() =>
            {
                numberOfBeerUnitsLeftInTheRound--;
                if (numberOfBeerUnitsLeftInTheRound == 0)
                {
                    // this is the moment where all beer units in this round are destroyed
                    Debug.Log("All beer from this round destroyed");
                    GameManager.CheckIfLevelShouldEnd();
                }
            });
        }
        GameManager.UpdateBeersDispatched(numberOfBeerUnitsPerRound);
        GameManager.DecreaseRoundsLeft();
    }
Ejemplo n.º 2
0
        public void Resolve_TaggedFileDeletedAtTag()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.2");
            var file2 = new FileInfo("file2").WithTag("tag", "1.1");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file1, "1.2").WithRevision(file2, "1.2", isDead: true),
            };

            var resolver = new TagResolver(m_logger, commits.CreateAllFiles());
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Resolve succeeded");
            var resolvedCommits = resolver.Commits.ToList();

            Assert.AreEqual(resolvedCommits.Count, 3, "Commit is split");

            Assert.AreEqual(resolvedCommits[0].CommitId, "c0");
            Assert.AreEqual(resolvedCommits[1].Single().File.Name, "file1");
            Assert.AreEqual(resolvedCommits[1].Single().Revision.ToString(), "1.2");
            Assert.AreEqual(resolvedCommits[2].Single().File.Name, "file2");
            Assert.IsTrue(resolvedCommits[2].Single().IsDead);
        }
Ejemplo n.º 3
0
        public void Resolve_SplitCommit_SplitCandidate()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.2");
            var file2 = new FileInfo("file2").WithTag("tag", "1.2");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file1, "1.2"),
                new Commit("c2").WithRevision(file1, "1.3").WithRevision(file2, "1.2"),
            };
            var allFiles = commits.CreateAllFiles();

            var resolver = new TagResolver(m_logger, allFiles);
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Succeeded");
            var newCommits = resolver.Commits.ToList();

            Assert.AreEqual(newCommits.Count, 4);
            Assert.AreEqual(newCommits[0].CommitId, "c0");
            Assert.AreEqual(newCommits[1].CommitId, "c1");
            Assert.IsTrue(newCommits[2].Single().File.Name == "file2" && newCommits[2].Single().Revision.Equals(Revision.Create("1.2")));
            Assert.IsTrue(newCommits[3].Single().File.Name == "file1" && newCommits[3].Single().Revision.Equals(Revision.Create("1.3")));
        }
Ejemplo n.º 4
0
        public static string ReplaceMatchedEnclosedPhrases(string inputString, string openingString, string closingString, Dictionary <string, string> tagMapping)
        {
            TagResolver resolver = delegate(string tag)
            {
                if (tagMapping.ContainsKey(tag))
                {
                    return(tagMapping[tag]);
                }

                return(openingString + tag + closingString);
            };

            return(ReplaceEnclosedPhrases(inputString, openingString, closingString, resolver));
        }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (!GameManager.IsGameRunning())
        {
            return;
        }

        if (this.IsOutOfCameraBounds())
        {
            DestroyAndNotify();
            return;
        }

        if (nodeToVisit == null)
        {
            nodeToVisit = lastVisitedSwitchNode.GetNextNode();
        }

        if (nodeToVisit != null && (new Vector2(transform.position.x, transform.position.y) - nodeToVisit.coordinates).sqrMagnitude <= 0.1)
        {
            // check where to go
            this.transform.position = nodeToVisit.coordinates;

            if (nodeToVisit.GetType() == typeof(SwitchNode))
            {
                direction             = ((SwitchNode)nodeToVisit).GetDirectionVector();
                lastVisitedSwitchNode = (SwitchNode)nodeToVisit;
                nodeToVisit           = null;
            }
            else
            {
                BeerTag      beerTag        = TagResolver.GetTagByName(gameObject.tag);
                GameObject   houseSpriteObj = GameObject.Find("HouseNode#" + nodeToVisit.nodeId);
                HouseHandler houseHandler   = houseSpriteObj.GetComponent <HouseHandler>() as HouseHandler;
                BeerTag      houseBeerTag   = houseHandler.getBeerTag();

                if (beerTag == houseBeerTag)
                {
                    houseHandler.addLiter();
                    houseHandler.CheckAndReset();
                    GameManager.UpdateScore(1);
                }
                DestroyAndNotify();
            }
        }

        Vector2 translation = Time.deltaTime * beerSpeed * direction;

        this.transform.Translate(translation);
    }
Ejemplo n.º 6
0
        public void Resolve_FileDeletedOnTrunkAfterBranchMadeButBeforeAnyCommitsOnBranch()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.1.2.2").WithBranch("branch", "1.1.0.2");
            var file2 = new FileInfo("file2").WithTag("tag", "1.1").WithBranch("branch", "1.1.0.2");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file2, "1.2", isDead: true),
                new Commit("c2").WithRevision(file1, "1.1.2.2"),
            };

            var resolver = new TagResolver(m_logger, commits.CreateAllFiles());
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Resolve succeeded");
            Assert.AreEqual(resolver.ResolvedTags["tag"].CommitId, "c2");
            Assert.IsTrue(resolver.Commits.Select(c => c.CommitId).SequenceEqual("c0", "c1", "c2"), "No reordering");
        }
Ejemplo n.º 7
0
        public void Resolve_FileDeletedAtTag()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.1");
            var file2 = new FileInfo("file2");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file2, "1.2", isDead: true)
            };
            var target = commits.ElementAt(1);

            var resolver = new TagResolver(m_logger, commits.CreateAllFiles());
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Resolve succeeded");
            Assert.IsTrue(resolver.Commits.Select(c => c.CommitId).SequenceEqual("c0", "c1"));
            Assert.AreSame(resolver.ResolvedTags["tag"], target);
        }
Ejemplo n.º 8
0
        public void Resolve_NonExistentTag()
        {
            var file1 = new FileInfo("file1");
            var file2 = new FileInfo("file2");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file1, "1.2"),
            };
            var allFiles = commits.CreateAllFiles();

            var resolver = new TagResolver(m_logger, allFiles);
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsFalse(result, "Failed");
            Assert.IsFalse(resolver.ResolvedTags.ContainsKey("tag"));
            Assert.AreEqual(resolver.UnresolvedTags.Single(), "tag");
        }
Ejemplo n.º 9
0
        public void Resolve_FileModifiedOnTrunkAfterBranchContainingTag()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.1.2.1").WithBranch("branch", "1.1.0.2");
            var file2 = new FileInfo("file2").WithTag("tag", "1.1.2.1").WithBranch("branch", "1.1.0.2");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file1, "1.1.2.1"),
                new Commit("c2").WithRevision(file1, "1.2"),
                new Commit("c3").WithRevision(file2, "1.1.2.1"),
            };

            var resolver = new TagResolver(m_logger, commits.CreateAllFiles());
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Resolve succeeded");
            Assert.AreSame(resolver.ResolvedTags["tag"].CommitId, "c3");
            Assert.IsTrue(resolver.Commits.Select(c => c.CommitId).SequenceEqual("c0", "c1", "c2", "c3"));
        }
Ejemplo n.º 10
0
        public void Resolve_ReorderCommits_TwoFilesThatDontMove()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.1");
            var file2 = new FileInfo("file2").WithTag("tag", "1.3");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file1, "1.2"),
                new Commit("c2").WithRevision(file2, "1.2"),
                new Commit("c3").WithRevision(file2, "1.3"),
            };

            var allFiles = commits.CreateAllFiles();
            var resolver = new TagResolver(m_logger, allFiles);
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Succeeded");
            Assert.IsTrue(resolver.Commits.Select(c => c.CommitId).SequenceEqual("c0", "c2", "c3", "c1"), "Commits reordered");
            Assert.AreSame(resolver.ResolvedTags["tag"].CommitId, "c3");
        }
Ejemplo n.º 11
0
        public void Resolve_FileCreatedOnTrunkAndBackported()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.1").WithBranch("branch", "1.1.0.2");
            var file2 = new FileInfo("file2").WithTag("tag", "1.1.2.1").WithBranch("branch", "1.1.0.2");
            var file3 = new FileInfo("file3").WithTag("tag", "1.1.2.1").WithBranch("branch", "1.1.0.2");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file2, "1.1.2.1"),
                new Commit("c2").WithRevision(file3, "1.1").WithRevision(file1, "1.2"),                   // add file3 on trunk, but also take file1 to r1.2
                new Commit("c3").WithRevision(file3, "1.1.2.1"),                                          // backport file3
            };

            var resolver = new TagResolver(m_logger, commits.CreateAllFiles());
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Resolve succeeded");
            Assert.AreEqual(resolver.ResolvedTags["tag"].CommitId, "c3");
            Assert.IsTrue(resolver.Commits.Select(c => c.CommitId).SequenceEqual("c0", "c1", "c2", "c3"), "No reordering");
        }
Ejemplo n.º 12
0
        public void Resolve_FileCreatedAndDeletedOnDifferentBranch_ReorderingRequired()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.1.2.1").WithBranch("branch", "1.1.0.2");
            var file2 = new FileInfo("file2").WithTag("tag", "1.1.2.2").WithBranch("branch", "1.1.0.2");
            var file3 = new FileInfo("file3");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file1, "1.1.2.1").WithRevision(file2, "1.1.2.1"),
                new Commit("c2").WithRevision(file1, "1.1.2.2"),
                new Commit("c3").WithRevision(file2, "1.1.2.2"),
                new Commit("c4").WithRevision(file3, "1.1"),
                new Commit("c5").WithRevision(file3, "1.2", isDead: true),
            };

            var resolver = new TagResolver(m_logger, commits.CreateAllFiles());
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Resolve succeeded");
            Assert.AreSame(resolver.ResolvedTags["tag"].CommitId, "c3");
            Assert.IsTrue(resolver.Commits.Select(c => c.CommitId).SequenceEqual("c0", "c1", "c3", "c2", "c4", "c5"));
        }
Ejemplo n.º 13
0
        public void Resolve_SplitCommit_FileInfoCommitsUpdated()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.2");
            var file2 = new FileInfo("file2").WithTag("tag", "1.3");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file1, "1.2"),
                new Commit("c2").WithRevision(file1, "1.3").WithRevision(file2, "1.2"),
                new Commit("c3").WithRevision(file2, "1.3"),
            };
            var allFiles = commits.CreateAllFiles();

            var resolver = new TagResolver(m_logger, allFiles);
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Succeeded");

            // check that the FileInfo Commit lookup gets updated
            Assert.IsTrue(file1.GetCommit("1.3").CommitId.StartsWith("c2-"));
            Assert.IsTrue(file2.GetCommit("1.2").CommitId.StartsWith("c2-"));
        }
Ejemplo n.º 14
0
        public void Resolve_ReorderWithCreatedAndModifiedFileInTheMiddle()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.1");
            var file2 = new FileInfo("file2").WithTag("tag", "1.2");
            var file3 = new FileInfo("file3");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file3, "1.1"),                  // file3 added
                new Commit("c2").WithRevision(file3, "1.2"),                  // file3 modified
                new Commit("c3").WithRevision(file2, "1.2"),                  // this is the target commit for "tag"
            };
            var target   = commits.ElementAt(3);
            var allFiles = commits.CreateAllFiles();

            var resolver = new TagResolver(m_logger, allFiles);
            var result   = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsTrue(result, "Succeeded");
            Assert.AreEqual(resolver.Commits.Count(), 4, "No split");
            Assert.IsTrue(resolver.Commits.Select(c => c.CommitId).SequenceEqual("c0", "c3", "c1", "c2"), "Commits reordered");
            Assert.AreSame(resolver.ResolvedTags["tag"], target);
        }
Ejemplo n.º 15
0
        public void Resolve_PartialBranchDetection()
        {
            var file1 = new FileInfo("file1").WithTag("tag", "1.2");
            var file2 = new FileInfo("file2");
            var file3 = new FileInfo("file3");
            var file4 = new FileInfo("file4");

            var commits = new List <Commit>()
            {
                new Commit("c0").WithRevision(file1, "1.1").WithRevision(file2, "1.1"),
                new Commit("c1").WithRevision(file3, "1.1").WithRevision(file4, "1.1"),
                new Commit("c2").WithRevision(file1, "1.2"),
            };

            var resolver = new TagResolver(m_logger, commits.CreateAllFiles())
            {
                PartialTagThreshold = 2
            };
            var result = resolver.Resolve(new[] { "tag" }, commits);

            Assert.IsFalse(result, "Resolve failed");
            Assert.IsFalse(resolver.ResolvedTags.ContainsKey("tag"));
            Assert.AreEqual(resolver.UnresolvedTags.Single(), "tag");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This overload allows you to specify a mapping of phrases to their replacements instead of a resolver function.
        /// </summary>
        /// <param name="inputString"></param>
        /// <param name="openingString"></param>
        /// <param name="closingString"></param>
        /// <param name="tagMapping">A dictionary containing the mappings of form phrase=>replacement.</param>
        /// <param name="textIfNoTag">Replacement for tokens for which the phrase is not contained in the tagMapping.</param>
        /// <returns>For example mapping: "image1"=>"&lt;img src="bird.jpg"&gt;", openingPhrase "[", closingPhrase "]" and the text "This is the image of a bird: [image1]" the result is "This is the image of a bird: &lt;img src="bird.jpg"&gt;"</returns>
        public static string ReplaceEnclosedPhrases(string inputString, string openingString, string closingString, Dictionary <string, string> tagMapping, string textIfNoTag)
        {
            if (inputString == null)
            {
                throw new ArgumentNullException("inputString");
            }
            else if (openingString == null)
            {
                throw new ArgumentNullException("openingString");
            }
            else if (closingString == null)
            {
                throw new ArgumentNullException("closingString");
            }
            else if (tagMapping == null)
            {
                throw new ArgumentNullException("tagMapping");
            }
            else if (textIfNoTag == null)
            {
                throw new ArgumentNullException("textIfNoTag");
            }


            TagResolver resolver = delegate(string tag)
            {
                if (tagMapping.ContainsKey(tag))
                {
                    return(tagMapping[tag]);
                }

                return(textIfNoTag);
            };

            return(ReplaceEnclosedPhrases(inputString, openingString, closingString, resolver).Trim());
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Add a custom tag resolution rule.
 /// </summary>
 /// <example>
 /// <code>
 ///
 /// </code>
 /// </example>
 /// <typeparam name="T">Type of value.</typeparam>
 /// <param name="tag">Tag for the value.</param>
 /// <param name="regex">Pattern to match the value.</param>
 /// <param name="decode">Method that decode value from <see cref="Match"/>
 ///     data after matching by <paramref name="regex"/>.</param>
 /// <param name="encode">Method that encode value to <see cref="string"/>.</param>
 public void AddRule <T>(string tag, string regex, Func <Match, T> decode, Func <T, string> encode)
 {
     TagResolver.AddRule <T>(tag, regex, decode, encode);
 }
Ejemplo n.º 18
0
        protected override void ApplyPreferences()
        {
            var exclusions = new Dictionary <string, List <string> >();
            var global     = new List <string>().TagExclusions();

            foreach (var domain in Settings.Domains)
            {
                List <string> domainexclusions = new List <string>();
                domainexclusions.AddRange(global);
                if (UserPreferences.TryGet <string>(ModuleKey, $"tag-exclusions:{domain.Id}", out string tagExclusions) &&
                    !string.IsNullOrWhiteSpace(tagExclusions))
                {
                    foreach (var tag in tagExclusions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        domainexclusions.Add(tag);
                    }
                }
                exclusions.Add(domain.Id, domainexclusions);
            }
            Resolver             = new TagResolver(exclusions);
            HandleTagsMinChanged = Resolver.TagsFilterMin;

            if (UserPreferences.TryGet <int>(ModuleKey, "recent-tags-max", out int maxRecentTags))
            {
                Resolver.MaxRecentTags = maxRecentTags;
            }

            if (UserPreferences.TryGet <ContentTypeOption>(ModuleKey, "content-type", out ContentTypeOption option))
            {
                Input.ContentType = option;
            }

            if (UserPreferences.TryGet <string>(ModuleKey, "selected-domain", out string id))
            {
                var found = Settings.Domains.FirstOrDefault(x => x.Id.Equals(id));
                if (found != null)
                {
                    Settings.SelectedDomain = found;
                }
                else
                {
                    Settings.SelectedDomain = Settings.Domains[0];
                }
            }
            else
            {
                Settings.SelectedDomain = Settings.Domains[0];
            }
            SetSelectedTagsFilter();
            if (UserPreferences.TryGet <string>(ModuleKey, "last-opened", out string location) && Directory.Exists(location))
            {
                Application.Current.Properties[AppConstants.LastOpenedFileDialogFolderpath] = location;
            }
            if (UserPreferences.TryGet <string>(ModuleKey, "selected-language", out string language))
            {
                SetSelectedLanguage(language);
            }

            if (UserPreferences.TryGet <bool>(ModuleKey, "tags-expanded", out bool isTagsExpanded))
            {
                IsTagsExpanded = isTagsExpanded;
            }
            if (UserPreferences.TryGet <bool>(ModuleKey, "recent-tags-checked", out bool isRecentTagsChecked))
            {
                IsTagsRecentChecked = isRecentTagsChecked;
            }
            if (UserPreferences.TryGet <bool>(ModuleKey, "is-recent-queries", out bool isRecentQueries))
            {
                if (isRecentQueries)
                {
                    IsRecentQueries = true;
                }
                else
                {
                    IsFavoriteQueries = true;
                }
            }
        }
        public static bool TryBuild(this NewContentViewModel vm,
                                    TagResolver resolver,
                                    Domain domain,
                                    IEnumerable <MimeMapViewModel> mimes,
                                    ContentManager contentManager,
                                    out ContentItem item)
        {
            bool b = vm.Validate();

            item = new ContentItem();
            var contentType = vm.ContentType;

            if (b)
            {
                b            = !b;
                item.Id      = Guid.NewGuid().ToString().ToLower();
                item.Display = vm.Display;
                item.Scope   = vm.Scope;
                item.Properties.DefaultTags(domain);
                item.Properties.AddRange(resolver.Resolve(vm.Tags));
                if (vm.HasFile)
                {
                    FileInfo info = new FileInfo(vm.Filepath);
                    if (contentManager.TryInload(info, out string filename))
                    {
                        item.Mime = mimes.Resolve(info);
                        item.Body = filename;
                        item.Properties.Add(new Property()
                        {
                            Name  = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.Extension}",
                            Value = item.Mime
                        });
                        var filetype = item.Mime.Trim(new char[] { '.' });
                        vm.Paths.Add($"/files/{filetype}");
                        b = true;
                    }
                }
                else
                {
                    item.Mime = vm.Mime;
                    if (vm.IsLink)
                    {
                        if (!vm.Body.StartsWithAny(new string[] { "http://", "https://" }))
                        {
                            item.Body = $"http://{vm.Body}";
                        }
                        else
                        {
                            item.Body = vm.Body;
                        }
                    }
                    else if (vm.Body.Length > contentManager.MaxLength &&
                             contentManager.TryInloadAsFile(vm.Body, item.Id, out string filename, out FileInfo info))
                    {
                        item.Mime = mimes.Resolve(info);
                        item.Body = filename;
                        item.Properties.Add(new Property()
                        {
                            Name  = $"{AppConstants.Tags.Prefix}-{AppConstants.Tags.Extension}",
                            Value = item.Mime
                        });
                        b = true;
                    }
                    else
                    {
                        item.Body = vm.Body;
                    }

                    b = true;
                }
Ejemplo n.º 20
0
        /// <summary>
        /// Passes tokens of text of form [openingString][phrase][closingString] found in input string to a resolver function, which can transform them. For example function can find strings of form "[photo]photo1.jpg[/photo]" and replace it by "&lt;img src="photo.jpg"&gt;" using the adequate resolver delegate.
        /// </summary>
        /// <param name="inputString">The input string to run replacing process on.</param>
        /// <param name="openingString">Token's opening string. Is a regular expression string.</param>
        /// <param name="closingString">Token's closing string. Is a regular expression string.</param>
        /// <param name="resolver">The phrase resolving function.</param>
        /// <returns>Input string in which the tokens have been processed by resolver.</returns>
        public static string ReplaceEnclosedPhrases(string inputString, string openingString, string closingString, TagResolver resolver)
        {
            if (inputString == null)
            {
                throw new ArgumentNullException("inputString");
            }
            else if (openingString == null)
            {
                throw new ArgumentNullException("openingString");
            }
            else if (closingString == null)
            {
                throw new ArgumentNullException("closingString");
            }
            else if (resolver == null)
            {
                throw new ArgumentNullException("resolver");
            }

            Regex regex;

            string regexString = string.Format(@"(?<openingString>{0})(?<tag>[^{0}{1}]*)(?<closingString>{1})",
                                               openingString, closingString);

            regex = new Regex(regexString, RegexOptions.Compiled);

            MatchEvaluator tagEvaluator = delegate(Match match)
            {
                return(resolver(match.Groups["tag"].Value));
            };

            return((inputString == null) ? "" : regex.Replace(inputString, tagEvaluator));
        }