source: trunk/lib/Trac.cc @ 289

Last change on this file since 289 was 289, checked in by Peter Johansson, 14 years ago

fixed trac link problem. fixes #178 and refs #180. Also changed format of config file.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.6 KB
Line 
1// $Id: Trac.cc 289 2007-05-08 12:48:07Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Trac.h"
25
26#include "Configuration.h"
27#include "HtmlStream.h"
28#include "html_utility.h"
29#include "utility.h"
30
31namespace theplu{
32namespace svndigest{
33
34  Trac::Trac(HtmlStream& hs)
35    : hs_(hs) 
36  {}
37
38  void Trac::print(std::string str)
39  {
40    std::string::const_iterator first(str.begin());
41    while (first!=str.end()) {
42      if (log(first, str.end()))
43        continue;
44      if (ticket(first, str.end()))
45        continue;
46      hs_ << *first;
47      ++first;
48    }
49  }
50
51
52  bool Trac::ticket(std::string::const_iterator& first, 
53                    const std::string::const_iterator& last)
54  {
55    if (first==last)
56      return false;
57
58    const std::string::const_iterator first_orig(first);
59    if (*first != '#')
60      return false;
61    ++first;
62    std::string ticket = match(first, last, Digit());
63
64    if (ticket.empty()) {
65      first = first_orig;
66      return false;
67    }
68
69    const Configuration& conf = Configuration::instance();
70    hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,"#"+ticket); 
71    return true;
72  }
73
74
75  bool Trac::log(std::string::const_iterator& first, 
76                 const std::string::const_iterator& last)
77  {
78    if (first==last)
79      return false;
80
81    const std::string::const_iterator first_orig(first);
82
83    const std::string log_str("log:"); 
84    if (!match_begin(first, last, log_str)) {
85      first = first_orig;
86      return false;
87    }
88    first += log_str.size();
89    std::string node = match(first, last, not2Char('#', '@'));
90    ++first;
91    std::string stop_rev = match(first, last, Digit());
92    if (stop_rev.empty() || first == last || *first != ':') {
93      first = first_orig;
94      return false;
95    }
96    ++first;
97    std::string rev = match(first, last, Digit());
98    std::string href(Configuration::instance().trac_root()+"log"+node+
99                     "?rev="+rev+"&stop_rev="+stop_rev);
100    std::string str(first_orig, first);
101    hs_.stream() << anchor(href, str); 
102    return true;
103  }
104
105}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.