/// <summary> /// Returns the comment contents after variable expansion. /// </summary> /// <param name="store">Variable store</param> /// <returns>Array of strings containing the initial comments with all variable references expanded</returns> public virtual string [] GetLines ( CommentVariables store ) { List<string> lines = new List<string> ( ) ; foreach ( string line in TextLines ) { MatchCollection matches = Regex. Matches ( line, VariableRegexPattern, VariableRegexOptions ) ; if ( matches. Count == 0 ) { lines. Add ( line ) ; continue ; } StringBuilder newline = new StringBuilder ( ) ; int next_index = 0 ; foreach ( Match match in matches ) { if ( match. Index > 0 ) newline. Append ( line. Substring ( next_index, match. Index - next_index ) ) ; next_index = match. Index + match. Length ; string vname = match. Groups [ "var" ]. Value ; string options = match. Groups [ "options" ]. Value ; string value = store. Expand ( vname, options ) ; newline. Append ( value ) ; } if ( next_index < line. Length ) newline. Append ( line. Substring ( next_index ) ) ; lines. Add ( newline. ToString ( ) ) ; } return ( lines. ToArray ( ) ) ; }
/// <summary> /// Validates the contents of the comments file. /// </summary> protected override void ValidateStructure ( ) { foreach ( XmlNode node in DocumentElement ) { if ( node. NodeType != XmlNodeType. Element ) continue ; switch ( node. Name. ToLower ( ) ) { case "author" : Author = new Author ( this, node ) ; break ; case "categories" : Categories = new Categories ( this, node ) ; break ; case "templates" : Templates = new Templates ( this, node ) ; break ; case "groups" : Groups = new Groups ( this, node ) ; break ; default : AddValidationMessage ( XmlParseErrorSeverity. Error, "Unrecognized tag <" + node. Name + ">" ) ; break ; } } // Check that all required nodes are present (paranoia, since the xsd validation has already been performed) if ( Author == null ) AddValidationMessage ( XmlParseErrorSeverity. Error, "Missing tag '<author>'" ) ; if ( Categories == null ) AddValidationMessage ( XmlParseErrorSeverity. Error, "Missing tag '<categories>'" ) ; if ( Templates == null ) AddValidationMessage ( XmlParseErrorSeverity. Error, "Missing tag '<templates>'" ) ; if ( Groups == null ) AddValidationMessage ( XmlParseErrorSeverity. Error, "Missing tag '<groups>'" ) ; // Checks on <templates> entries if ( Templates != null ) { // Check that each comment in the <template> nodes reference an existing category foreach ( Template template in Templates ) { foreach ( Comment comment in template. Comments ) { if ( ! Categories. Exists ( comment. Name ) ) AddValidationMessage ( XmlParseErrorSeverity. Error, "Comment category \"" + comment. Name + "\" specified in template \"" + template. Name + "\" does not exist" ) ; } } // Check that template names are unique if ( Templates. Count == 0 ) AddValidationMessage ( XmlParseErrorSeverity. Warning, "No template defined in the <templates> node" ) ; else { for ( int i = 1 ; i < Templates. Count ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( String. Compare ( Templates [i]. Name, Templates [j]. Name, true ) == 0 ) { AddValidationMessage ( XmlParseErrorSeverity. Error, "Template \"" + Templates [i]. Name + "\" is defined more than once" ) ; break ; } } } } } // Checks on <groups> entries if ( Groups != null ) { // Check that each comment in the <group> nodes reference an existing category foreach ( Group group in Groups ) { foreach ( Comment comment in group. Comments ) { if ( ! Categories. Exists ( comment. Name ) ) AddValidationMessage ( XmlParseErrorSeverity. Error, "Comment category \"" + comment. Name + "\" specified in group \"" + group. Name + "\" does not exist" ) ; } if ( String. IsNullOrWhiteSpace ( group. ExtensionsAsString ) ) AddValidationMessage ( XmlParseErrorSeverity. Error, "Group \"" + group. Name + "\" is not associated with any file extension ('extensions' attribute value is empty)" ) ; } // Check that group names are unique if ( Groups. Count == 0 ) AddValidationMessage ( XmlParseErrorSeverity. Warning, "No group defined in the <groups> node" ) ; else { for ( int i = 1 ; i < Groups. Count ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( String. Compare ( Groups [i]. Name, Groups [j]. Name, true ) == 0 ) { AddValidationMessage ( XmlParseErrorSeverity. Error, "Group \"" + Groups [i]. Name + "\" is defined more than once" ) ; break ; } } } } } // Create the variable store at the end, since it may reference values that are available only after parsing Variables = new CommentVariables ( this ) ; }