<commit_before>// NAnt - A .NET build tool
// Copyright (C) 2001-2004 <NAME>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// <NAME>
//

using System;
using NAnt.Core;
using NAnt.Core.Types;
using NAnt.Core.Attributes;

namespace NAnt.Contrib.Functions {
    
    /// <summary>
    /// Provides methods for interrogating Filesets.
    /// </summary>
    [FunctionSet("fileset", "FileSet")]
    public class FileSetFunctions : FunctionSetBase {
        
        #region Public Instance Constructors
        
        public FileSetFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
        
        #endregion Public Instance Constructors

        #region Public Instance Methods
        
        /// <summary>
        /// Determines the number of files within a <see cref="FileSet"/>.
        /// </summary>
        /// <param name="fileset">The id of the FileSet to scan.</param>
        /// <returns>The number of files included in the FileSet</returns>
        /// <exception cref="ArgumentException"><paramref name="fileset" /> is not a valid refid to a defined fileset.</exception>
        /// <example>
        ///   <para>
        ///   Define a fileset and check the number of files in it.
        ///   </para>
        ///   <code>
        ///     <![CDATA[
        /// <fileset id="test.fileset">
        ///     <include name="**/*.cs">
        /// </fileset>
        /// <echo message="FileSet contains ${fileset::get-file-count('test.fileset')} files." />
        /// ]]>
        ///   </code>
        /// </example>
        [Function("get-file-count")]
        public int GetFileCount(string fileset) {
            //Try to retrieve the specified fileset from the Data References on the project
            FileSet fs = base.Project.DataTypeReferences[fileset] as FileSet;
            //If the value was missing or the referenced type was not a fileset, then throw an exception
            if (fs == null) {
                throw new ArgumentException(string.Format("'{0}' is not a valid fileset reference", fileset));
            }
            //Otherwise return the number of files in the fileset.
            return fs.FileNames.Count;
        }

        /// <summary>
        /// Determines whether <see cref="FileSet"/> contains any files.
        /// </summary>
        /// <param name="fileset">The id of the fileset to check.</param>
        /// <returns><see langword="true" /> if the FileSet contains one or more files, otherwise <see langword="false"/>.</returns>
        /// <exception cref="ArgumentException"><paramref name="fileset" /> is not a valid refid to a defined fileset.</exception>
        /// <example>
        ///   <para>
        ///   Perform conditional processing on a fileset if it contains files.
        ///   </para>
        ///   <code>
        ///     <![CDATA[
        /// <fileset id="test.fileset">
        ///     <include name="**/*.cs">
        /// </fileset>
        /// <if test="${fileset::has-files('test.fileset')}">
        ///     <dostuff... />
        /// </if>
        /// ]]>
        ///   </code>
        /// </example>
        [Function("has-files")]
        public bool HasFiles(string fileset) {
            //Try to retrieve the specified fileset from the Data References on the project
            FileSet fs = base.Project.DataTypeReferences[fileset] as FileSet;
            //If the value was missing or the referenced type was not a fileset, then throw an exception
            if (fs == null) {
                throw new ArgumentException(string.Format("'{0}' is not a valid fileset reference", fileset));
            }
            //Otherwise return whether or not the fileset contains files.
            return (fs.FileNames.Count > 0);
        }
        
        #endregion Public Instance Methods
    }
}<commit_msg>Update from <NAME> to convert a fileset to a delimeted string<commit_after>// NAnt - A .NET build tool
// Copyright (C) 2001-2004 <NAME>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// <NAME>
//

using System;
using System.Text;
using NAnt.Core;
using NAnt.Core.Types;
using NAnt.Core.Attributes;

namespace NAnt.Contrib.Functions {
    
    /// <summary>
    /// Provides methods for interrogating Filesets.
    /// </summary>
    [FunctionSet("fileset", "FileSet")]
    public class FileSetFunctions : FunctionSetBase {
        
        #region Public Instance Constructors
        
        public FileSetFunctions(Project project, PropertyDictionary properties) : base(project, properties) { }
        
        #endregion Public Instance Constructors

        #region Public Instance Methods
        
        /// <summary>
        /// Determines the number of files within a <see cref="FileSet"/>.
        /// </summary>
        /// <param name="fileset">The id of the FileSet to scan.</param>
        /// <returns>The number of files included in the FileSet</returns>
        /// <exception cref="ArgumentException"><paramref name="fileset" /> is not a valid refid to a defined fileset.</exception>
        /// <example>
        ///   <para>
        ///   Define a fileset and check the number of files in it.
        ///   </para>
        ///   <code>
        ///     <![CDATA[
        /// <fileset id="test.fileset">
        ///     <include name="**/*.cs">
        /// </fileset>
        /// <echo message="FileSet contains ${fileset::get-file-count('test.fileset')} files." />
        /// ]]>
        ///   </code>
        /// </example>
        [Function("get-file-count")]
        public int GetFileCount(string fileset) {
            //Try to retrieve the specified fileset from the Data References on the project
            FileSet fs = base.Project.DataTypeReferences[fileset] as FileSet;
            //If the value was missing or the referenced type was not a fileset, then throw an exception
            if (fs == null) {
                throw new ArgumentException(string.Format("'{0}' is not a valid fileset reference", fileset));
            }
            //Otherwise return the number of files in the fileset.
            return fs.FileNames.Count;
        }

        /// <summary>
        /// Determines whether <see cref="FileSet"/> contains any files.
        /// </summary>
        /// <param name="fileset">The id of the fileset to check.</param>
        /// <returns><see langword="true" /> if the FileSet contains one or more files, otherwise <see langword="false"/>.</returns>
        /// <exception cref="ArgumentException"><paramref name="fileset" /> is not a valid refid to a defined fileset.</exception>
        /// <example>
        ///   <para>
        ///   Perform conditional processing on a fileset if it contains files.
        ///   </para>
        ///   <code>
        ///     <![CDATA[
        /// <fileset id="test.fileset">
        ///     <include name="**/*.cs">
        /// </fileset>
        /// <if test="${fileset::has-files('test.fileset')}">
        ///     <dostuff... />
        /// </if>
        /// ]]>
        ///   </code>
        /// </example>
        [Function("has-files")]
        public bool HasFiles(string fileset) {
            //Try to retrieve the specified fileset from the Data References on the project
            FileSet fs = base.Project.DataTypeReferences[fileset] as FileSet;
            //If the value was missing or the referenced type was not a fileset, then throw an exception
            if (fs == null) {
                throw new ArgumentException(string.Format("'{0}' is not a valid fileset reference", fileset));
            }
            //Otherwise return whether or not the fileset contains files.
            return (fs.FileNames.Count > 0);
        }
        /// <summary>
        /// Returns a delimited string of all the filenames within a <see cref="FileSet"/> with each filename
        /// separated by the specified delimiter string.
        /// </summary>
        /// <param name="fileset">The id of the fileset to check.</param>
        /// <param name="delimiter">String to separate filenames with.</param>
        /// <returns>A delimited string of the filenames within the specified FileSet.</returns>
        /// <exception cref="ArgumentException"><paramref name="fileset" /> is not a valid refid to a defined fileset.</exception>
        /// <example>
        ///   <para>
        ///   Displays a space-pipe-space separated string fo the files within a defined FileSet.
        ///   </para>
        ///   <code>
        ///     <![CDATA[
        /// <fileset id="test.fileset">
        ///     <include name="**/*.cs">
        /// </fileset>
        /// <echo message="${fileset::to-string('test.fileset', ' | ')}">
        /// ]]>
        ///   </code>
        /// </example>
        [Function("to-string")]
        public string ToString(string fileset, string delimiter){
            //Try to retrieve the specified fileset from the Data References on the project
            FileSet fs = base.Project.DataTypeReferences[fileset] as FileSet;
            
            //If the value was missing or the referenced type was not a fileset, then throw an exception
            if (fs == null){
                throw new ArgumentException(string.Format("'{0}' is not a valid fileset reference", fileset));
            }

            //We've got a valid fileset.  Use a stringbuilder to build the delimiter separated list.
            StringBuilder sb = new StringBuilder();

            //This is a loop as we need to omit the delimiter on the last element, and it's easier 
            //to check the last element with a for loop than in a foreach loop.
            for (int i = 0; i < fs.FileNames.Count; i++){
                string file = fs.FileNames[i];
                sb.Append(file);
                //if this is not the last element, then append the delimiter
                if (i < fs.FileNames.Count - 1){
                    sb.Append(delimiter);
                }
            }
            //Now return the string representation of the FileSet.
            return sb.ToString();
        }
        #endregion Public Instance Methods
    }
}
{'fraction_non_alphanumeric': 0.1232289662410355, 'fraction_numerical': 0.004810215147804792, 'mean_word_length': 1.9267980547734835, 'pattern_counts': {'":': 0, '<': 129, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5981239', 'n_tokens_mistral': 3004, 'n_tokens_neox': 2912, 'n_words': 1107}