Feature #917 » 0917_supportregexp.patch
src/actions.cpp (Arbeitskopie) | ||
---|---|---|
558 | 558 | |
559 | 559 |
bool Print::grepTag(const std::string& key) |
560 | 560 |
{ |
561 |
bool result=Params::instance().keys_.empty(); |
|
562 |
if (!result) |
|
563 |
for (Params::Keys::const_iterator k = Params::instance().keys_.begin(); |
|
564 |
!result && k != Params::instance().keys_.end(); ++k) { |
|
565 |
result = key.find(*k) != std::string::npos; |
|
561 |
if( Params::instance().keys_.empty()) |
|
562 |
return true; |
|
563 |
|
|
564 |
for( Params::Keys::const_iterator k = Params::instance().keys_.begin(); |
|
565 |
k != Params::instance().keys_.end(); ++k) |
|
566 |
{ |
|
567 |
if( 0 == regexec( &(*k), key.c_str(), 0, NULL, REG_NOTBOL | REG_NOTEOL)) |
|
568 |
return true; |
|
569 |
// result = key.find(*k) != std::string::npos; |
|
566 | 570 |
} |
567 |
return result ;
|
|
571 |
return false;
|
|
568 | 572 |
} |
569 | 573 | |
570 | 574 |
void Print::printMetadatum(const Exiv2::Metadatum& md, const Exiv2::Image* pImage) |
src/exiv2.cpp (Arbeitskopie) | ||
---|---|---|
47 | 47 |
#include <cstring> |
48 | 48 |
#include <cassert> |
49 | 49 |
#include <cctype> |
50 |
#include <regex.h> |
|
50 | 51 | |
51 | 52 |
#if defined(__MINGW32__) || defined(__MINGW64__) |
52 | 53 |
# ifndef __MINGW__ |
... | ... | |
352 | 353 |
case 'u': unknown_ = false; break; |
353 | 354 |
case 'f': force_ = true; fileExistsPolicy_ = overwritePolicy; break; |
354 | 355 |
case 'F': force_ = true; fileExistsPolicy_ = renamePolicy; break; |
355 |
case 'g': keys_.push_back(optarg); printMode_ = pmList; break;
|
|
356 |
case 'g': rc = evalKey(optarg); printMode_ = pmList; break;
|
|
356 | 357 |
case 'n': charset_ = optarg; break; |
357 | 358 |
case 'r': rc = evalRename(opt, optarg); break; |
358 | 359 |
case 't': rc = evalRename(opt, optarg); break; |
... | ... | |
410 | 411 |
return rc; |
411 | 412 |
} // Params::setLogLevel |
412 | 413 | |
414 |
int Params::evalKey( const std::string& optarg) |
|
415 |
{ |
|
416 |
// try to compile a reg-exp from the input argument and store it in the vector |
|
417 |
const size_t i = keys_.size(); |
|
418 |
keys_.resize(i + 1); |
|
419 |
regex_t *pRegex = &keys_[i]; |
|
420 |
int errcode = regcomp( pRegex, optarg.c_str(), REG_NOSUB); |
|
421 |
if( 0 == errcode) |
|
422 |
return 0; // no error |
|
423 |
|
|
424 |
// there was an error compiling the regexp |
|
425 |
size_t length = regerror (errcode, pRegex, NULL, 0); |
|
426 |
char *buffer = new char[ length]; |
|
427 |
regerror (errcode, pRegex, buffer, length); |
|
428 |
std::cerr << progname() |
|
429 |
<< ": " << _("Option") << " -g: " |
|
430 |
<< _("Invalid regexp") << " \"" << optarg << "\": " << buffer << "\n"; |
|
431 | ||
432 |
// free the memory and drop the regexp |
|
433 |
delete[] buffer; |
|
434 |
regfree( pRegex); |
|
435 |
keys_.resize(i); |
|
436 |
return 1; |
|
437 |
} // Params::evalKey |
|
438 | ||
413 | 439 |
int Params::evalRename(int opt, const std::string& optarg) |
414 | 440 |
{ |
415 | 441 |
int rc = 0; |
src/exiv2app.hpp (Arbeitskopie) | ||
---|---|---|
39 | 39 |
#include <vector> |
40 | 40 |
#include <set> |
41 | 41 |
#include <iostream> |
42 |
#include <regex.h> |
|
42 | 43 | |
43 | 44 |
// ***************************************************************************** |
44 | 45 |
// class definitions |
... | ... | |
125 | 126 |
//! Container for preview image numbers |
126 | 127 |
typedef std::set<int> PreviewNumbers; |
127 | 128 |
//! Container for keys |
128 |
typedef std::vector<std::string> Keys;
|
|
129 |
typedef std::vector<regex_t> Keys;
|
|
129 | 130 | |
130 | 131 |
/*! |
131 | 132 |
@brief Controls all access to the global Params instance. |
... | ... | |
261 | 262 |
//! @name Helpers |
262 | 263 |
//@{ |
263 | 264 |
int setLogLevel(const std::string& optarg); |
265 |
int evalKey( const std::string& optarg); |
|
264 | 266 |
int evalRename(int opt, const std::string& optarg); |
265 | 267 |
int evalAdjust(const std::string& optarg); |
266 | 268 |
int evalYodAdjust(const Yod& yod, const std::string& optarg); |