|
1 // Common/Wildcard.h |
|
2 |
|
3 #ifndef __COMMON_WILDCARD_H |
|
4 #define __COMMON_WILDCARD_H |
|
5 |
|
6 #include "Common/String.h" |
|
7 |
|
8 void SplitPathToParts(const UString &path, UStringVector &pathParts); |
|
9 void SplitPathToParts(const UString &path, UString &dirPrefix, UString &name); |
|
10 UString ExtractDirPrefixFromPath(const UString &path); |
|
11 UString ExtractFileNameFromPath(const UString &path); |
|
12 bool DoesNameContainWildCard(const UString &path); |
|
13 bool CompareWildCardWithName(const UString &mask, const UString &name); |
|
14 |
|
15 namespace NWildcard { |
|
16 |
|
17 struct CItem |
|
18 { |
|
19 UStringVector PathParts; |
|
20 bool Recursive; |
|
21 bool ForFile; |
|
22 bool ForDir; |
|
23 bool CheckPath(const UStringVector &pathParts, bool isFile) const; |
|
24 }; |
|
25 |
|
26 class CCensorNode |
|
27 { |
|
28 CCensorNode *Parent; |
|
29 bool CheckPathCurrent(bool include, const UStringVector &pathParts, bool isFile) const; |
|
30 void AddItemSimple(bool include, CItem &item); |
|
31 bool CheckPath(UStringVector &pathParts, bool isFile, bool &include) const; |
|
32 public: |
|
33 CCensorNode(): Parent(0) { }; |
|
34 CCensorNode(const UString &name, CCensorNode *parent): Name(name), Parent(parent) { }; |
|
35 UString Name; |
|
36 CObjectVector<CCensorNode> SubNodes; |
|
37 CObjectVector<CItem> IncludeItems; |
|
38 CObjectVector<CItem> ExcludeItems; |
|
39 |
|
40 int FindSubNode(const UString &path) const; |
|
41 |
|
42 void AddItem(bool include, CItem &item); |
|
43 void AddItem(bool include, const UString &path, bool recursive, bool forFile, bool forDir); |
|
44 void AddItem2(bool include, const UString &path, bool recursive); |
|
45 |
|
46 bool NeedCheckSubDirs() const; |
|
47 bool AreThereIncludeItems() const; |
|
48 |
|
49 bool CheckPath(const UString &path, bool isFile, bool &include) const; |
|
50 bool CheckPath(const UString &path, bool isFile) const; |
|
51 |
|
52 bool CheckPathToRoot(bool include, UStringVector &pathParts, bool isFile) const; |
|
53 // bool CheckPathToRoot(const UString &path, bool isFile, bool include) const; |
|
54 void ExtendExclude(const CCensorNode &fromNodes); |
|
55 }; |
|
56 |
|
57 struct CPair |
|
58 { |
|
59 UString Prefix; |
|
60 CCensorNode Head; |
|
61 CPair(const UString &prefix): Prefix(prefix) { }; |
|
62 }; |
|
63 |
|
64 class CCensor |
|
65 { |
|
66 int FindPrefix(const UString &prefix) const; |
|
67 public: |
|
68 CObjectVector<CPair> Pairs; |
|
69 bool AllAreRelative() const |
|
70 { return (Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty()); } |
|
71 void AddItem(bool include, const UString &path, bool recursive); |
|
72 bool CheckPath(const UString &path, bool isFile) const; |
|
73 void ExtendExclude(); |
|
74 }; |
|
75 |
|
76 } |
|
77 |
|
78 #endif |