1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2007-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 // required includes
\r
23 #include "DictionaryBasedTempPath.h"
\r
24 #include "NodeClassification.h"
\r
27 * Efficiently classifies a path as "trunk", "branches" or "tags".
\r
28 * For every class, a list of wild card patterns separated by semicolon
\r
29 * can be specified. Example "tags;qa ?;qa ?.*". String comparison
\r
30 * is case-insensitive for latin chars ('a' .. 'z').
\r
31 * A given path may be assigned to multiple classes.
\r
34 class CPathClassificator
\r
38 class CWildCardPattern
\r
42 /// pattern to match against
\r
44 std::string pattern;
\r
46 /// algorithm selection
\r
50 /// different matching algorithms
\r
52 bool WildCardMatch (const char* s, const char* pattern) const;
\r
53 bool StraightMatch (const char* s, size_t length) const;
\r
55 /// construction utility
\r
57 void NormalizePattern();
\r
63 CWildCardPattern (const std::string& pattern);
\r
65 /// match s against the pattern
\r
67 bool Match (const char* s, size_t length) const;
\r
70 /// the patterns to detect trunk, branches and tags
\r
72 typedef std::vector<CWildCardPattern> TPatterns;
\r
74 TPatterns trunkPatterns;
\r
75 TPatterns branchesPatterns;
\r
76 TPatterns tagsPatterns;
\r
78 /// path classification
\r
80 std::vector<unsigned char> pathElementClassification;
\r
81 std::vector<unsigned char> pathClassification;
\r
83 /// construction utilities
\r
85 TPatterns ParsePatterns (const std::string& patterns) const;
\r
87 bool Matches ( TPatterns::const_iterator firstPattern
\r
88 , TPatterns::const_iterator lastPattern
\r
89 , const char* element
\r
90 , size_t length) const;
\r
91 void ClassifyPathElements ( const LogCache::CStringDictionary& elements
\r
92 , const TPatterns& patterns
\r
93 , unsigned char classification);
\r
94 void ClassifyPathElements (const LogCache::CStringDictionary& elements);
\r
95 void ClassifyPaths (const LogCache::CPathDictionary& paths);
\r
99 /// construction / destruction
\r
101 CPathClassificator ( const LogCache::CPathDictionary& paths
\r
102 , const std::string& trunkPatterns = "trunk"
\r
103 , const std::string& branchesPatterns = "branches"
\r
104 , const std::string& tagsPatterns = "tags");
\r
105 ~CPathClassificator(void);
\r
107 /// get the classification for a given path
\r
109 unsigned char GetClassification (const LogCache::index_t pathID) const;
\r
110 unsigned char operator[](const LogCache::CDictionaryBasedPath& path) const;
\r
112 unsigned char GetClassification (const LogCache::CDictionaryBasedTempPath& path) const;
\r
113 unsigned char operator[](const LogCache::CDictionaryBasedTempPath& path) const;
\r
116 /// get the classification for a given path
\r
118 inline unsigned char
\r
119 CPathClassificator::GetClassification (const LogCache::index_t pathID) const
\r
121 return pathClassification[pathID];
\r
124 inline unsigned char
\r
125 CPathClassificator::operator[](const LogCache::CDictionaryBasedPath& path) const
\r
127 return GetClassification (path.GetIndex());
\r
130 inline unsigned char
\r
131 CPathClassificator::operator[](const LogCache::CDictionaryBasedTempPath& path) const
\r
133 return GetClassification (path);
\r