Example #1
0
        /// <summary>
        /// Determines if a path segment contains a Windows directory separator.
        /// </summary>
        public static bool ContainsMixedDirectorySeparator(string pathSegment)
        {
            var output = DirectorySeparatorGood.ContainsWindowsDirectorySeparator(pathSegment) &&
                         DirectorySeparatorGood.ContainsNonWindowsDirectorySeparator(pathSegment);

            return(output);
        }
Example #2
0
        /// <summary>
        /// Between the Windows ('\') and the non-Windows ('/') directory separator, given one, return the other.
        /// Checked - Validates the directory separator first.
        /// </summary>
        public static string GetAlternateDirectorySeparator(string directorySeparator)
        {
            DirectorySeparatorGood.Validate(directorySeparator);

            var alternateDirectorySeparator = DirectorySeparatorGood.GetAlternateDirectorySeparatorUnchecked(directorySeparator);

            return(alternateDirectorySeparator);
        }
Example #3
0
        /// <summary>
        /// Determines if the specified directory separator is detected for the path segment.
        /// The input directory separator is validated.
        /// </summary>
        public static bool IsDirectorySeparatorDetected(string pathSegment, string directorySeparator)
        {
            DirectorySeparatorGood.Validate(directorySeparator);

            var isDetected = DirectorySeparatorGood.IsDirectorySeparatorDetectedUnchecked(pathSegment, directorySeparator);

            return(isDetected);
        }
Example #4
0
        /// <summary>
        /// Determine if the non-Windows directory separator is detected in a path segment, but if no directory separator is detected, assume the non-Windows directory separator was detected (return true).
        /// </summary>
        public static bool IsNonWindowsDirectorySeparatorDetectedAssumeNonWindows(string pathSegment)
        {
            var directorySeparator = DirectorySeparatorGood.DetectDirectorySeparatorOrDefaultNonWindows(pathSegment);

            var isNonWindows = DirectorySeparatorGood.IsNonWindowsDirectorySeparator(directorySeparator);

            return(isNonWindows);
        }
Example #5
0
 /// <summary>
 /// Checks that the specified directory separator argument is actually a directory separator, and throws an exception if it is not.
 /// </summary>
 /// <exception cref="ArgumentException">Thrown if the <paramref name="directorySeparator"/> is not a valid directory separator according to <see cref="DirectorySeparatorGood.IsValid(string)"/>.</exception>
 public static void Validate(string directorySeparator, string argumentName)
 {
     if (!DirectorySeparatorGood.IsValid(directorySeparator))
     {
         var exception = DirectorySeparatorGood.GetInvalidDirectorySeparatorValueArgumentException(directorySeparator, argumentName);
         throw exception;
     }
 }
Example #6
0
        /// <summary>
        /// Determines if a path segment contains a specified directory separator.
        /// Detecting the use of a directory-separator by a path-segment requires an extra step beyond just determining if the path-segment contains the directory-separator.
        /// A path-segment can contain both Windows and non-Windows directory-separators, in which case the first directory-separator is the detected directory-separator because it is dominant.
        /// Validation is performed on the directory separator.
        /// </summary>
        public static bool ContainsDirectorySeparator(string pathSegment, string directorySeparator)
        {
            DirectorySeparatorGood.Validate(directorySeparator);

            var output = DirectorySeparatorGood.ContainsDirectorySeparatorUnchecked(pathSegment, directorySeparator);

            return(output);
        }
Example #7
0
        public static Exception GetInvalidDirectorySeparatorValueException(string found)
        {
            var message = DirectorySeparatorGood.GetInvalidDirectorySeparatorValueExceptionMessage(found);

            var exception = new Exception(message);

            return(exception);
        }
Example #8
0
        public static ArgumentException GetNonWindowsDirectorySeparatorValueExpectedArgumentException(string found, string parameterName)
        {
            var message = DirectorySeparatorGood.GetNonWindowsDirectorySeparatorValueExpectedExceptionMessage(found);

            var exception = new ArgumentException(message, parameterName);

            return(exception);
        }
Example #9
0
        public static Exception GetNonWindowsDirectorySeparatorValueExpectedException(string notNonWindowsDirectorySeparator)
        {
            var message = DirectorySeparatorGood.GetNonWindowsDirectorySeparatorValueExpectedExceptionMessage(notNonWindowsDirectorySeparator);

            var exception = new Exception(message);

            return(exception);
        }
Example #10
0
        /// <summary>
        /// Checks that the specified directory separator is actually a directory separator, and throws an exception if it is not.
        /// </summary>
        /// <exception cref="Exception">Thrown if the <paramref name="directorySeparator"/> is not a valid directory separator according to <see cref="DirectorySeparatorGood.IsValid(string)"/>.</exception>
        public static void Validate(string directorySeparator)
        {
            var isValid = DirectorySeparatorGood.IsValid(directorySeparator);

            if (!isValid)
            {
                var exception = DirectorySeparatorGood.GetInvalidDirectorySeparatorValueException(directorySeparator);
                throw exception;
            }
        }
Example #11
0
        /// <summary>
        /// Detects the directory separator used in a path segment.
        /// If no directory separator can be detected, throws an exception.
        /// </summary>
        /// <exception cref="Exception">Thrown when a path segment a directory separator cannot be detected (i.e. contains no directory separators).</exception>
        public static string DetectDirectorySeparator(string pathSegment)
        {
            var detectionSuccess = DirectorySeparatorGood.TryDetectDirectorySeparator(pathSegment, out var directorySeparator);

            if (!detectionSuccess)
            {
                throw new Exception($@"Unable to detect platform for path '{pathSegment}'.");
            }

            return(directorySeparator);
        }
Example #12
0
        public static void ValidateWindows(string windowsDirectorySeparator)
        {
            DirectorySeparatorGood.Validate(windowsDirectorySeparator);

            var isWindows = DirectorySeparatorGood.IsWindowsDirectorySeparator(windowsDirectorySeparator);

            if (!isWindows)
            {
                var exception = DirectorySeparatorGood.GetWindowsDirectorySeparatorValueExpectedException(windowsDirectorySeparator);
                throw exception;
            }
        }
Example #13
0
        /// <summary>
        /// Determines if the specified directory separator is detected for the path segment.
        /// Unchecked - No validation is performed on the input directory separator.
        /// </summary>
        public static bool IsDirectorySeparatorDetectedUnchecked(string pathSegment, string directorySeparator)
        {
            var isAnySeparatorDetected = DirectorySeparatorGood.TryDetectDirectorySeparatorOrInvalid(pathSegment, out var outDirectorySeparator);

            if (isAnySeparatorDetected)
            {
                var isDetected = directorySeparator == outDirectorySeparator;
                return(isDetected);
            }

            return(false);
        }
Example #14
0
        public static void ValidateNonWindows(string nonWindowsDirectorySeparator, string argumentName)
        {
            DirectorySeparatorGood.Validate(nonWindowsDirectorySeparator);

            var isWindows = DirectorySeparatorGood.IsNonWindowsDirectorySeparator(nonWindowsDirectorySeparator);

            if (!isWindows)
            {
                var exception = DirectorySeparatorGood.GetNonWindowsDirectorySeparatorValueExpectedArgumentException(nonWindowsDirectorySeparator, argumentName);
                throw exception;
            }
        }
Example #15
0
        /// <summary>
        /// Determines if a string is a valid directory separator.
        /// Checks that specified directory separator is not the <see cref="DirectorySeparatorGood.InvalidValue"/>, then if it is one of the Windows of non-Windows directory separators.
        /// </summary>
        public static bool IsValid(string directorySeparator)
        {
            var isInvalid = DirectorySeparatorGood.IsInvalid(directorySeparator);

            if (isInvalid)
            {
                return(false);
            }

            var output = DirectorySeparatorGood.IsDirectorySeparator(directorySeparator);

            return(output);
        }
Example #16
0
        /// <summary>
        /// Between the Windows ('\') and the non-Windows ('/') directory separator, given one, return the other.
        /// Unchecked - If the input directory separator is neither the Windows nor non-Windows separator, the Windows separator is returned.
        /// </summary>
        public static string GetAlternateDirectorySeparatorUnchecked(string directorySeparator)
        {
            var isWindows = DirectorySeparatorGood.IsWindowsDirectorySeparator(directorySeparator);

            if (isWindows)
            {
                return(DirectorySeparatorGood.NonWindowsValue);
            }
            else
            {
                return(DirectorySeparatorGood.WindowsValue);
            }
        }
Example #17
0
        /// <summary>
        /// Determines if the specified value equals the specified directory-separator, and if the specified directory separator is actually a directory separator.
        /// </summary>
        public static bool IsDirectorySeparator(char value, char possibleDirectorySeparator)
        {
            var areEqual = value == possibleDirectorySeparator;

            if (!areEqual)
            {
                return(false);
            }

            var isDirectorySeparator = DirectorySeparatorGood.IsDirectorySeparator(possibleDirectorySeparator);

            if (!isDirectorySeparator)
            {
                return(false);
            }

            return(true);
        }
Example #18
0
        /// <summary>
        /// Determines if a character is a valid directory-separator.
        /// Since there is no invalid directory separator character, this is identical to whether the specified character is one of the Windows of non-Windows directory separators.
        /// </summary>
        public static bool IsValid(char directorySeparator)
        {
            var isValid = DirectorySeparatorGood.IsDirectorySeparator(directorySeparator);

            return(isValid);
        }
Example #19
0
        /// <summary>
        /// Determines if a path segment contains a Windows directory separator.
        /// </summary>
        public static bool ContainsNonWindowsDirectorySeparator(string pathSegment)
        {
            var output = DirectorySeparatorGood.ContainsDirectorySeparatorUnchecked(pathSegment, DirectorySeparatorGood.NonWindowsValue);

            return(output);
        }
Example #20
0
        /// <summary>
        /// Determine if the non-Windows directory separator is detected in a path segment.
        /// </summary>
        public static bool IsNonWindowsDirectorySeparatorDetected(string pathSegment)
        {
            var isNonWindows = DirectorySeparatorGood.IsDirectorySeparatorDetectedUnchecked(pathSegment, DirectorySeparatorGood.NonWindowsValue);

            return(isNonWindows);
        }
Example #21
0
        /// <summary>
        /// Determines if any directory separator can be detected for a path segment.
        /// </summary>
        public static bool IsDirectorySeparatorDetected(string pathSegment)
        {
            var isAnySeparatorDetected = DirectorySeparatorGood.TryDetectDirectorySeparatorOrInvalid(pathSegment, out var _);

            return(isAnySeparatorDetected);
        }
Example #22
0
        /// <summary>
        /// Detects the directory separator used in a path segment, or if no directory separator can be detected, defaults to the non-Windows value.
        /// </summary>
        public static string DetectDirectorySeparatorOrDefaultNonWindows(string pathSegment)
        {
            var directorySeparator = DirectorySeparatorGood.DetectDirectorySeparatorOrDefault(pathSegment, DirectorySeparatorGood.NonWindowsValue);

            return(directorySeparator);
        }
Example #23
0
        public static bool IsNonWindowsDirectorySeparator(string directorySeparator)
        {
            var isWindows = DirectorySeparatorGood.IsDirectorySeparator(directorySeparator, DirectorySeparatorGood.NonWindowsValue);

            return(isWindows);
        }
Example #24
0
        /// <summary>
        /// Attempts to detect the directory separator (Windows or non-Windows) used within a path segment.
        /// Returns true if a directory separator can be detected, false otherwise.
        /// If no directory separator is detected, the output <paramref name="directorySeparator"/> is set to the <see cref="DirectorySeparatorGood.InvalidValue"/>.
        /// </summary>
        public static bool TryDetectDirectorySeparatorOrInvalid(string pathSegment, out string directorySeparator)
        {
            var output = DirectorySeparatorGood.TryDetectDirectorySeparator(pathSegment, out directorySeparator, DirectorySeparatorGood.InvalidValue);

            return(output);
        }
Example #25
0
        /// <summary>
        /// Attempts to detect the directory separator (Windows or non-Windows) used within a path segment, setting the output <paramref name="directorySeparator"/> to the <see cref="DirectorySeparatorGood.DefaultValue"/> if no directory separator can be detected.
        /// Returns true if a directory separator can be detected, false otherwise.
        /// </summary>
        public static bool TryDetectDirectorySeparator(string pathSegment, out string directorySeparator)
        {
            var output = DirectorySeparatorGood.TryDetectDirectorySeparatorOrDefault(pathSegment, out directorySeparator);

            return(output);
        }
Example #26
0
        /// <summary>
        /// Detects the directory separator used in a path segment.
        /// If a directory separator cannot be detected (for example, if the path segment is a file-name, or the un-directory-indicated relative path between parent a child directory, which is just the directory name), return the specified default.
        /// </summary>
        public static string DetectDirectorySeparatorOrDefault(string pathSegment, string defaultDirectorySeparator)
        {
            DirectorySeparatorGood.TryDetectDirectorySeparator(pathSegment, out var directorySeparator, defaultDirectorySeparator);

            return(directorySeparator);
        }
Example #27
0
        public static bool IsWindowsDirectorySeparator(char directorySeparator)
        {
            var isWindows = DirectorySeparatorGood.IsDirectorySeparator(directorySeparator, DirectorySeparatorGood.WindowsValueChar);

            return(isWindows);
        }