Candor.WindowsAzure.Storage.Blob.CloudBlobRules.GetValidBlobName C# (CSharp) Method

GetValidBlobName() public static method

Gets a valid blob name by removing excess slashes and dots. If the name is still invalid, then an exception occurs. See remarks for naming rules.
A blob name can contain any combination of characters, but reserved URL characters must be properly escaped. A blob name must be at least one character long and cannot be more than 1,024 characters long. Blob names are case-sensitive. Avoid names the end with a dot (.), o forward slash (/), or a sequence or combination of the two.
public static GetValidBlobName ( this name, bool strict = false ) : String
name this
strict bool Specifies if an exception is thrown if the cleaned up name would need url encoding to be stored.
return String
        public static String GetValidBlobName(this String name, bool strict = false)
        {
            var cleanupAttempt = CompiledExpressions.RepeatingSlashDotReplaceRegex.Replace(
                CompiledExpressions.RepeatingDotSlashReplaceRegex.Replace(name,
                                                                          "."),
                "/");
            if (cleanupAttempt.EndsWith(".") || cleanupAttempt.EndsWith("/"))
                cleanupAttempt = cleanupAttempt.Substring(0, cleanupAttempt.Length - 1);

            if (strict && !CompiledExpressions.AzureBlobNameValidationRegex.IsMatch(cleanupAttempt))
                throw new ArgumentException("Cannot verify a valid blob name for the supplied string.");

            return cleanupAttempt;
        }