示例#1
0
        ///---------------------------------------------------------------------
        protected virtual BuildResult DoApplyZonedScript(ref FileData fileData)
        {
            var keywords = TemplateRegistry.Keywords;
            var ignorers = TemplateHelpers.GatherValidIgnorables(fileData.destination.content, fileData.destination.extension);
            var stack    = new KeywordTemplateStack(KeywordTemplateMode.UsedAsScope, fileData.destination.content);

            for (var r = 0; r < keywords.Count; r++)
            {
                var keyword = keywords[r];
                if (!keyword.Match(fileData.destination.name, fileData.destination.extension, fileData.destination.content))
                {
                    continue;
                }

                if (keyword.TemplateMode == KeywordTemplateMode.UsedAsSwap)
                {
                    continue;
                }

                var start = 0;
                while ((start = fileData.destination.content.IndexOf(keyword.TagBegin, start)) >= 0)
                {
                    var safety = ignorers.AdvanceToSafety(start, IgnorableStyle.Text);
                    if (safety != start)
                    {
                        start = safety;
                        continue;
                    }

                    var tagEnd = keyword.TagEnd;
                    var end    = fileData.destination.content.IndexOf(tagEnd, start);
                    if (end < 0)
                    {
                        break;
                    }

                    end += tagEnd.Length;

                    stack.Add(keyword, start, end);

                    start = end;
                }
            }

            if (stack.CanApply)
            {
                fileData.destination.content = stack.Apply();
            }

            return(BuildResult.ValueType.Success);
        }
示例#2
0
        ///---------------------------------------------------------------------
        protected virtual BuildResult DoApplyFixUps(ref FileData fileData)
        {
            Profiler.BeginSample($"DoApplyFixUps()");

            InitCommentSplits();

            var commentSplitRoot   = Strings.CommentSplitRoot;
            var commentSplitLength = Strings.CommentSplitLength - 1;
            var ignorers           = TemplateHelpers.GatherValidIgnorables(fileData.destination.content, fileData.destination.extension);
            var stack = new KeywordTemplateStack(KeywordTemplateMode.UsedAsScope, fileData.destination.content);

            var position = 0;

            while ((position = fileData.destination.content.IndexOf(commentSplitRoot, position)) >= 0)
            {
                Profiler.BeginSample($"while(position)");

                var safety = ignorers.AdvanceToSafety(position, IgnorableStyle.Text);
                if (safety != position)
                {
                    position = safety;

                    Profiler.EndSample();
                    continue;
                }

                var lineStart = fileData.destination.content.LastIndexOf(Strings.Separator.LineFeed.C(), position);
                var lineEnd   = fileData.destination.content.IndexOf(Strings.Separator.LineFeed.C(), position);

                if (lineStart < 0 || lineEnd < 0)
                {
                    position++;

                    Profiler.EndSample();
                    continue;
                }

                lineStart++;
                var line = fileData.destination.content.Substring(lineStart, lineEnd - lineStart);
                if (line.Length != commentSplitLength)
                {
                    var diff = commentSplitLength - line.Length;
                    if (diff < 0)
                    {
                        line = line.Substring(0, commentSplitLength);
                    }
                    else
                    {
                        line += commentSplits[diff];
                    }

                    stack.Add(line, lineStart, lineEnd);
                }

                position = lineEnd;

                Profiler.EndSample();
            }

            if (stack.CanApply)
            {
                fileData.destination.content = stack.Apply();
            }

            Profiler.EndSample();

            return(BuildResult.ValueType.Success);
        }