1 | #ifndef _theplu_svndigest_trac_ |
---|
2 | #define _theplu_svndigest_trac_ |
---|
3 | |
---|
4 | // $Id: Trac.h 768 2009-01-31 21:30:37Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2007, 2008, 2009 Peter Johansson |
---|
8 | |
---|
9 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
10 | |
---|
11 | svndigest is free software; you can redistribute it and/or modify it |
---|
12 | under the terms of the GNU General Public License as published by |
---|
13 | the Free Software Foundation; either version 3 of the License, or |
---|
14 | (at your option) any later version. |
---|
15 | |
---|
16 | svndigest is distributed in the hope that it will be useful, but |
---|
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU General Public License |
---|
22 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | */ |
---|
24 | |
---|
25 | #include <string> |
---|
26 | |
---|
27 | namespace theplu{ |
---|
28 | namespace svndigest{ |
---|
29 | |
---|
30 | class HtmlStream; |
---|
31 | |
---|
32 | /// |
---|
33 | /// Class responsible for filtering log messages and detect |
---|
34 | /// trac:links and create appropriate anchors. |
---|
35 | /// |
---|
36 | class Trac |
---|
37 | { |
---|
38 | public: |
---|
39 | /// |
---|
40 | /// \Constructor |
---|
41 | /// |
---|
42 | Trac(HtmlStream& html); |
---|
43 | |
---|
44 | /// |
---|
45 | /// |
---|
46 | /// |
---|
47 | void print(std::string str, size_t width); |
---|
48 | |
---|
49 | private: |
---|
50 | /** |
---|
51 | */ |
---|
52 | std::string anchor_text(std::string::const_iterator first, |
---|
53 | std::string::const_iterator last, |
---|
54 | std::string::const_iterator last_trunc); |
---|
55 | /// |
---|
56 | /// @see changeset1 changeset2 changeset3 |
---|
57 | /// |
---|
58 | /// @return true if any of changesetX returns true |
---|
59 | /// |
---|
60 | bool changeset(const std::string::const_iterator& first, |
---|
61 | std::string::const_iterator& iter, |
---|
62 | const std::string::const_iterator& last, |
---|
63 | const std::string::const_iterator& last_trunc); |
---|
64 | |
---|
65 | /// |
---|
66 | /// \brief search for 'r123' |
---|
67 | /// |
---|
68 | /// Search in range [\a first, \a last) for expression |
---|
69 | /// /r(\d+)/. In addition character before cannot be |
---|
70 | /// alpha-numeric, and character after expression cannot be |
---|
71 | /// alpha-numeric or ':' (beginning/end of string is allowed). If |
---|
72 | /// expression is found an anchor to trac-root/changeset/123, |
---|
73 | /// displaying expression, and first is pointing to character |
---|
74 | /// after expression. |
---|
75 | /// |
---|
76 | /// @return true if expression is found |
---|
77 | /// |
---|
78 | bool changeset1(const std::string::const_iterator& first, |
---|
79 | std::string::const_iterator& iter, |
---|
80 | const std::string::const_iterator& last, |
---|
81 | const std::string::const_iterator& last_trunc); |
---|
82 | |
---|
83 | /// |
---|
84 | /// \brief search for '[123]' |
---|
85 | /// |
---|
86 | /// Search in range [\a first, \a last) for expression |
---|
87 | /// /\[(\d+)\]/. If expression is found an anchor to |
---|
88 | /// trac-root/changeset/123, displaying expression, and first is |
---|
89 | /// pointing to character after expression. |
---|
90 | /// |
---|
91 | /// @return true if expression is found |
---|
92 | /// |
---|
93 | bool changeset2(std::string::const_iterator& first, |
---|
94 | const std::string::const_iterator& last, |
---|
95 | const std::string::const_iterator& last_trunc); |
---|
96 | |
---|
97 | /// |
---|
98 | /// \brief search for changeset:123 |
---|
99 | /// |
---|
100 | /// Search in range [\a first, \a last) for expression |
---|
101 | /// /changeset:(\d+)/. If expression is found an anchor to |
---|
102 | /// trac-root/changeset/123, displaying expression, and first is |
---|
103 | /// pointing to character after expression. |
---|
104 | /// |
---|
105 | /// @return true if expression is found |
---|
106 | /// |
---|
107 | bool changeset3(std::string::const_iterator& first, |
---|
108 | const std::string::const_iterator& last, |
---|
109 | const std::string::const_iterator& last_trunc); |
---|
110 | |
---|
111 | /// |
---|
112 | /// \brief search for /comment:ticket:123:1/ |
---|
113 | /// |
---|
114 | /// Search in range [\a first, \a last) for expression |
---|
115 | /// /comment:ticket:(\w+):(\d+)/. If expression is found an anchor |
---|
116 | /// to trac-root/ticket/123#comment:1, displaying expression, and |
---|
117 | /// first is pointing to character after expression. |
---|
118 | /// |
---|
119 | /// @return true if expression is found |
---|
120 | /// |
---|
121 | bool comment(std::string::const_iterator& first, |
---|
122 | const std::string::const_iterator& last, |
---|
123 | const std::string::const_iterator& last_trunc); |
---|
124 | |
---|
125 | /// |
---|
126 | /// @see diff1 diff2 diff3 |
---|
127 | /// |
---|
128 | /// @return true if any of diffX returns true |
---|
129 | /// |
---|
130 | bool diff(std::string::const_iterator& first, |
---|
131 | const std::string::const_iterator& last, |
---|
132 | const std::string::const_iterator& last_trunc); |
---|
133 | |
---|
134 | /// |
---|
135 | /// \brief search for diff:trunk@12:123 |
---|
136 | /// |
---|
137 | /// Search in range [\a first, \a last) for expression |
---|
138 | /// /diff:(.*)@(\w+):(\w+)/. If expression is found an anchor is |
---|
139 | /// created, displaying the expression, and first is pointing to |
---|
140 | /// character after expression. |
---|
141 | /// |
---|
142 | /// If $1 (trunk) is empty anchor goes to |
---|
143 | /// trac-root/changeset?new=123&old=12 otherwise it goes to |
---|
144 | /// trac-root/changeset?new=123&newpath=trunk&old=12&oldpath=trunk |
---|
145 | /// |
---|
146 | /// @return true if expression is found |
---|
147 | /// |
---|
148 | bool diff1(std::string::const_iterator& first, |
---|
149 | const std::string::const_iterator& last, |
---|
150 | const std::string::const_iterator& last_trunc); |
---|
151 | |
---|
152 | /// |
---|
153 | /// @brief search for diff:tags/1.0 or diff:tags/1.0//tags/1.0.1 |
---|
154 | /// |
---|
155 | /// Search in range [\a first, \a last) for expression |
---|
156 | /// /diff:(^\s+)/ or /diff:(^\s+)\/\/(^\s+)/. If expression is found |
---|
157 | /// an anchor is created, displaying the expression, and first is |
---|
158 | /// pointing to character after expression. |
---|
159 | /// |
---|
160 | /// The created anchor goes to |
---|
161 | /// trac-root/changeset?new_path=tags/1.0&old_path=tags/1.0 or |
---|
162 | /// trac-root/changeset?new_path=tags/1.0&old_path=tags/1.0.1 |
---|
163 | /// respectively. |
---|
164 | /// |
---|
165 | /// @return true if expression is found |
---|
166 | /// |
---|
167 | bool diff2(std::string::const_iterator& first, |
---|
168 | const std::string::const_iterator& last, |
---|
169 | const std::string::const_iterator& last_trunc); |
---|
170 | |
---|
171 | /// |
---|
172 | /// @brief search for diff:tags/1.0@123//trunk@236 |
---|
173 | /// |
---|
174 | /// Search in range [\a first, \a last) for expression |
---|
175 | /// /diff:(^\s+)@(\w+)\/\/(^\s+)@(\w+)/. If expression is found an |
---|
176 | /// anchor is created, displaying the expression, and first is |
---|
177 | /// pointing to character after expression. |
---|
178 | /// |
---|
179 | /// The created anchor goes to |
---|
180 | /// trac-root/changeset?new=236&new_path=trunk&old=123&old_path=tags/1.0 |
---|
181 | /// |
---|
182 | /// @return true if expression is found |
---|
183 | /// |
---|
184 | bool diff3(std::string::const_iterator& first, |
---|
185 | const std::string::const_iterator& last, |
---|
186 | const std::string::const_iterator& last_trunc); |
---|
187 | |
---|
188 | |
---|
189 | /// |
---|
190 | /// @see log1 log2 log3 |
---|
191 | /// |
---|
192 | /// @return true if any of logX returns true |
---|
193 | /// |
---|
194 | bool log(const std::string::const_iterator& first, |
---|
195 | std::string::const_iterator& iter, |
---|
196 | const std::string::const_iterator& last, |
---|
197 | const std::string::const_iterator& last_trunc); |
---|
198 | |
---|
199 | /// |
---|
200 | /// @brief search for r123:236 |
---|
201 | /// |
---|
202 | /// Search in range [\a first, \a last) for expression |
---|
203 | /// /r(\d+):(\d+)/. In addition character before and after |
---|
204 | /// expression cannot be alpha-numeric (beginning/end of string is |
---|
205 | /// allowed). If expression is found an anchor is created, |
---|
206 | /// displaying the expression, and iter is pointing to character |
---|
207 | /// after expression. |
---|
208 | /// |
---|
209 | /// The created anchor goes to trac-root/log/?rev=236&stop_rev=123 |
---|
210 | /// |
---|
211 | /// @return true if expression is found |
---|
212 | /// |
---|
213 | bool log1(const std::string::const_iterator& first, |
---|
214 | std::string::const_iterator& iter, |
---|
215 | const std::string::const_iterator& last, |
---|
216 | const std::string::const_iterator& last_trunc); |
---|
217 | |
---|
218 | /// |
---|
219 | /// @brief search for [123:236] |
---|
220 | /// |
---|
221 | /// Search in range [\a first, \a last) for expression |
---|
222 | /// /\[(\w+):(\w+)\]/. If expression is found an |
---|
223 | /// anchor is created, displaying the expression, and first is |
---|
224 | /// pointing to character after expression. |
---|
225 | /// |
---|
226 | /// The created anchor goes to trac-root/log/?rev=236&stop_rev=123 |
---|
227 | /// |
---|
228 | /// @return true if expression is found |
---|
229 | /// |
---|
230 | bool log2(std::string::const_iterator& first, |
---|
231 | const std::string::const_iterator& last, |
---|
232 | const std::string::const_iterator& last_trunc); |
---|
233 | |
---|
234 | /// |
---|
235 | /// @brief search for log:trunk@123:236 or log:trunk#123:236 |
---|
236 | /// |
---|
237 | /// Search in range [\a first, \a last) for expression |
---|
238 | /// /log:(^\s*)(@|#)(\w+):(\w+)/. If expression is found an |
---|
239 | /// anchor is created, displaying the expression, and first is |
---|
240 | /// pointing to character after expression. |
---|
241 | /// |
---|
242 | /// The created anchor goes to trac-root/log/trunk?rev=236&stop_rev=123 |
---|
243 | /// |
---|
244 | /// @return true if expression is found |
---|
245 | /// |
---|
246 | bool log3(std::string::const_iterator& first, |
---|
247 | const std::string::const_iterator& last, |
---|
248 | const std::string::const_iterator& last_trunc); |
---|
249 | |
---|
250 | /// |
---|
251 | /// @brief search for milestone:1.0 |
---|
252 | /// |
---|
253 | /// Search in range [\a first, \a last) for expression |
---|
254 | /// /milestone:(^s\*)\w/. If expression is found an |
---|
255 | /// anchor is created, displaying the expression, and first is |
---|
256 | /// pointing to character after expression. |
---|
257 | /// |
---|
258 | /// The created anchor goes to trac-root/milestone/1.0 |
---|
259 | /// |
---|
260 | /// @return true if expression is found |
---|
261 | /// |
---|
262 | bool milestone(std::string::const_iterator& first, |
---|
263 | const std::string::const_iterator& last, |
---|
264 | const std::string::const_iterator& last_trunc); |
---|
265 | |
---|
266 | /// |
---|
267 | /// @brief search for source:trunk or source:trunk@123 or |
---|
268 | /// source:trunk@123#L3 |
---|
269 | /// |
---|
270 | /// Search in range [\a first, \a last) for expression |
---|
271 | /// /source:(^s\*)/, /source:(^s\*)@(\w+)/ or |
---|
272 | /// /source:(^s\*)@(\w+)#L(\d+)/. If expression is found an anchor |
---|
273 | /// is created, displaying the expression, and first is pointing |
---|
274 | /// to character after expression. |
---|
275 | /// |
---|
276 | /// The created anchor goes to trac-root/browser/trunk or |
---|
277 | /// trac-root/browser/trunk?rev=123 or |
---|
278 | /// trac-root/browser/trunk?rev=123#L3 |
---|
279 | /// |
---|
280 | /// @return true if expression is found |
---|
281 | /// |
---|
282 | bool source(std::string::const_iterator& first, |
---|
283 | const std::string::const_iterator& last, |
---|
284 | const std::string::const_iterator& last_trunc); |
---|
285 | |
---|
286 | /// |
---|
287 | /// @see ticket1 ticket2 |
---|
288 | /// |
---|
289 | /// @return true ticket1 or ticket2 returns true |
---|
290 | /// |
---|
291 | bool ticket(std::string::const_iterator& first, |
---|
292 | const std::string::const_iterator& last, |
---|
293 | const std::string::const_iterator& last_trunc); |
---|
294 | |
---|
295 | /// |
---|
296 | /// @brief search for #65 |
---|
297 | /// |
---|
298 | /// Search in range [\a first, \a last) for expression |
---|
299 | /// /#(\d+)/. If expression is found an |
---|
300 | /// anchor is created, displaying the expression, and first is |
---|
301 | /// pointing to character after expression. |
---|
302 | /// |
---|
303 | /// The created anchor goes to trac-root/ticket/65 |
---|
304 | /// |
---|
305 | /// @return true if expression is found |
---|
306 | /// |
---|
307 | bool ticket1(std::string::const_iterator& first, |
---|
308 | const std::string::const_iterator& last, |
---|
309 | const std::string::const_iterator& last_trunc); |
---|
310 | |
---|
311 | /// |
---|
312 | /// @brief search for ticket:65 |
---|
313 | /// |
---|
314 | /// Search in range [\a first, \a last) for expression |
---|
315 | /// /ticket:(\d+)/. If expression is found an |
---|
316 | /// anchor is created, displaying the expression, and first is |
---|
317 | /// pointing to character after expression. |
---|
318 | /// |
---|
319 | /// The created anchor goes to trac-root/ticket/65 |
---|
320 | /// |
---|
321 | /// @return true if expression is found |
---|
322 | /// |
---|
323 | bool ticket2(std::string::const_iterator& first, |
---|
324 | const std::string::const_iterator& last, |
---|
325 | const std::string::const_iterator& last_trunc); |
---|
326 | |
---|
327 | |
---|
328 | |
---|
329 | HtmlStream& hs_; |
---|
330 | }; |
---|
331 | |
---|
332 | }} // end of namespace svndigest end of namespace theplu |
---|
333 | |
---|
334 | #endif |
---|