Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Produce a version of the given name that can be used as a file name. This is done
        /// by replacing invalid characters with underscores '_'.
        /// </summary>
        /// <param name="sName">Name to be filtered</param>
        /// <param name="invalidChars">characters to filter out</param>
        /// <param name="strength">strength of the filter (<c>kFilterProjName</c> will also remove all non-ASCII characters)</param>
        /// <returns>the filtered name</returns>
        /// ------------------------------------------------------------------------------------
        public static string FilterForFileName(string sName, string invalidChars,
                                               MiscUtils.FilenameFilterStrength strength = MiscUtils.FilenameFilterStrength.kFilterBackup)
        {
            StringBuilder cleanName = new StringBuilder(sName);

            // replace all invalid characters with an '_'
            for (int i = 0; i < sName.Length; i++)
            {
                if (invalidChars.IndexOf(sName[i]) >= 0 || sName[i] < ' ')                 // eliminate all control characters too
                {
                    cleanName[i] = '_';
                }
                else if (strength == MiscUtils.FilenameFilterStrength.kFilterProjName && sName[i] > '~')
                {
                    cleanName[i] = '_';
                }
            }
            return(cleanName.ToString());
        }
Example #2
0
 public string FilterForFileName(string filter, MiscUtils.FilenameFilterStrength strength)
 {
     return(MiscUtils.FilterForFileName(filter, strength));
 }