00001
00002
00003
00004
00005 #ifndef __COMMON_WILDCARD_H
00006 #define __COMMON_WILDCARD_H
00007
00008 #include "String.h"
00009
00010 void SplitPathToParts(const UString &path, UStringVector &pathParts);
00011 void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name);
00012 UString ExtractDirPrefixFromPath(const UString &path);
00013 UString ExtractFileNameFromPath(const UString &path);
00014 bool DoesNameContainWildCard(const UString &path);
00015 bool CompareWildCardWithName(const UString &mask, const UString &name);
00016
00017 namespace NWildcard {
00018
00019 struct CItem
00020 {
00021 UStringVector PathParts;
00022 bool Recursive;
00023 bool ForFile;
00024 bool ForDir;
00025 bool CheckPath(const UStringVector &pathParts, bool isFile) const;
00026 };
00027
00028 class CCensorNode
00029 {
00030 CCensorNode *Parent;
00031 bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const;
00032 void AddItemSimple(bool include, CItem &item);
00033 bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const;
00034 public:
00035 CCensorNode(): Parent(0) { };
00036 CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { };
00037 UString Name;
00038 CObjectVector<CCensorNode> SubNodes;
00039 CObjectVector<CItem> IncludeItems;
00040 CObjectVector<CItem> ExcludeItems;
00041
00042 int FindSubNode(const UString &path) const;
00043
00044 void AddItem(bool include, CItem &item);
00045 void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir);
00046 void AddItem2(bool include, const UString &path, bool recursive);
00047
00048 bool NeedCheckSubDirs() const;
00049 bool AreThereIncludeItems() const;
00050
00051 bool CheckPath(const UString &path, bool isFile, bool &include) const;
00052 bool CheckPath(const UString &path, bool isFile) const;
00053
00054 bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const;
00055
00056 };
00057
00058 struct CPair
00059 {
00060 UString Prefix;
00061 CCensorNode Head;
00062 CPair(const UString &prefix): Prefix(prefix) { };
00063 };
00064
00065 class CCensor
00066 {
00067 int FindPrefix(const UString &prefix) const;
00068 public:
00069 CObjectVector<CPair> Pairs;
00070 bool AllAreRelative() const
00071 { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); }
00072 void AddItem(bool include, const UString &path, bool recursive);
00073 bool CheckPath(const UString &path, bool isFile) const;
00074 };
00075
00076 }
00077
00078 bool AreTheFileNamesDirDelimiterEqual(const UString &name1, const UString &name2);
00079
00080 #endif