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