Changeset 294


Ignore:
Timestamp:
May 8, 2007, 7:47:12 PM (16 years ago)
Author:
Peter Johansson
Message:

refs #180, support:
diff:@288:294,
diff:tags/release-0.4/bin//tags/release-0.5/bin or
diff:trunk/lib/Trac.cc@288//trunk/lib/Trac.cc@294

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Trac.cc

    r293 r294  
    9696      return false;
    9797    const std::string::const_iterator first_orig(first);
    98     if (match(first, last, "changeset:").empty()){
     98    if (match(first, last, Str("changeset:")).empty()){
    9999      first = first_orig;
    100100      return false;
     
    123123      if (changeset(first, str.end()))
    124124        continue;
     125      if (diff(first, str.end()))
     126        continue;
    125127      hs_ << *first;
    126128      ++first;
     
    136138
    137139    const std::string::const_iterator first_orig(first);
    138     if (match(first, last, "comment:ticket:").empty()){
     140    if (match(first, last, Str("comment:ticket:")).empty()){
    139141      first = first_orig;
    140142      return false;
     
    208210    const std::string::const_iterator first_orig(first);
    209211
    210     if (match(first, last, "ticket:").empty()){
     212    if (match(first, last, Str("ticket:")).empty()){
    211213      first = first_orig;
    212214      return false;
     
    217219    const Configuration& conf = Configuration::instance();
    218220    hs_.stream() << anchor(conf.trac_root()+"ticket/"+ticket,"#"+ticket);
     221    return true;
     222  }
     223
     224
     225  bool Trac::diff(std::string::const_iterator& first,
     226                  const std::string::const_iterator& last)
     227  {
     228    if (diff1(first, last))
     229      return true;
     230    if (diff3(first, last))
     231      return true;
     232    if (diff2(first, last))
     233      return true;
     234    return false;
     235  }
     236
     237
     238  bool Trac::diff1(std::string::const_iterator& first,
     239                   const std::string::const_iterator& last)
     240  {
     241    if (first==last)
     242      return false;
     243
     244    const std::string::const_iterator first_orig(first);
     245    if (match(first, last, Str("diff:")).empty()){
     246      first = first_orig;
     247      return false;
     248    }
     249    std::string node = match(first, last, notChar('@'));
     250    if (first==last){
     251      first = first_orig;
     252      return false;
     253    }
     254    ++first;
     255    std::string old_rev = match(first, last, Digit());
     256    if (old_rev.empty() || first == last || *first != ':') {
     257      first = first_orig;
     258      return false;
     259    }
     260    ++first;
     261    std::string new_rev = match(first, last, Digit());
     262    if (new_rev.empty() ) {
     263      first = first_orig;
     264      return false;
     265    }
     266    std::string href;
     267    if (node.empty())
     268      href = std::string(Configuration::instance().trac_root()+
     269                         "changeset?new="+new_rev+"&old="+old_rev);
     270    else
     271      href = std::string(Configuration::instance().trac_root()+
     272                         "changeset?new="+new_rev+"&new_path="+node+"&old="+
     273                         old_rev+"&oldpath="+node);
     274    hs_.stream() << anchor(href, std::string(first_orig, first));
     275    return true;
     276  }
     277
     278
     279  bool Trac::diff2(std::string::const_iterator& first,
     280                   const std::string::const_iterator& last)
     281  {
     282    if (first==last)
     283      return false;
     284
     285    const std::string::const_iterator first_orig(first);
     286    if (match(first, last, Str("diff:")).empty()){
     287      first = first_orig;
     288      return false;
     289    }
     290    std::string old_path(match(first, last, not2Str("//", " ")));
     291    std::string new_path;
     292    if (first==last || *first==' ')
     293      new_path = old_path;
     294    else {
     295      first += 2;
     296      new_path = match(first, last, notChar(' '));
     297    }
     298    if (new_path.empty() || old_path.empty()){
     299      first = first_orig;
     300      return false;
     301    }
     302    std::string href(Configuration::instance().trac_root()+
     303                     "changeset?new_path="+new_path+"&old_path="+old_path);
     304    hs_.stream() << anchor(href, std::string(first_orig, first));
     305    return true;
     306  }
     307
     308
     309  bool Trac::diff3(std::string::const_iterator& first,
     310                   const std::string::const_iterator& last)
     311  {
     312    if (first==last)
     313      return false;
     314
     315    const std::string::const_iterator first_orig(first);
     316    if (match(first, last, Str("diff:")).empty()){
     317      first = first_orig;
     318      return false;
     319    }
     320    std::string old_path(match(first, last, not2Char('@', ' ')));
     321    if (*first!='@'){
     322      first = first_orig;
     323      return false;
     324    }
     325    ++first;
     326    std::string old_rev(match(first, last, Digit()));
     327    if (!match_begin(first, first+1, std::string("//"))) {
     328      first = first_orig;
     329      return false;
     330    }
     331    first+2;
     332    std::string new_path = match(first, last, not2Char('@', ' '));
     333    if (*first!='@'){
     334      first = first_orig;
     335      return false;
     336    }
     337    ++first;
     338    std::string new_rev(match(first, last, Digit()));
     339    if (new_rev.empty()){
     340      first = first_orig;
     341      return false;
     342    }
     343   
     344    std::string href(Configuration::instance().trac_root()+
     345                     "changeset?new="+new_rev+"&new_path="+new_path+
     346                     "&old="+old_rev+"&old_path="+old_path);
     347    hs_.stream() << anchor(href, std::string(first_orig, first));
    219348    return true;
    220349  }
  • trunk/lib/Trac.h

    r293 r294  
    6262                   const std::string::const_iterator& last);
    6363
     64    bool diff(std::string::const_iterator& first,
     65              const std::string::const_iterator& last);
     66
     67    bool diff1(std::string::const_iterator& first,
     68               const std::string::const_iterator& last);
     69
     70    bool diff2(std::string::const_iterator& first,
     71               const std::string::const_iterator& last);
     72
     73    bool diff3(std::string::const_iterator& first,
     74               const std::string::const_iterator& last);
     75
    6476    bool comment(std::string::const_iterator& first,
    6577                 const std::string::const_iterator& last);
  • trunk/lib/utility.cc

    r290 r294  
    111111
    112112
    113   std::string match(std::string::const_iterator& first,
    114                     const std::string::const_iterator& last,
    115                     const char* c)
    116   {
    117     std::string str(c);
    118     if (match_begin(first, last, str)) {
    119       first += str.size();
    120       return str;
    121     }
    122     return std::string();
    123   }
    124 
    125 
    126113  bool node_exist(const std::string& path)
    127114  {
     
    188175   
    189176
     177  Str::Str(std::string s)
     178    : str_(s)
     179  {}
     180
     181
     182  not2Str::not2Str(std::string s1, std::string s2)
     183    : str1_(s1), str2_(s2)
     184  {}
     185   
     186
    190187}} // end of namespace svndigest and namespace theplu
  • trunk/lib/utility.h

    r290 r294  
    134134
    135135
    136   std::string match(std::string::const_iterator& first,
    137                     const std::string::const_iterator& last,
    138                     const char*);
    139 
    140136  template <class T>
    141137  std::string match(std::string::const_iterator& first,
     
    144140  {
    145141    std::string res;
    146     for (;first!=last && func(*first); ++first)
     142    for (;first!=last && func(first); ++first)
    147143      res.append(1,*first);
    148144    return res;
     
    151147  struct Digit
    152148  {
    153     inline bool operator()(char c) const { return isdigit(c); }
     149    inline bool operator()(std::string::const_iterator i) const
     150    { return isdigit(*i); }
    154151  };
    155152
     
    158155  public:
    159156    notChar(char);
    160     inline bool operator()(char c) const { return c!=char_; }
     157    inline bool operator()(std::string::const_iterator i) const
     158    { return *i!=char_; }
    161159  private:
    162160    char char_;
     
    167165  public:
    168166    not2Char(char, char);
    169     inline bool operator()(char c) const
    170     { return c!=char1_ && c!=char2_; }
     167    inline bool operator()(std::string::const_iterator i) const
     168    { return *i!=char1_ && *i!=char2_; }
    171169  private:
    172170    const char char1_;
    173171    const char char2_;
     172  };
     173
     174  class Str
     175  {
     176  public:
     177    Str(std::string);
     178    inline bool operator()(std::string::const_iterator i) const
     179    { return (std::equal(str_.begin(), str_.end(), i)); }
     180
     181  private:
     182    const std::string str_;
     183  };
     184
     185  class not2Str
     186  {
     187  public:
     188    not2Str(std::string, std::string);
     189    inline bool operator()(std::string::const_iterator i) const
     190    {
     191      return !(std::equal(str1_.begin(), str1_.end(), i) ||
     192              std::equal(str2_.begin(), str2_.end(), i));
     193    }
     194
     195  private:
     196    const std::string str1_;
     197    const std::string str2_;
    174198  };
    175199
Note: See TracChangeset for help on using the changeset viewer.