source: trunk/lib/Trac.h @ 1513

Last change on this file since 1513 was 1513, checked in by Peter Johansson, 9 years ago

remove trailing whitespace

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