Esempio n. 1
0
        private static void ParseTags(this RcSlotRegion region, SubArray <string> textLines)
        {
            var lineIndex = 0;

            while (lineIndex <= textLines.LastIndex)
            {
                var textLine = textLines[lineIndex];

                var subArray = textLines.GetSubArray(lineIndex, textLines.LastIndex);

                if (region.JoinSlotTagsBeginMarker.MarkerRegex.IsMatch(textLine))
                {
                    lineIndex += region.ParseJoinSlotTags(subArray);
                }

                else if (region.SlotTagMarker.MarkerRegex.IsMatch(textLine))
                {
                    lineIndex += region.ParseSlotTag(subArray);
                }

                else
                {
                    lineIndex += region.ParseFixedTag(subArray);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add a slot region at the end of this template
        /// </summary>
        /// <param name="tagString"></param>
        /// <param name="linePrefix"></param>
        /// <returns></returns>
        public RcSlotRegion AddSlotRegion(string tagString, string linePrefix = null)
        {
            //The tag string must be non-null and single line
            if (string.IsNullOrEmpty(tagString))
            {
                tagString = string.Empty;
            }
            else
            {
                var tagStringLines = tagString.SplitLines();
                if (tagStringLines.Length > 1)
                {
                    tagString = tagStringLines.Concatenate(" ");
                }
            }

            var region = new RcSlotRegion(_markers)
            {
                TagString  = tagString,
                LinePrefix = linePrefix ?? string.Empty
            };

            _regionsList.Add(region);

            return(region);
        }
Esempio n. 3
0
        private static int ParseJoinSlotTags(this RcSlotRegion region, SubArray <string> textLines)
        {
            textLines = region.FindJoinSlotTagsLines(textLines);

            var tagStringLinesList = new List <string>(textLines.Length);

            for (var i = 1; i <= textLines.LastIndex; i++)
            {
                var textLine = textLines[i];

                var m = region.SlotTagMarker.MarkerRegex.Match(textLine);

                if (m.Success == false)
                {
                    break;
                }

                tagStringLinesList.Add(textLine.Substring(m.Index + m.Length));
            }

            if (tagStringLinesList.Count > 0)
            {
                region.AddSlotTag(tagStringLinesList.Concatenate(Environment.NewLine));
            }

            return(textLines.Length);
        }
Esempio n. 4
0
        private static int ParseFixedTag(this RcSlotRegion region, SubArray <string> textLines)
        {
            textLines = region.FindFixedTagLines(textLines);

            region.AddFixedTextLines(
                textLines.Where(t => region.FixedTagMarker.MarkerRegex.IsMatch(t) == false)
                );

            return(textLines.Length);
        }
Esempio n. 5
0
        private static SubArray <string> FindJoinSlotTagsLines(this RcSlotRegion region, SubArray <string> textLines)
        {
            var generatedTextFound = false;

            for (var i = 1; i <= textLines.LastIndex; i++)
            {
                var textLine = textLines[i];

                if (region.JoinSlotTagsEndMarker.MarkerRegex.IsMatch(textLine))
                {
                    //Make sure to take all generated text after the end join tags marker is found
                    for (var j = i + 1; j <= textLines.LastIndex; j++)
                    {
                        textLine = textLines[j];

                        if (region.JoinSlotTagsBeginMarker.MarkerRegex.IsMatch(textLine) ||
                            region.SlotTagMarker.MarkerRegex.IsMatch(textLine) ||
                            region.FixedTagMarker.MarkerRegex.IsMatch(textLine)
                            )
                        {
                            return(textLines.GetSubArray(0, j - 1));
                        }
                    }

                    return(textLines);
                }

                if (region.JoinSlotTagsBeginMarker.MarkerRegex.IsMatch(textLine))
                {
                    return(textLines.GetSubArray(0, i - 1));
                }

                if (region.FixedTagMarker.MarkerRegex.IsMatch(textLine))
                {
                    return(textLines.GetSubArray(0, i - 1));
                }

                if (region.SlotTagMarker.MarkerRegex.IsMatch(textLine))
                {
                    if (generatedTextFound)
                    {
                        return(textLines.GetSubArray(0, i - 1));
                    }
                }
                else
                {
                    generatedTextFound = true;
                }
            }

            return(textLines);
        }
Esempio n. 6
0
        private static int ParseSlotTag(this RcSlotRegion region, SubArray <string> textLines)
        {
            textLines = region.FindSlotTagLines(textLines);

            var textLine = textLines.FirstItem;

            var m = region.SlotTagMarker.MarkerRegex.Match(textLine);

            var tagString = textLine.Substring(m.Index + m.Length);

            region.AddSlotTag(tagString);

            return(textLines.Length);
        }
Esempio n. 7
0
        private static SubArray <string> FindSlotTagLines(this RcSlotRegion region, SubArray <string> textLines)
        {
            for (var i = 1; i <= textLines.LastIndex; i++)
            {
                var textLine = textLines[i];

                if (region.SlotTagMarker.MarkerRegex.IsMatch(textLine) ||
                    region.JoinSlotTagsBeginMarker.MarkerRegex.IsMatch(textLine) ||
                    region.FixedTagMarker.MarkerRegex.IsMatch(textLine)
                    )
                {
                    return(textLines.GetSubArray(0, i - 1));
                }
            }

            return(textLines);
        }
Esempio n. 8
0
        /// <summary>
        /// Create an exact copy of this region
        /// </summary>
        /// <param name="newMarkers"></param>
        /// <returns></returns>
        internal RcSlotRegion CreateCopy(RcTemplateMarkers newMarkers)
        {
            var newRegion = new RcSlotRegion(newMarkers);

            foreach (var tag in _tagsList)
            {
                if (tag.IsFixed)
                {
                    newRegion._tagsList.Add(((RcFixedTag)tag).CreateCopy(newMarkers));
                }

                else
                {
                    newRegion._tagsList.Add(((RcSlotTag)tag).CreateCopy(newMarkers));
                }
            }

            return(newRegion);
        }
Esempio n. 9
0
        /// <summary>
        /// Parse the given text template to add tags to a slot region if template syntax is correct
        /// </summary>
        /// <param name="region"></param>
        /// <param name="templateText"></param>
        /// <returns></returns>
        public static RcSlotRegion ParseTemplate(this RcSlotRegion region, string templateText)
        {
            region.ClearTags();

            if (string.IsNullOrEmpty(templateText))
            {
                return(region);
            }

            var verifyMarkersResult = region.VerifyMarkers();

            if (string.IsNullOrEmpty(verifyMarkersResult) == false)
            {
                throw new InvalidOperationException(verifyMarkersResult);
            }

            region.ParseTags(
                templateText.SplitLines().GetSubArray()
                );

            return(region);
        }