mirror of
https://github.com/jcreek/Creek.FileRepository.git
synced 2026-07-13 02:43:43 +00:00
feat(*): Add documentation to StringHelper
This commit is contained in:
@@ -4,8 +4,16 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Creek.FileRepository.Helpers
|
namespace Creek.FileRepository.Helpers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A helper class for string methods.
|
||||||
|
/// </summary>
|
||||||
internal class StringHelper
|
internal class StringHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if a filename contains invalid characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">The filename to be checked.</param>
|
||||||
|
/// <returns>Returns true if the filename contains invalid characters.</returns>
|
||||||
public static bool IsInvalidFileName(string filename)
|
public static bool IsInvalidFileName(string filename)
|
||||||
{
|
{
|
||||||
char[] invalidCharacters = new char[] { '<', '>', ':', '\'', '/', '\\', '|', '?', '*' };
|
char[] invalidCharacters = new char[] { '<', '>', ':', '\'', '/', '\\', '|', '?', '*' };
|
||||||
@@ -13,10 +21,15 @@ namespace Creek.FileRepository.Helpers
|
|||||||
return Array.Exists(invalidCharacters, character => filename.Contains(character.ToString()));
|
return Array.Exists(invalidCharacters, character => filename.Contains(character.ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sanitises a filename containing invalid characters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="originalFileName">The filename to sanitise.</param>
|
||||||
|
/// <returns>Returns the sanitised filename.</returns>
|
||||||
internal static string MakeValidFileName(string originalFileName)
|
internal static string MakeValidFileName(string originalFileName)
|
||||||
{
|
{
|
||||||
char[] invalids = System.IO.Path.GetInvalidFileNameChars();
|
char[] invalids = System.IO.Path.GetInvalidFileNameChars();
|
||||||
string validFileName = String.Join("_", originalFileName.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
string validFileName = string.Join("_", originalFileName.Split(invalids, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
|
||||||
|
|
||||||
// Additionally remove Windows characters explicitly, in case we're running on Linux (e.g. in Docker) but need to access the files in Windows
|
// Additionally remove Windows characters explicitly, in case we're running on Linux (e.g. in Docker) but need to access the files in Windows
|
||||||
string[] charsToRemove = new string[] { "<", ">", ":", "\"", "/", "\\", "|", "?", "*" };
|
string[] charsToRemove = new string[] { "<", ">", ":", "\"", "/", "\\", "|", "?", "*" };
|
||||||
@@ -26,6 +39,12 @@ namespace Creek.FileRepository.Helpers
|
|||||||
return validFileName;
|
return validFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes any characters in an array of strings from a string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="charsToRemove">The string array of characters to remove.</param>
|
||||||
|
/// <param name="str">The string to modify.</param>
|
||||||
|
/// <returns>Returns the modified string.</returns>
|
||||||
internal static string RemoveCharsFromString(string[] charsToRemove, string str)
|
internal static string RemoveCharsFromString(string[] charsToRemove, string str)
|
||||||
{
|
{
|
||||||
foreach (string c in charsToRemove)
|
foreach (string c in charsToRemove)
|
||||||
|
|||||||
Reference in New Issue
Block a user