source: trunk/lib/Trac.h @ 745

Last change on this file since 745 was 693, checked in by Jari Häkkinen, 13 years ago

Fixes #339. Change to GPLv3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
1#ifndef _theplu_svndigest_trac_
2#define _theplu_svndigest_trac_
3
4// $Id: Trac.h 693 2008-09-11 20:42:56Z jari $
5
6/*
7  Copyright (C) 2007 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
27namespace theplu{
28namespace 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(std::string::const_iterator& first, 
61                   const std::string::const_iterator& last,
62                   const std::string::const_iterator& last_trunc);
63
64    ///
65    /// \brief search for 'r123'
66    ///
67    /// Search in range [\a first, \a last) for expression
68    /// /r(\d+)/. If expression is found an anchor to
69    /// trac-root/changeset/123, displaying expression, and first is
70    /// pointing to character after expression.
71    ///
72    /// @return true if expression is found
73    ///
74    bool changeset1(std::string::const_iterator& first, 
75                    const std::string::const_iterator& last,
76                    const std::string::const_iterator& last_trunc);
77
78    ///
79    /// \brief search for '[123]'
80    ///
81    /// Search in range [\a first, \a last) for expression
82    /// /\[(\d+)\]/. If expression is found an anchor to
83    /// trac-root/changeset/123, displaying expression, and first is
84    /// pointing to character after expression.
85    ///
86    /// @return true if expression is found
87    ///
88    bool changeset2(std::string::const_iterator& first, 
89                    const std::string::const_iterator& last,
90                    const std::string::const_iterator& last_trunc);
91
92    ///
93    /// \brief search for changeset:123
94    ///
95    /// Search in range [\a first, \a last) for expression
96    /// /changeset:(\d+)/. If expression is found an anchor to
97    /// trac-root/changeset/123, displaying expression, and first is
98    /// pointing to character after expression.
99    ///
100    /// @return true if expression is found
101    ///
102    bool changeset3(std::string::const_iterator& first, 
103                    const std::string::const_iterator& last,
104                    const std::string::const_iterator& last_trunc);
105
106    ///
107    /// \brief search for /comment:ticket:123:1/
108    ///
109    /// Search in range [\a first, \a last) for expression
110    /// /comment:ticket:(\w+):(\d+)/. If expression is found an anchor
111    /// to trac-root/ticket/123#comment:1, displaying expression, and
112    /// first is pointing to character after expression.
113    ///
114    /// @return true if expression is found
115    ///
116    bool comment(std::string::const_iterator& first, 
117                 const std::string::const_iterator& last,
118                 const std::string::const_iterator& last_trunc);
119
120    ///
121    /// @see diff1 diff2 diff3
122    ///
123    /// @return true if any of diffX returns true
124    ///
125    bool diff(std::string::const_iterator& first, 
126              const std::string::const_iterator& last,
127              const std::string::const_iterator& last_trunc);
128
129    ///
130    /// \brief search for diff:trunk@12:123
131    ///
132    /// Search in range [\a first, \a last) for expression
133    /// /diff:(.*)@(\w+):(\w+)/. If expression is found an anchor is
134    /// created, displaying the expression, and first is pointing to
135    /// character after expression.
136    ///
137    /// If $1 (trunk) is empty anchor goes to
138    /// trac-root/changeset?new=123&old=12 otherwise it goes to
139    /// trac-root/changeset?new=123&newpath=trunk&old=12&oldpath=trunk
140    ///
141    /// @return true if expression is found
142    ///
143    bool diff1(std::string::const_iterator& first, 
144               const std::string::const_iterator& last,
145               const std::string::const_iterator& last_trunc);
146
147    ///
148    /// @brief search for diff:tags/1.0 or diff:tags/1.0//tags/1.0.1
149    ///
150    /// Search in range [\a first, \a last) for expression
151    /// /diff:(^\s+)/ or /diff:(^\s+)\/\/(^\s+)/. If expression is found
152    /// an anchor is created, displaying the expression, and first is
153    /// pointing to character after expression.
154    ///
155    /// The created anchor goes to
156    /// trac-root/changeset?new_path=tags/1.0&old_path=tags/1.0 or
157    /// trac-root/changeset?new_path=tags/1.0&old_path=tags/1.0.1
158    /// respectively.
159    ///
160    /// @return true if expression is found
161    ///
162    bool diff2(std::string::const_iterator& first, 
163               const std::string::const_iterator& last,
164               const std::string::const_iterator& last_trunc);
165
166    ///
167    /// @brief search for diff:tags/1.0@123//trunk@236
168    ///
169    /// Search in range [\a first, \a last) for expression
170    /// /diff:(^\s+)@(\w+)\/\/(^\s+)@(\w+)/. If expression is found an
171    /// anchor is created, displaying the expression, and first is
172    /// pointing to character after expression.
173    ///
174    /// The created anchor goes to
175    /// trac-root/changeset?new=236&new_path=trunk&old=123&old_path=tags/1.0
176    ///
177    /// @return true if expression is found
178    ///
179    bool diff3(std::string::const_iterator& first, 
180               const std::string::const_iterator& last,
181               const std::string::const_iterator& last_trunc);
182
183
184    ///
185    /// @see log1 log2 log3
186    ///
187    /// @return true if any of logX returns true
188    ///
189    bool log(std::string::const_iterator& first, 
190             const std::string::const_iterator& last,
191             const std::string::const_iterator& last_trunc);
192
193    ///
194    /// @brief search for r123:236
195    ///
196    /// Search in range [\a first, \a last) for expression
197    /// /r(\w+):(\w+)/. If expression is found an
198    /// anchor is created, displaying the expression, and first is
199    /// pointing to character after expression.
200    ///
201    /// The created anchor goes to trac-root/log/?rev=236&stop_rev=123
202    ///
203    /// @return true if expression is found
204    ///
205    bool log1(std::string::const_iterator& first, 
206              const std::string::const_iterator& last,
207              const std::string::const_iterator& last_trunc);
208
209    ///
210    /// @brief search for [123:236]
211    ///
212    /// Search in range [\a first, \a last) for expression
213    /// /\[(\w+):(\w+)\]/. If expression is found an
214    /// anchor is created, displaying the expression, and first is
215    /// pointing to character after expression.
216    ///
217    /// The created anchor goes to trac-root/log/?rev=236&stop_rev=123
218    ///
219    /// @return true if expression is found
220    ///
221    bool log2(std::string::const_iterator& first, 
222              const std::string::const_iterator& last,
223              const std::string::const_iterator& last_trunc);
224
225    ///
226    /// @brief search for log:trunk@123:236 or log:trunk#123:236
227    ///
228    /// Search in range [\a first, \a last) for expression
229    /// /log:(^\s*)(@|#)(\w+):(\w+)/. If expression is found an
230    /// anchor is created, displaying the expression, and first is
231    /// pointing to character after expression.
232    ///
233    /// The created anchor goes to trac-root/log/trunk?rev=236&stop_rev=123
234    ///
235    /// @return true if expression is found
236    ///
237    bool log3(std::string::const_iterator& first, 
238              const std::string::const_iterator& last,
239              const std::string::const_iterator& last_trunc);
240
241    ///
242    /// @brief search for milestone:1.0
243    ///
244    /// Search in range [\a first, \a last) for expression
245    /// /milestone:(^s\*)\w/. If expression is found an
246    /// anchor is created, displaying the expression, and first is
247    /// pointing to character after expression.
248    ///
249    /// The created anchor goes to trac-root/milestone/1.0
250    ///
251    /// @return true if expression is found
252    ///
253    bool milestone(std::string::const_iterator& first, 
254                   const std::string::const_iterator& last,
255                   const std::string::const_iterator& last_trunc);
256
257    ///
258    /// @brief search for source:trunk or source:trunk@123 or
259    /// source:trunk@123#L3
260    ///
261    /// Search in range [\a first, \a last) for expression
262    /// /source:(^s\*)/, /source:(^s\*)@(\w+)/ or
263    /// /source:(^s\*)@(\w+)#L(\d+)/. If expression is found an anchor
264    /// is created, displaying the expression, and first is pointing
265    /// to character after expression.
266    ///
267    /// The created anchor goes to trac-root/browser/trunk or
268    /// trac-root/browser/trunk?rev=123 or
269    /// trac-root/browser/trunk?rev=123#L3
270    ///
271    /// @return true if expression is found
272    ///
273    bool source(std::string::const_iterator& first, 
274                const std::string::const_iterator& last,
275                const std::string::const_iterator& last_trunc);
276
277    ///
278    /// @see ticket1 ticket2
279    ///
280    /// @return true ticket1 or ticket2 returns true
281    ///
282    bool ticket(std::string::const_iterator& first, 
283                const std::string::const_iterator& last,
284                const std::string::const_iterator& last_trunc);
285
286    ///
287    /// @brief search for #65
288    ///
289    /// Search in range [\a first, \a last) for expression
290    /// /#(\d+)/. If expression is found an
291    /// anchor is created, displaying the expression, and first is
292    /// pointing to character after expression.
293    ///
294    /// The created anchor goes to trac-root/ticket/65
295    ///
296    /// @return true if expression is found
297    ///
298    bool ticket1(std::string::const_iterator& first, 
299                 const std::string::const_iterator& last,
300                 const std::string::const_iterator& last_trunc);
301
302    ///
303    /// @brief search for ticket:65
304    ///
305    /// Search in range [\a first, \a last) for expression
306    /// /ticket:(\d+)/. If expression is found an
307    /// anchor is created, displaying the expression, and first is
308    /// pointing to character after expression.
309    ///
310    /// The created anchor goes to trac-root/ticket/65
311    ///
312    /// @return true if expression is found
313    ///
314    bool ticket2(std::string::const_iterator& first, 
315                 const std::string::const_iterator& last,
316                 const std::string::const_iterator& last_trunc);
317
318
319
320    HtmlStream& hs_;
321  };
322
323}} // end of namespace svndigest end of namespace theplu
324
325#endif
Note: See TracBrowser for help on using the repository browser.