예제 #1
0
 /// <summary>
 /// Parses a string such as "web,cms,ubermeat" (without quotations) to extract tags; the return structure
 /// will contain an array of successfully parsed tags; however if an error occurs, the error variable
 /// is set and the process is aborted.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public static ArticleTags getTags(string tags, int tagsTitleMin, int tagsTitleMax, int tagsMax)
 {
     // Initialize return struct
     ArticleTags tagCollection = new ArticleTags();
     tagCollection.error = null;
     tagCollection.tags = new List<string>();
     // Parse the tags and try to find an error
     string tag;
     foreach (string rawTag in tags.Split(','))
     {
         tag = rawTag.Trim();
         if (tag.Length != 0)
         {
             if (tag.Length < tagsTitleMin || tag.Length > tagsTitleMax)
             {
                 tagCollection.error = "Invalid tag '" + tag + "' - must be between " + tagsTitleMin + " to " + tagsTitleMax + " characters!";
                 break;
             }
             else if (tagCollection.tags.Count + 1 > tagsMax)
                 tagCollection.error = "Maximum tags of " + tagsMax + " exceeded!";
             else if(!tagCollection.tags.Contains(tag))
                 tagCollection.tags.Add(tag);
         }
     }
     return tagCollection;
 }