Changeset 308 for trunk


Ignore:
Timestamp:
May 12, 2007, 12:36:23 PM (14 years ago)
Author:
Peter Johansson
Message:

Refs #189. Added doc to private classes in Trac class. Re-ordered functions. Changed the behaviour: revisions does not need to be an integer can for example be head

Location:
trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Trac.cc

    r302 r308  
    111111
    112112
    113   void Trac::print(std::string str)
    114   {
    115     std::string::const_iterator first(str.begin());
    116     while (first!=str.end()) {
    117       if (log(first, str.end()))
    118         continue;
    119       if (ticket(first, str.end()))
    120         continue;
    121       if (comment(first, str.end()))
    122         continue;
    123       if (changeset(first, str.end()))
    124         continue;
    125       if (diff(first, str.end()))
    126         continue;
    127       if (milestone(first, str.end()))
    128         continue;
    129       if (source(first, str.end()))
    130         continue;
    131       hs_ << *first;
    132       ++first;
    133     }
    134   }
    135 
    136 
    137113  bool Trac::comment(std::string::const_iterator& first,
    138114                     const std::string::const_iterator& last)
     
    147123    }
    148124     
    149     std::string ticket = match(first, last, Digit());
     125    std::string ticket = match(first, last, AlNum());
    150126    if (ticket.empty() || first == last || *first != ':') {
    151127      first = first_orig;
     
    174150
    175151
    176   bool Trac::milestone(std::string::const_iterator& first,
    177                        const std::string::const_iterator& last)
    178   {
    179     if (first==last)
    180       return false;
    181 
    182     const std::string::const_iterator first_orig(first);
    183 
    184     if (match(first, last, Str("milestone:")).empty()){
    185       first = first_orig;
    186       return false;
    187     }
    188 
    189     const std::string::const_iterator milestone_begin(first);
    190 
    191     // find the last alphanumerical char before next space (or last)
    192     for (std::string::const_iterator i(first); i!=last && *i!=' '; ++i)
    193       if (isalnum(*i))
    194         first = i+1;
    195 
    196     std::string milestone(milestone_begin, first);
    197     if (milestone.empty()){
    198       first = first_orig;
    199       return false;
    200     }
    201 
    202     const Configuration& conf = Configuration::instance();
    203     hs_.stream() << anchor(conf.trac_root()+"milestone/"+milestone,
    204                            std::string(first_orig, first));
    205     return true;
    206   }
    207 
    208 
    209   bool Trac::source(std::string::const_iterator& first,
    210                     const std::string::const_iterator& last)
    211   {
    212     if (first==last)
    213       return false;
    214 
    215     const std::string::const_iterator first_orig(first);
    216 
    217     if (match(first, last, Str("source:")).empty()){
    218       first = first_orig;
    219       return false;
    220     }
    221 
    222     std::string node;
    223     std::string rev;
    224     std::string line;
    225     const std::string::const_iterator node_begin(first);
    226 
    227     node = match(first, last, not2Char('@', ' '));
    228     if (!node.empty() && node[0]=='/')
    229       node = node.substr(1, node.size()-1);
    230  
    231     if (*first == '@'){
    232       ++first;
    233       rev = match(first, last, Digit());
    234       if (*first == '#') {
    235         ++first;
    236         line = match(first, last, notChar(' '));
    237       }
    238     }
    239 
    240     const Configuration& conf = Configuration::instance();
    241     std::string href(conf.trac_root()+node);
    242     if (!rev.empty()) {
    243       href += "@"+rev;
    244       if (!line.empty())
    245         href += "#"+line;
    246     }
    247     hs_.stream() << anchor(href, std::string(first_orig, first));
    248     return true;
    249   }
    250 
    251 
    252   bool Trac::ticket(std::string::const_iterator& first,
    253                     const std::string::const_iterator& last)
    254   {
    255     if (ticket1(first, last))
    256       return true;
    257     if (ticket2(first, last))
    258       return true;
    259     return false;
    260   }
    261 
    262 
    263   bool Trac::ticket1(std::string::const_iterator& first,
    264                      const std::string::const_iterator& last)
    265   {
    266     if (first==last)
    267       return false;
    268 
    269     const std::string::const_iterator first_orig(first);
    270     if (*first != '#')
    271       return false;
    272     ++first;
    273     std::string ticket = match(first, last, Digit());
    274 
    275     if (ticket.empty()) {
    276       first = first_orig;
    277       return false;
    278     }
    279 
    280     const Configuration& conf = Configuration::instance();
    281     hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,
    282                            std::string(first_orig, first));
    283     return true;
    284   }
    285 
    286 
    287   bool Trac::ticket2(std::string::const_iterator& first,
    288                      const std::string::const_iterator& last)
    289   {
    290     if (first==last)
    291       return false;
    292 
    293     const std::string::const_iterator first_orig(first);
    294 
    295     if (match(first, last, Str("ticket:")).empty()){
    296       first = first_orig;
    297       return false;
    298     }
    299      
    300     std::string ticket = match(first, last, Digit());
    301 
    302     const Configuration& conf = Configuration::instance();
    303     hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,"#"+ticket);
    304     return true;
    305   }
    306 
    307 
    308152  bool Trac::diff(std::string::const_iterator& first,
    309153                  const std::string::const_iterator& last)
     
    336180    }
    337181    ++first;
    338     std::string old_rev = match(first, last, Digit());
     182    std::string old_rev = match(first, last, AlNum());
    339183    if (old_rev.empty() || first == last || *first != ':') {
    340184      first = first_orig;
     
    342186    }
    343187    ++first;
    344     std::string new_rev = match(first, last, Digit());
     188    std::string new_rev = match(first, last, AlNum());
    345189    if (new_rev.empty() ) {
    346190      first = first_orig;
     
    407251    }
    408252    ++first;
    409     std::string old_rev(match(first, last, Digit()));
     253    std::string old_rev(match(first, last, AlNum()));
    410254    if (!match_begin(first, first+1, std::string("//"))) {
    411255      first = first_orig;
     
    419263    }
    420264    ++first;
    421     std::string new_rev(match(first, last, Digit()));
     265    std::string new_rev(match(first, last, AlNum()));
    422266    if (new_rev.empty()){
    423267      first = first_orig;
     
    457301    ++first;
    458302
    459     std::string stop_rev = match(first, last, Digit());
     303    std::string stop_rev = match(first, last, AlNum());
    460304    if (stop_rev.empty() || first == last || *first != ':') {
    461305      first = first_orig;
     
    463307    }
    464308    ++first;
    465     std::string rev = match(first, last, Digit());
     309    std::string rev = match(first, last, AlNum());
    466310    if (rev.empty() ) {
    467311      first = first_orig;
     
    486330    ++first;
    487331
    488     std::string stop_rev = match(first, last, Digit());
     332    std::string stop_rev = match(first, last, AlNum());
    489333    if (stop_rev.empty() || first == last || *first != ':') {
    490334      first = first_orig;
     
    492336    }
    493337    ++first;
    494     std::string rev = match(first, last, Digit());
     338    std::string rev = match(first, last, AlNum());
    495339    if (rev.empty() || first == last || *first != ']') {
    496340      first = first_orig;
     
    520364    std::string node = match(first, last, not2Char('#', '@'));
    521365    ++first;
    522     std::string stop_rev = match(first, last, Digit());
     366    std::string stop_rev = match(first, last, AlNum());
    523367    if (stop_rev.empty() || first == last || *first != ':') {
    524368      first = first_orig;
     
    526370    }
    527371    ++first;
    528     std::string rev = match(first, last, Digit());
     372    std::string rev = match(first, last, AlNum());
    529373    if (rev.empty() ) {
    530374      first = first_orig;
     
    543387  }
    544388
     389
     390  bool Trac::milestone(std::string::const_iterator& first,
     391                       const std::string::const_iterator& last)
     392  {
     393    if (first==last)
     394      return false;
     395
     396    const std::string::const_iterator first_orig(first);
     397
     398    if (match(first, last, Str("milestone:")).empty()){
     399      first = first_orig;
     400      return false;
     401    }
     402
     403    const std::string::const_iterator milestone_begin(first);
     404
     405    // find the last alphanumerical char before next space (or last)
     406    for (std::string::const_iterator i(first); i!=last && *i!=' '; ++i)
     407      if (isalnum(*i))
     408        first = i+1;
     409
     410    std::string milestone(milestone_begin, first);
     411    if (milestone.empty()){
     412      first = first_orig;
     413      return false;
     414    }
     415
     416    const Configuration& conf = Configuration::instance();
     417    hs_.stream() << anchor(conf.trac_root()+"milestone/"+milestone,
     418                           std::string(first_orig, first));
     419    return true;
     420  }
     421
     422
     423  void Trac::print(std::string str)
     424  {
     425    std::string::const_iterator first(str.begin());
     426    while (first!=str.end()) {
     427      if (log(first, str.end()))
     428        continue;
     429      if (ticket(first, str.end()))
     430        continue;
     431      if (comment(first, str.end()))
     432        continue;
     433      if (changeset(first, str.end()))
     434        continue;
     435      if (diff(first, str.end()))
     436        continue;
     437      if (milestone(first, str.end()))
     438        continue;
     439      if (source(first, str.end()))
     440        continue;
     441      hs_ << *first;
     442      ++first;
     443    }
     444  }
     445
     446
     447  bool Trac::source(std::string::const_iterator& first,
     448                    const std::string::const_iterator& last)
     449  {
     450    if (first==last)
     451      return false;
     452
     453    const std::string::const_iterator first_orig(first);
     454
     455    if (match(first, last, Str("source:")).empty()){
     456      first = first_orig;
     457      return false;
     458    }
     459
     460    std::string node;
     461    std::string rev;
     462    std::string line;
     463    const std::string::const_iterator node_begin(first);
     464
     465    node = match(first, last, not2Char('@', ' '));
     466    if (!node.empty() && node[0]=='/')
     467      node = node.substr(1, node.size()-1);
     468 
     469    if (*first == '@'){
     470      ++first;
     471      rev = match(first, last, AlNum());
     472      if (*first == '#') {
     473        ++first;
     474        line = match(first, last, notChar(' '));
     475      }
     476    }
     477
     478    const Configuration& conf = Configuration::instance();
     479    std::string href(conf.trac_root()+"browser/"+node);
     480    if (!rev.empty()) {
     481      href += "?rev="+rev;
     482      if (!line.empty())
     483        href += "#"+line;
     484    }
     485    hs_.stream() << anchor(href, std::string(first_orig, first));
     486    return true;
     487  }
     488
     489
     490  bool Trac::ticket(std::string::const_iterator& first,
     491                    const std::string::const_iterator& last)
     492  {
     493    if (ticket1(first, last))
     494      return true;
     495    if (ticket2(first, last))
     496      return true;
     497    return false;
     498  }
     499
     500
     501  bool Trac::ticket1(std::string::const_iterator& first,
     502                     const std::string::const_iterator& last)
     503  {
     504    if (first==last)
     505      return false;
     506
     507    const std::string::const_iterator first_orig(first);
     508    if (*first != '#')
     509      return false;
     510    ++first;
     511    std::string ticket = match(first, last, Digit());
     512
     513    if (ticket.empty()) {
     514      first = first_orig;
     515      return false;
     516    }
     517
     518    const Configuration& conf = Configuration::instance();
     519    hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,
     520                           std::string(first_orig, first));
     521    return true;
     522  }
     523
     524
     525  bool Trac::ticket2(std::string::const_iterator& first,
     526                     const std::string::const_iterator& last)
     527  {
     528    if (first==last)
     529      return false;
     530
     531    const std::string::const_iterator first_orig(first);
     532
     533    if (match(first, last, Str("ticket:")).empty()){
     534      first = first_orig;
     535      return false;
     536    }
     537     
     538    std::string ticket = match(first, last, Digit());
     539
     540    const Configuration& conf = Configuration::instance();
     541    hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,"#"+ticket);
     542    return true;
     543  }
     544
     545
    545546}} // end of namespace svndigest and namespace theplu
  • trunk/lib/Trac.h

    r294 r308  
    5050
    5151  private:
     52    ///
     53    /// @see changeset1 changeset2 changeset3
     54    ///
     55    /// @return true if any of changesetX returns true
     56    ///
    5257    bool changeset(std::string::const_iterator& first,
    5358                   const std::string::const_iterator& last);
    5459
     60    ///
     61    /// \brief search for 'r123'
     62    ///
     63    /// Search in range [\a first, \a last) for expression
     64    /// /r(\d+)/. If expression is found an anchor to
     65    /// trac-root/changeset/123, displaying expression, and first is
     66    /// pointing to character after expression.
     67    ///
     68    /// @return true if expression is found
     69    ///
    5570    bool changeset1(std::string::const_iterator& first,
    5671                   const std::string::const_iterator& last);
    5772
     73    ///
     74    /// \brief search for '[123]'
     75    ///
     76    /// Search in range [\a first, \a last) for expression
     77    /// /\[(\d+)\]/. If expression is found an anchor to
     78    /// trac-root/changeset/123, displaying expression, and first is
     79    /// pointing to character after expression.
     80    ///
     81    /// @return true if expression is found
     82    ///
    5883    bool changeset2(std::string::const_iterator& first,
    5984                   const std::string::const_iterator& last);
    6085
     86    ///
     87    /// \brief search for changeset:123
     88    ///
     89    /// Search in range [\a first, \a last) for expression
     90    /// /changeset:(\d+)/. If expression is found an anchor to
     91    /// trac-root/changeset/123, displaying expression, and first is
     92    /// pointing to character after expression.
     93    ///
     94    /// @return true if expression is found
     95    ///
    6196    bool changeset3(std::string::const_iterator& first,
    6297                   const std::string::const_iterator& last);
    6398
     99    ///
     100    /// \brief search for /comment:ticket:123:1/
     101    ///
     102    /// Search in range [\a first, \a last) for expression
     103    /// /comment:ticket:(\w+):(\d+)/. If expression is found an anchor
     104    /// to trac-root/ticket/123#comment:1, displaying expression, and
     105    /// first is pointing to character after expression.
     106    ///
     107    /// @return true if expression is found
     108    ///
     109    bool comment(std::string::const_iterator& first,
     110                 const std::string::const_iterator& last);
     111
     112    ///
     113    /// @see diff1 diff2 diff3
     114    ///
     115    /// @return true if any of diffX returns true
     116    ///
    64117    bool diff(std::string::const_iterator& first,
    65118              const std::string::const_iterator& last);
    66119
     120    ///
     121    /// \brief search for diff:trunk@12+:123
     122    ///
     123    /// Search in range [\a first, \a last) for expression
     124    /// /diff:(.*)@(\w+):(\w+)/. If expression is found an anchor is
     125    /// created, displaying the expression, and first is pointing to
     126    /// character after expression.
     127    ///
     128    /// If $1 (trunk) is empty anchor goes to
     129    /// trac-root/changeset?new=123&old=12 otherwise it goes to
     130    /// trac-root/changeset?new=123&newpath=trunk&old=12&oldpath=trunk
     131    ///
     132    /// @return true if expression is found
     133    ///
    67134    bool diff1(std::string::const_iterator& first,
    68135               const std::string::const_iterator& last);
    69136
     137    ///
     138    /// @brief search for diff:tags/1.0 or diff:tags/1.0//1.0.1
     139    ///
     140    /// Search in range [\a first, \a last) for expression
     141    /// /diff:(^\s+)/ or /diff:(^\s+)\/\/(^\s+)/. If expression is found
     142    /// an anchor is created, displaying the expression, and first is
     143    /// pointing to character after expression.
     144    ///
     145    /// The created anchor goes to
     146    /// trac-root/changeset?new_path=tags/1.0&old_path=tags/1.0 or
     147    /// trac-root/changeset?new_path=tags/1.0&old_path=tags/1.0.1
     148    /// respectively.
     149    ///
     150    /// @return true if expression is found
     151    ///
    70152    bool diff2(std::string::const_iterator& first,
    71153               const std::string::const_iterator& last);
    72154
     155    ///
     156    /// @brief search for diff:tags/1.0@123//trunk@236
     157    ///
     158    /// Search in range [\a first, \a last) for expression
     159    /// /diff:(^\s+)@(\w+)\/\/(^\s+)@(\w+)/. If expression is found an
     160    /// anchor is created, displaying the expression, and first is
     161    /// pointing to character after expression.
     162    ///
     163    /// The created anchor goes to
     164    /// trac-root/changeset?new=236&new_path=trunk&old=236&old_path=tags/1.0
     165    ///
     166    /// @return true if expression is found
     167    ///
    73168    bool diff3(std::string::const_iterator& first,
    74169               const std::string::const_iterator& last);
    75170
    76     bool comment(std::string::const_iterator& first,
    77                  const std::string::const_iterator& last);
    78 
     171
     172    ///
     173    /// @see log1 log2 log3
     174    ///
     175    /// @return true if any of logX returns true
     176    ///
    79177    bool log(std::string::const_iterator& first,
    80178             const std::string::const_iterator& last);
    81179
     180    ///
     181    /// @brief search for r123:236
     182    ///
     183    /// Search in range [\a first, \a last) for expression
     184    /// /r(\w+):(\w+)/. If expression is found an
     185    /// anchor is created, displaying the expression, and first is
     186    /// pointing to character after expression.
     187    ///
     188    /// The created anchor goes to trac-root/log/?rev=236&stop_rev=123
     189    ///
     190    /// @return true if expression is found
     191    ///
    82192    bool log1(std::string::const_iterator& first,
    83193              const std::string::const_iterator& last);
    84194
     195    ///
     196    /// @brief search for [123:236]
     197    ///
     198    /// Search in range [\a first, \a last) for expression
     199    /// /\[(\w+):(\w+)\]/. If expression is found an
     200    /// anchor is created, displaying the expression, and first is
     201    /// pointing to character after expression.
     202    ///
     203    /// The created anchor goes to trac-root/log/?rev=236&stop_rev=123
     204    ///
     205    /// @return true if expression is found
     206    ///
    85207    bool log2(std::string::const_iterator& first,
    86208              const std::string::const_iterator& last);
    87209
     210    ///
     211    /// @brief search for log:trunk@123:236 or log:trunk#123:236
     212    ///
     213    /// Search in range [\a first, \a last) for expression
     214    /// /log:(^\s*)(@|#)(\w+):(\w+)/. If expression is found an
     215    /// anchor is created, displaying the expression, and first is
     216    /// pointing to character after expression.
     217    ///
     218    /// The created anchor goes to trac-root/log/trunk?rev=236&stop_rev=123
     219    ///
     220    /// @return true if expression is found
     221    ///
    88222    bool log3(std::string::const_iterator& first,
    89223              const std::string::const_iterator& last);
    90224
     225    ///
     226    /// @brief search for milestone:1.0
     227    ///
     228    /// Search in range [\a first, \a last) for expression
     229    /// /milestone:(^s\*)\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/milestone/1.0
     234    ///
     235    /// @return true if expression is found
     236    ///
    91237    bool milestone(std::string::const_iterator& first,
    92238                   const std::string::const_iterator& last);
    93239
     240    ///
     241    /// @brief search for source:trunk or source:trunk@123 or
     242    /// source:trunk@123#L3
     243    ///
     244    /// Search in range [\a first, \a last) for expression
     245    /// /source:(^s\*)/, /source:(^s\*)@(\w+)/ or
     246    /// /source:(^s\*)@(\w+)#L(\d+)/. If expression is found an anchor
     247    /// is created, displaying the expression, and first is pointing
     248    /// to character after expression.
     249    ///
     250    /// The created anchor goes to trac-root/browser/trunk or
     251    /// trac-root/browser/trunk?rev=123 or
     252    /// trac-root/browser/trunk?rev=123#L3
     253    ///
     254    /// @return true if expression is found
     255    ///
    94256    bool source(std::string::const_iterator& first,
    95257                const std::string::const_iterator& last);
    96258
     259    ///
     260    /// @see ticket1 ticket2
     261    ///
     262    /// @return true ticket1 or ticket2 returns true
     263    ///
    97264    bool ticket(std::string::const_iterator& first,
    98265                const std::string::const_iterator& last);
    99266
    100     /// if range (first, last) starts with /#[:digit:]*/ a ticket link
    101     /// is written;
    102     /// @return if ticket is found iterator pointing to after found
    103     /// ticket; else first is returned.
     267    ///
     268    /// @brief search for #65
     269    ///
     270    /// Search in range [\a first, \a last) for expression
     271    /// /#(\d+)/. If expression is found an
     272    /// anchor is created, displaying the expression, and first is
     273    /// pointing to character after expression.
     274    ///
     275    /// The created anchor goes to trac-root/ticket/65
     276    ///
     277    /// @return true if expression is found
     278    ///
    104279    bool ticket1(std::string::const_iterator& first,
    105280                 const std::string::const_iterator& last);
    106281
     282    ///
     283    /// @brief search for ticket:65
     284    ///
     285    /// Search in range [\a first, \a last) for expression
     286    /// /ticket:(\d+)/. If expression is found an
     287    /// anchor is created, displaying the expression, and first is
     288    /// pointing to character after expression.
     289    ///
     290    /// The created anchor goes to trac-root/ticket/65
     291    ///
     292    /// @return true if expression is found
     293    ///
    107294    bool ticket2(std::string::const_iterator& first,
    108295                 const std::string::const_iterator& last);
  • trunk/lib/utility.h

    r303 r308  
    150150  }
    151151
     152  struct AlNum
     153  {
     154    inline bool operator()(std::string::const_iterator i) const
     155    { return isalnum(*i); }
     156  };
     157
     158
    152159  struct Digit
    153160  {
     
    155162    { return isdigit(*i); }
    156163  };
     164
    157165
    158166  class notChar
Note: See TracChangeset for help on using the changeset viewer.