source: branches/0.6-stable/lib/Trac.h @ 764

Last change on this file since 764 was 764, checked in by Peter Johansson, 13 years ago

Preparing release 0.6.7

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