Exemplo n.º 1
0
        public static string RefreshMacros(this string sourceText, string macrosName, string macrosCode)
        {
            var vars    = MacrosTemplates.GetParameters(sourceText, macrosName);
            var rawArgs = MacrosTemplates.GetPartOfMacros(sourceText, macrosName, "macrosArgs");

            var macrosText = macrosTemplate.Replace("{{NAME}}", macrosName);

            macrosText = macrosText.Replace("{{CODE}}", macrosCode);

            Regex rgx    = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var   match  = rgx.Match(sourceText);
            var   spaces = match.Groups[1].Value;

            macrosText = macrosText.Replace(Environment.NewLine, Environment.NewLine + spaces);

            var pt = @"(\s?)#region\s+macros\s+" + macrosName + "\\s+(.*?)#endregion";

            rgx = new Regex(pt, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            //Debug.Log(macrosName + ": " + sourceText + " => " + macrosText);
            sourceText = rgx.Replace(sourceText, spaces + macrosText);

            foreach (var item in vars)
            {
                sourceText = sourceText.Replace("/*{" + item.Key + "}*/", item.Value);
                sourceText = sourceText.Replace("{" + item.Key + "}", item.Value);
            }

            sourceText = sourceText.Replace(macrosName, macrosName + " " + rawArgs);

            return(sourceText);
        }
Exemplo n.º 2
0
        private static Dictionary <string, string> GetParameters(string sourceText, string macrosName)
        {
            string args = MacrosTemplates.GetPartOfMacros(sourceText, macrosName, "macrosArgs").Replace("\r", string.Empty).Replace("\n", string.Empty).Trim();

            var res = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(args) == false)
            {
                var separator = args.EndsWith(")") == true ? "," : args.Substring(args.Length - 1);
                args = args.Remove(args.IndexOf(")")).Replace("(", string.Empty);

                var pairs = args.Split(new string[] { separator }, System.StringSplitOptions.None);

                foreach (var pair in pairs)
                {
                    var p = pair.Split(new string[] { ":" }, System.StringSplitOptions.None);
                    if (p.Length < 2)
                    {
                        Debug.LogWarning("Wrong args format");
                        continue;
                    }

                    res.Add(p[0], p[1]);
                }
            }

            return(res);
        }