Пример #1
0
 /// <summary>
 /// Parse any direct tag input values.
 /// </summary>
 /// <param name="data">The input tag data.</param>
 public abstract string Handle(TagData data);
Пример #2
0
 /// <summary>
 /// Reads and parses all tags inside a string.
 /// </summary>
 /// <param name="base_color">The base color for tags to use.</param>
 /// <param name="vars">Any variables in this tag's context.</param>
 /// <param name="input">The tagged string.</param>
 /// <param name="mode">What debugmode to use.</param>
 /// <returns>The string with tags parsed.</returns>
 public string ParseTags(string input, string base_color, Dictionary<string, TemplateObject> vars, DebugMode mode)
 {
     if (input.IndexOf("<{") < 0)
     {
         return Unescape(input);
     }
     int len = input.Length;
     int blocks = 0;
     int brackets = 0;
     StringBuilder blockbuilder = new StringBuilder();
     StringBuilder final = new StringBuilder(len);
     for (int i = 0; i < len; i++)
     {
         if (i + 1 < len && input[i] == '<' && input[i + 1] == '{')
         {
             blocks++;
             if (blocks == 1)
             {
                 i++;
                 continue;
             }
         }
         else if (i + 1 < len && input[i] == '}' && input[i + 1] == '>')
         {
             blocks--;
             if (blocks == 0)
             {
                 string value = blockbuilder.ToString();
                 List<string> split = value.Split(dot).ToList();
                 for (int s = 0; s < split.Count; s++)
                 {
                     split[s] = split[s].Replace("&dot", ".").Replace("&amp", "&");
                 }
                 value = value.Replace("&dot", ".").Replace("&amp", "&");
                 TagData data = new TagData(this, split, base_color, vars, mode);
                 TemplateTags handler;
                 bool handled = Handlers.TryGetValue(data.Input[0], out handler);
                 if (handled)
                 {
                     string res = handler.Handle(data);
                     final.Append(res);
                     if (mode <= DebugMode.FULL)
                     {
                         CommandSystem.Output.Good("Filled tag " + TextStyle.Color_Separate +
                             Escape("<{" + value + "}>") + TextStyle.Color_Outgood + " with \"" + TextStyle.Color_Separate + Escape(res)
                             + TextStyle.Color_Outgood + "\".", mode);
                     }
                 }
                 else
                 {
                     if (mode <= DebugMode.MINIMAL)
                     {
                         CommandSystem.Output.Bad("Failed to fill tag tag " + TextStyle.Color_Separate +
                             Escape("<{" + value + "}>") + TextStyle.Color_Outbad + "!", mode);
                     }
                     final.Append("{UNKNOWN_TAG:" + data.Input[0] + "}");
                 }
                 blockbuilder = new StringBuilder();
                 i++;
                 continue;
             }
         }
         else if (blocks == 1 && input[i] == '[')
         {
             brackets++;
         }
         else if (blocks == 1 && input[i] == ']')
         {
             brackets--;
         }
         if (blocks > 0)
         {
             switch (input[i])
             {
                 case '.':
                     if (blocks > 1 || brackets > 0)
                     {
                         blockbuilder.Append("&dot");
                     }
                     else
                     {
                         blockbuilder.Append(".");
                     }
                     break;
                 case '&':
                     blockbuilder.Append("&amp");
                     break;
                 default:
                     blockbuilder.Append(input[i]);
                     break;
             }
         }
         else
         {
             final.Append(input[i]);
         }
     }
     return Unescape(final.ToString());
 }