other-licenses/7zstub/src/Common/Wildcard.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 // Common/Wildcard.h
     3 #ifndef __COMMON_WILDCARD_H
     4 #define __COMMON_WILDCARD_H
     6 #include "Common/String.h"
     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);
    15 namespace NWildcard {
    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 };
    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;
    40   int FindSubNode(const UString &path) const;
    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);
    46   bool NeedCheckSubDirs() const;
    47   bool AreThereIncludeItems() const;
    49   bool CheckPath(const UString &path, bool isFile, bool &include) const;
    50   bool CheckPath(const UString &path, bool isFile) const;
    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 };
    57 struct CPair
    58 {
    59   UString Prefix;
    60   CCensorNode Head;
    61   CPair(const UString &prefix): Prefix(prefix) { };
    62 };
    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 };
    76 }
    78 #endif

mercurial