Example #1
0
 public static string GetSqfPropertySectionArg(SqfProperty prop, string fullString, int argIndex)
 {
     var section = GetSqfPropertySection(prop, fullString);
     if (string.IsNullOrWhiteSpace(section))
         return "";
     var filterString = Regex.Replace(prop.Format, @"\{[0-9]*\}", "(.*)");
     var matches = Regex.Split(section, filterString);
     return matches[argIndex + 1];
 }
Example #2
0
 public static string GetSqfPropertySection(SqfProperty prop, string fullString)
 {
     if (prop.AllowInfinite)
         throw new ArgumentException("This function cannot handle infinite arguments");
     var match = Regex.Match(fullString, string.Format("comment \"<{0}>\";(.*)comment \"</{0}>\";", Regex.Escape(prop.Ident)));
     if (match.Success)
     {
         return match.Groups[1].Value;
     }
     return "";
 }
Example #3
0
        public static string GetSqfPropertySectionArg(SqfProperty prop, string fullString, int argIndex)
        {
            var section = GetSqfPropertySection(prop, fullString);

            if (string.IsNullOrWhiteSpace(section))
            {
                return("");
            }
            var filterString = Regex.Replace(prop.Format, @"\{[0-9]*\}", "(.*)");
            var matches      = Regex.Split(section, filterString);

            return(matches[argIndex + 1]);
        }
Example #4
0
        public static string SetSqfPropertySectionArg(SqfProperty prop, string fullString, string content, int argIndex)
        {
            if (prop.AllowInfinite)
            {
                throw new ArgumentException("This function cannot handle infinite arguments");
            }
            if (!HasSqfPropertySection(prop, fullString))
            {
                var stringList = new List <string>();
                foreach (var it in prop.Arguments)
                {
                    if (it.Property == null)
                    {
                        stringList.Add("(_this select 0)");
                    }
                    else
                    {
                        stringList.Add("");
                    }
                }
                stringList[argIndex] = content;
                var builder = new StringBuilder();
                builder.Append("comment \"<");
                builder.Append(prop.Ident);
                builder.Append(">\";");
                builder.Append(string.Format(prop.Format, stringList.ToArray()));
                builder.Append("comment \"</");
                builder.Append(prop.Ident);
                builder.Append(">\";");
                return(fullString.Insert(0, builder.ToString()));
            }
            else
            {
                var section      = GetSqfPropertySection(prop, fullString);
                var filterString = Regex.Replace(prop.Format, @"\{[0-9]*\}", "(.*)");
                var matches      = Regex.Split(section, filterString);
                matches[argIndex + 1] = content;
                var builder = new StringBuilder();
                builder.Append("comment \"<");
                builder.Append(prop.Ident);
                builder.Append(">\";");
                string[] sArr = new string[matches.Length - 1];
                Array.Copy(matches, 1, sArr, 0, matches.Length - 1);
                builder.Append(string.Format(prop.Format, sArr));
                builder.Append("comment \"</");
                builder.Append(prop.Ident);
                builder.Append(">\";");

                return(Regex.Replace(fullString, string.Format("comment \"<{0}>\";.*comment \"</{0}>\";", Regex.Escape(prop.Ident)), builder.ToString()));
            }
        }
Example #5
0
        public static string GetSqfPropertySection(SqfProperty prop, string fullString)
        {
            if (prop.AllowInfinite)
            {
                throw new ArgumentException("This function cannot handle infinite arguments");
            }
            var match = Regex.Match(fullString, string.Format("comment \"<{0}>\";(.*)comment \"</{0}>\";", Regex.Escape(prop.Ident)));

            if (match.Success)
            {
                return(match.Groups[1].Value);
            }
            return("");
        }
Example #6
0
        public static string SetSqfPropertySectionArg(SqfProperty prop, string fullString, string content, int argIndex)
        {
            if (prop.AllowInfinite)
                throw new ArgumentException("This function cannot handle infinite arguments");
            if(!HasSqfPropertySection(prop, fullString))
            {
                var stringList = new List<string>();
                foreach (var it in prop.Arguments)
                {
                    if (it.Property == null)
                    {
                        stringList.Add("(_this select 0)");
                    }
                    else
                    {
                        stringList.Add("");
                    }
                }
                stringList[argIndex] = content;
                var builder = new StringBuilder();
                builder.Append("comment \"<");
                builder.Append(prop.Ident);
                builder.Append(">\";");
                builder.Append(string.Format(prop.Format, stringList.ToArray()));
                builder.Append("comment \"</");
                builder.Append(prop.Ident);
                builder.Append(">\";");
                return fullString.Insert(0, builder.ToString());
            }
            else
            {
                var section = GetSqfPropertySection(prop, fullString);
                var filterString = Regex.Replace(prop.Format, @"\{[0-9]*\}", "(.*)");
                var matches = Regex.Split(section, filterString);
                matches[argIndex + 1] = content;
                var builder = new StringBuilder();
                builder.Append("comment \"<");
                builder.Append(prop.Ident);
                builder.Append(">\";");
                string[] sArr = new string[matches.Length - 1];
                Array.Copy(matches, 1, sArr, 0, matches.Length - 1);
                builder.Append(string.Format(prop.Format, sArr));
                builder.Append("comment \"</");
                builder.Append(prop.Ident);
                builder.Append(">\";");

                return Regex.Replace(fullString, string.Format("comment \"<{0}>\";.*comment \"</{0}>\";", Regex.Escape(prop.Ident)), builder.ToString());
            }
        }
Example #7
0
 public static bool HasSqfPropertySection(SqfProperty prop, string fullString)
 {
     return Regex.IsMatch(fullString, string.Format("comment \"<{0}>\";(.*)comment \"</{0}>\";", Regex.Escape(prop.Ident)));
 }
Example #8
0
 public static bool HasSqfPropertySection(SqfProperty prop, string fullString)
 {
     return(Regex.IsMatch(fullString, string.Format("comment \"<{0}>\";(.*)comment \"</{0}>\";", Regex.Escape(prop.Ident))));
 }