static public string ApplyCaseComparison(string path, PathCaseComparison caseComparison) { if (path == null) { throw new ArgumentNullException(); } switch (caseComparison) { case PathCaseComparison.EnvironmentDefault: if (IsEnvironmentCaseSensitive()) { goto default; } else { goto case PathCaseComparison.IgnoreCase; } case PathCaseComparison.IgnoreCase: return(path.ToLowerInvariant()); default: return(path); } }
static public bool Equals(string first, string second, PathCaseComparison caseComparison, FolderPathEquality folderEquality) { if (first == null && second == null) { return(true); } if (first == null ^ second == null) { return(false); } return(string.Equals(ApplyFolderEquality(PathUtils.Normalize(first), folderEquality), ApplyFolderEquality(PathUtils.Normalize(second), folderEquality), GetStringComparison(caseComparison))); }
static public string UniqueFile(string path, PathCaseComparison caseComparison) { if (!IsValidPath(path)) { throw new ArgumentException(); } if (IsExplicitFolderPath(path)) { throw new ArgumentException(); } // Normalize path = Normalize(path); // Change case if necessary return(PathComparer.ApplyCaseComparison(Normalize(path), caseComparison)); }
static public int Compare(string first, string second, PathCaseComparison caseComparison, FolderPathEquality folderEquality) { if (first == null && second == null) { return(0); } if (first == null) { return(-1); } if (second == null) { return(1); } return(string.Compare(ApplyFolderEquality(PathUtils.Normalize(first), folderEquality), ApplyFolderEquality(PathUtils.Normalize(second), folderEquality), GetStringComparison(caseComparison))); }
static public StringComparison GetStringComparison(PathCaseComparison caseComparison) { switch (caseComparison) { case PathCaseComparison.EnvironmentDefault: return(IsEnvironmentCaseSensitive() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); case PathCaseComparison.RespectCase: return(StringComparison.Ordinal); case PathCaseComparison.IgnoreCase: return(StringComparison.OrdinalIgnoreCase); default: throw new NotSupportedException(); } }
static public string UniqueFolder(string path, PathCaseComparison caseComparison) { if (!IsValidPath(path)) { throw new ArgumentException(); } // Normalize path = Normalize(path, out char separator); // Change case if necessary path = PathComparer.ApplyCaseComparison(path, caseComparison); // Add end separator if (!IsExplicitFolderPath(path, separator)) { path += separator; } return(path); }
public PathHandlersBase(string uniquePath, SharedWatcher sharedWatcher, bool subscribeToChanged) { UniquePath = uniquePath; PathPattern = new PathPattern(uniquePath, sharedWatcher.FileSystem.PathsCaseSensitive); SharedWatcher = sharedWatcher; _subscribeToChanged = subscribeToChanged; SharedWatcher.Increment(); SharedWatcher.FolderCreated += OnParentFolderCreated; SharedWatcher.FolderDeleted += OnParentFolderDeleted; PathCaseComparison caseComparison = sharedWatcher.FileSystem.PathsCaseSensitive ? PathCaseComparison.RespectCase : PathCaseComparison.IgnoreCase; var existingPathComparer = new PathComparer(caseComparison, FolderPathEquality.RespectAmbiguity); _matchingPaths = new ConcurrentDictionary <string, bool>(existingPathComparer); RefreshExistingMatchingPaths(); SubscribeToWatcher(); }
static private bool MatchSimplePath(string path, string pattern, bool caseSensitive = true) { PathCaseComparison pathCaseComparison = caseSensitive ? PathCaseComparison.RespectCase : PathCaseComparison.IgnoreCase; return(PathComparer.Equals(path, pattern, pathCaseComparison, FolderPathEquality.RespectAmbiguity)); }
public PathComparer(PathCaseComparison caseComparison, FolderPathEquality folderEquality) { CaseComparison = caseComparison; FolderEquality = folderEquality; }