Ejemplo n.º 1
0
        /// <summary>
        /// Create an exact copy of this template
        /// </summary>
        /// <returns></returns>
        public RcTemplate CreateCopy()
        {
            var newTemplate = new RcTemplate();

            //Copy markers
            var newMarkers = newTemplate._markers;

            newMarkers.RegionBeginMarker.MarkerText       = _markers.RegionBeginMarker.MarkerText;
            newMarkers.RegionEndMarker.MarkerText         = _markers.RegionEndMarker.MarkerText;
            newMarkers.FixedTagMarker.MarkerText          = _markers.FixedTagMarker.MarkerText;
            newMarkers.SlotTagMarker.MarkerText           = _markers.SlotTagMarker.MarkerText;
            newMarkers.JoinSlotTagsBeginMarker.MarkerText = _markers.JoinSlotTagsBeginMarker.MarkerText;
            newMarkers.JoinSlotTagsEndMarker.MarkerText   = _markers.JoinSlotTagsEndMarker.MarkerText;

            //Copy regions
            foreach (var region in _regionsList)
            {
                if (region.IsFixed)
                {
                    newTemplate._regionsList.Add(((RcFixedRegion)region).CreateCopy());
                }

                else
                {
                    newTemplate._regionsList.Add(((RcSlotRegion)region).CreateCopy(newMarkers));
                }
            }

            return(newTemplate);
        }
Ejemplo n.º 2
0
        private static int ParseSlotRegion(this RcTemplate template, SubArray <string> textLines)
        {
            //Find the lines that belong to this region
            textLines = template.FindSlotRegionLines(textLines);

            var beginLineText = textLines.FirstItem;

            var m = template.RegionBeginMarker.MarkerRegex.Match(beginLineText);

            var regionLinePrefix =
                m.Index > 0
                ? beginLineText.Substring(0, m.Index)
                : string.Empty;

            var tagString =
                m.Index + m.Length < beginLineText.Length
                ? beginLineText.Substring(m.Index + m.Length)
                : string.Empty;

            var slotRegion = template.AddSlotRegion(tagString, regionLinePrefix);

            var subArray =
                (template.RegionEndMarker.MarkerRegex.IsMatch(textLines.LastItem))
                    ? textLines.GetSubArray(1, textLines.LastIndex - 1)
                    : textLines.GetSubArray(1, textLines.LastIndex);

            slotRegion.ParseTags(subArray);

            //Return the number of lines used in this region
            return(textLines.Length);
        }
Ejemplo n.º 3
0
        private static int ParseFixedRegion(this RcTemplate template, SubArray <string> textLines)
        {
            //Find the lines that belong to this region
            textLines = template.FindFixedRegionLines(textLines);

            template.AddFixedRegionLines(textLines);

            //Return the number of lines used in this region
            return(textLines.Length);
        }
Ejemplo n.º 4
0
        private static SubArray <string> FindFixedRegionLines(this RcTemplate template, SubArray <string> textLines)
        {
            for (var i = 1; i <= textLines.LastIndex; i++)
            {
                var textLine = textLines[i];

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

            return(textLines);
        }
Ejemplo n.º 5
0
        private static void ParseRegions(this RcTemplate template, SubArray <string> textLines)
        {
            var lineIndex = 0;

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

                var subArray = textLines.GetSubArray(lineIndex, textLines.Length - 1);

                if (template.RegionBeginMarker.MarkerRegex.IsMatch(textLine))
                {
                    lineIndex += template.ParseSlotRegion(subArray);
                }

                else
                {
                    lineIndex += template.ParseFixedRegion(subArray);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Parse the given text to add regions to a region template if text syntax is correct
        /// </summary>
        /// <param name="template"></param>
        /// <param name="templateText"></param>
        /// <returns></returns>
        public static RcTemplate ParseTemplate(this RcTemplate template, string templateText)
        {
            template.ClearRegions();

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

            var verifyMarkersResult = template.VerifyMarkers();

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

            template.ParseRegions(
                templateText.SplitLines().GetSubArray()
                );

            return(template);
        }
Ejemplo n.º 7
0
 public RegionComposer()
 {
     Template = new RcTemplate();
 }