Changeset 507 for trunk


Ignore:
Timestamp:
Dec 8, 2007, 4:58:19 AM (14 years ago)
Author:
Peter Johansson
Message:

added function comparing strings with wildcards - needed for #122

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility.cc

    r482 r507  
    8989
    9090
     91  bool equal(std::string::const_iterator first1,
     92             std::string::const_iterator end1,
     93             std::string::const_iterator first2,
     94             std::string::const_iterator end2)
     95  {
     96    if (first1==end1 && first2==end2)
     97      return true;
     98    if (first1!=end1 && first2!=end2 &&
     99        (*first1==*first2 || *first1=='*' || *first2=='*') &&
     100        equal(first1+1, end1, first2+1, end2) )
     101      return true;
     102    if (first1!=end1 && *first1=='*' && first2!=end2 &&
     103        equal(first1, end1, first2+1, end2) )
     104      return true;
     105    if (first2!=end2 && *first2=='*' && first1!=end1 &&
     106        equal(first1+1, end1, first2, end2) )
     107      return true;
     108       
     109    return false;
     110  }
     111
     112
    91113  std::string file_name(const std::string& full_path)
    92114  {
  • trunk/lib/utility.h

    r482 r507  
    6969   */
    7070  std::string directory_name(std::string path);
     71
     72  /**
     73     Function to compare strings. Strings may contain '*'.
     74
     75     \return true if \a a and \a b are identical.
     76   */
     77  bool equal(std::string::const_iterator first1,
     78             std::string::const_iterator end1,
     79             std::string::const_iterator first2,
     80             std::string::const_iterator end2);
    7181
    7282  ///
  • trunk/test/utility_test.cc

    r439 r507  
    2828
    2929bool test_hex(int, u_int, std::string);
     30bool test_equal(bool, std::string, std::string);
    3031
    3132int main(const int argc,const char* argv[])
     
    3738  ok &= test_hex(16,2, "10");
    3839
     40  ok &= test_equal(true,"peter", "peter");
     41  ok &= test_equal(false,"peter", "peterj");
     42  ok &= test_equal(true,"p*", "peterj");
     43  ok &= test_equal(true,"peter", "p*");
     44  ok &= test_equal(false,"peter", "p*j");
     45
    3946  if (ok)
    4047    return 0;
    4148  return 1;
     49}
     50
     51bool test_equal(bool answ, std::string a, std::string b)
     52{
     53  if (theplu::svndigest::equal(a.begin(), a.end(), b.begin(), b.end())==answ)
     54    return true;
     55  std::cerr << "equal(" << a << ", " << b << ") results "
     56            << theplu::svndigest::equal(a.begin(), a.end(),b.begin(), b.end())
     57            << ". Expects " << answ << std::endl;
     58  return false;
    4259}
    4360
     
    5168  return false;
    5269}
     70
Note: See TracChangeset for help on using the changeset viewer.