Ejemplo n.º 1
0
        public void AppendJoinedBlockElements(List <Block> referenceBlocks, IReferenceLanguageInfo languageInfo)
        {
            var nestedRefBlocks = new List <Block>();

            foreach (Block r in referenceBlocks)
            {
                if (r.MatchesReferenceText)
                {
                    nestedRefBlocks.Add(r.ReferenceBlocks.Single());
                }
                foreach (BlockElement element in r.BlockElements)
                {
                    var scriptText = element as ScriptText;
                    if (scriptText != null)
                    {
                        var prevScriptText = BlockElements.LastOrDefault() as ScriptText;
                        if (prevScriptText != null)
                        {
                            prevScriptText.Content = prevScriptText.Content.TrimEnd() + languageInfo.WordSeparator + scriptText.Content;
                            continue;
                        }
                    }
                    BlockElements.Add(element.Clone());
                }
            }
            if (nestedRefBlocks.Any())
            {
                var backingRefBlock = new Block(StyleTag, ChapterNumber, InitialStartVerseNumber,
                                                InitialEndVerseNumber);
                backingRefBlock.SetCharacterAndDeliveryInfo(this);
                backingRefBlock.AppendJoinedBlockElements(nestedRefBlocks, languageInfo.BackingReferenceLanguage);
                SetMatchedReferenceBlock(backingRefBlock);
            }
        }
Ejemplo n.º 2
0
        private void ParsePlainText(string text)
        {
            var verseNumbers = new Regex(@"((" + kRegexForVerseNumber + ")|" + Sound.kRegexForUserLocatedSounds + ")" + kRegexForWhitespaceFollowingVerseNumber);
            var pos          = 0;

            text = text.TrimStart();
            var prependSpace = "";

            while (pos < text.Length)
            {
                var match = verseNumbers.Match(text, pos);
                if (match.Success)
                {
                    if (match.Index == pos)
                    {
                        // We don't allow two verses in a row with no text between, so unless this is a verse at the very
                        // beginning, remove the preceding (empty) verse.
                        if (match.Index > 0 && BlockElements.Last() is Verse)
                        {
                            BlockElements.RemoveAt(BlockElements.Count - 1);
                        }

                        if (match.Groups["verse"].Success)
                        {
                            InitialStartVerseNumber = Int32.Parse(match.Result("${startVerse}"));
                            int endVerse;
                            if (!Int32.TryParse(match.Result("${endVerse}"), out endVerse))
                            {
                                endVerse = 0;
                            }
                            InitialEndVerseNumber = endVerse;
                        }
                    }
                    else
                    {
                        BlockElements.Add(new ScriptText(prependSpace + text.Substring(pos, match.Index - pos)));
                    }
                    if (match.Groups["verse"].Success)
                    {
                        BlockElements.Add(new Verse(match.Result("${verse}").Replace(',', '-')));
                    }
                    else
                    {
                        var prevText = BlockElements.LastOrDefault() as ScriptText;
                        if (prevText != null && prevText.Content.Last() != ' ')
                        {
                            prevText.Content += " ";
                        }
                        BlockElements.Add(Sound.CreateFromMatchedRegex(match));
                        prependSpace = " ";
                    }
                    pos = match.Index + match.Length;
                }
                else
                {
                    BlockElements.Add(new ScriptText(prependSpace + text.Substring(pos)));
                    break;
                }
            }
            if (!BlockElements.Any())
            {
                BlockElements.Add(new ScriptText(""));
            }
        }