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