예제 #1
0
        private void SetupTrimCommand()
        {
            var matches = RegExHelper.GetContainedString(parameterPath, @"\[", "]");

            if (matches.Count > 0 && !string.IsNullOrEmpty(matches[0].Value))
            {
                var rawTrim = matches[0].Value;
                parameterPath = parameterPath.Replace("[" + rawTrim + "]", "");
                var trimValues = rawTrim.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                if (trimValues.Length == 1)
                {
                    if (rawTrim[0] == ':')
                    {
                        trimRange = new Tuple <int?, int?>(null, int.Parse(trimValues[0]));
                    }
                    else
                    {
                        trimRange = new Tuple <int?, int?>(int.Parse(trimValues[0]), null);
                    }
                }
                else
                {
                    trimRange = new Tuple <int?, int?>(int.Parse(trimValues[0]), int.Parse(trimValues[1]));
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Creates a placeholder from a raw string.
        /// </summary>
        /// <param name="raw">Raw string.</param>
        /// <returns></returns>
        public static Placeholder FromRaw(string raw)
        {
            var matches = RegExHelper.GetContainedString(raw, "{", "}");

            if (matches.Count > 0)
            {
                var unwrapped = matches[0].Value;
                return(new Placeholder(unwrapped));
            }

            return(null);
        }
예제 #3
0
        private Placeholder(string raw)
        {
            ConcreteForm = "${" + RegExHelper.ClearStringFormatting(raw) + "}";
            var parts = raw.Split('?');

            parameterPath = parts[0];
            if (parts.Length > 1)
            {
                modifier = parts[1];
            }

            SetupTrimCommand();
        }
예제 #4
0
        /// <summary>
        /// Creates a new instance of a template entity.
        /// </summary>
        /// <param name="raw">Raw source string.</param>
        public TemplateModel(string raw)
        {
            concreteForm = RegExHelper.ClearStringFormatting(raw);
            raw          = RegExHelper.FormatLines(raw);

            using (var ms = new MemoryStream())
            {
                using (var sw = new StreamWriter(ms))
                {
                    sw.Write(raw);
                    sw.Flush();
                    ExtractFromStream(ms);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Creates many placeholders from a raw string.
        /// </summary>
        /// <param name="raw">Raw string.</param>
        /// <returns></returns>
        public static Placeholder[] ManyFromRaw(string raw)
        {
            var matches = RegExHelper.GetContainedString(raw, "{", "}");

            if (matches.Count > 0)
            {
                var result = new List <Placeholder>();
                foreach (Match c in matches)
                {
                    var unwrapped = c.Value;
                    result.Add(new Placeholder(unwrapped));
                }

                return(result.ToArray());
            }

            return(null);
        }
예제 #6
0
        /// <summary>
        /// Creates a new instance of the IfBlock class.
        /// </summary>
        /// <param name="raw">Raw string.</param>
        public IfBlock(string raw)
        {
            ConcreteForm = RegExHelper.TrimUntilChar(RegExHelper.ClearStringFormatting(raw), '$') + "}";
            var subBlocks  = RegExHelper.GetContainedString(raw, ">", "<");
            var innerBlock = RegExHelper.GetContainedString(raw, "<#if", ">")[0].Value;


            var rawAction = subBlocks[0].Value;

            if (subBlocks.Count > 1)
            {
                elseAction = new TemplateModel(subBlocks[1].Value);
            }

            action = new TemplateModel(rawAction);

            innerBlock = innerBlock.Replace(" ", string.Empty);

            if (innerBlock.Contains("&&"))
            {
                optr = "&&";
            }
            else if (innerBlock.Contains("||"))
            {
                optr = "||";
            }

            if (string.IsNullOrEmpty(optr))
            {
                conditions = new[] { new IfCondition(innerBlock) };
            }
            else
            {
                var rawConditions = innerBlock.Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries);
                var condList      = new List <IfCondition>();

                foreach (var c in rawConditions)
                {
                    condList.Add(new IfCondition(c));
                }

                conditions = condList.ToArray();
            }
        }