Changeset 523
- Timestamp:
- Dec 25, 2007, 2:51:54 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Configuration.cc
r522 r523 66 66 { 67 67 if (const std::pair<std::string,std::string>* dict=dictionary(file_name)) 68 try { 69 file_name = translate(file_name, *dict); 70 } 71 catch (std::runtime_error& e) { 72 std::stringstream mess; 73 mess << "svndigest: invalid config file: " 74 << "expression " << dict->second << " is invalid"; 75 if (e.what()[0]) 76 mess << "because " << e.what() << " is a too large."; 77 else 78 mess << "."; 79 throw std::runtime_error(mess.str()); 80 } 68 file_name = translate(file_name, *dict); 81 69 for (String2Codons::const_iterator i(string2codons_.begin()); 82 70 i!=string2codons_.end(); ++i) { … … 125 113 { 126 114 set_default(); 115 validate_dictionary(); 127 116 } 128 117 … … 268 257 } 269 258 } 259 validate_dictionary(); 270 260 } 271 261 … … 300 290 size_t n = 0; 301 291 ss >> n; 302 if (n>vec.size() ){292 if (n>vec.size() || n==0){ 303 293 std::stringstream mess; 304 mess << n; 305 throw std::runtime_error(mess.str()); 306 } 307 if (n) { 308 res += vec[n-1]; 294 mess << "svndigest: invalid config file: " 295 << "expression " << dic.second << " is invalid"; 296 if (n) 297 mess << "because " << n << " is a too large."; 298 throw std::runtime_error(""); 299 } 300 res += vec[n-1]; 301 ++i; 302 if (n>9){ 309 303 ++i; 310 if (n>9 ){304 if (n>99) 311 305 ++i; 312 if (n>99) 313 ++i; 314 } 315 } 316 else 317 throw std::runtime_error(""); 306 307 } 318 308 } 319 309 else … … 412 402 413 403 404 void Configuration::validate_dictionary(void) const 405 { 406 VectorPair::const_iterator end(dictionary_.end()); 407 for (VectorPair::const_iterator iter(dictionary_.begin());iter!=end;++iter){ 408 std::string word(iter->first); 409 replace(word, "*", ""); 410 replace(word, "?", ""); 411 // throws if dictionary is invalid 412 translate(word, *iter); 413 } 414 415 } 416 417 414 418 std::ostream& operator<<(std::ostream& os, const Configuration& conf) 415 419 { -
trunk/lib/Configuration.h
r522 r523 104 104 Translate string \a str using dictionary \a dict 105 105 106 \note \a str must be equal to d.first, or behavior is unspecified. 106 \note \a str must be equal to d.first (see function equal), 107 or behavior is unspecified. 107 108 108 109 \throw if a '$' character is not followed by a positive integer … … 112 113 const std::pair<std::string, std::string>& d) const; 113 114 115 void validate_dictionary(void) const; 116 114 117 static Configuration* instance_; 115 118 -
trunk/lib/utility.cc
r519 r523 102 102 equal(first1+1, end1, first2+1, end2) ) 103 103 return true; 104 if (first1!=end1 && *first1=='*' && first2!=end2 && 105 equal(first1, end1, first2+1, end2) ) 104 if ( (first1!=end1 && first2!=end2 && (*first1=='*'|| *first2=='*') ) && 105 (equal(first1+1, end1, first2, end2) || 106 equal(first1, end1, first2+1, end2)) 107 ) 106 108 return true; 107 if (first2!=end2 && *first2=='*' && first1!=end1 &&108 equal(first1+1, end1, first2, end2) )109 return true;110 111 109 return false; 112 110 } -
trunk/test/utility_test.cc
r519 r523 47 47 ok &= test_equal(true,"peter", "p*"); 48 48 ok &= test_equal(false,"peter", "p*j"); 49 ok &= test_equal(true,"peter", "*peter"); 49 50 50 51 std::vector<std::string> vec;
Note: See TracChangeset
for help on using the changeset viewer.