int main(int, char**) { gcore::String exp = "fred(?!eric)"; gcore::Rex re0(exp); gcore::StringList strs; strs.push_back("frederic"); strs.push_back("fredo"); for (size_t i=0; i<strs.size(); ++i) { std::cout << "\"" << strs[i] << "\" =~ /" << exp << "/" << std::endl; if (re0.match(strs[i])) { std::cout << " Matched" << std::endl; } else { std::cout << " Not matched" << std::endl; } } gcore::Rex re1(RAW("(\d\d):(\d\d)")); //fprintf(stderr, "Error? %s\n", re1.getError(err)); gcore::RexMatch md; gcore::String str = " Time -> 10:23 "; if (re1.search(str, md, 0, 3, str.length()-3)) { fprintf(stderr, "\"%s", md.pre().c_str() ); fprintf(stderr, "<<%s>>", md.group(0).c_str() ); fprintf(stderr, "%s\"\n", md.post().c_str()); fprintf(stderr, "Found1: \'%s\'\n", md.group(1).c_str() ); fprintf(stderr, "Found2: \'%s\'\n", md.group(2).c_str() ); //fprintf(stderr, "Substitute: %s\n", re1.substitute(md, "Current time is \\1:\\2, removed \"\\`\" and \"\\'\", whole match \"\\&\"").c_str()); fprintf(stderr, "Substitute: %s\n", re1.substitute(md, RAW("Current time is \1:\2, removed '\`' and '\'', whole match '\&'")).c_str()); }
void QgsValueMapConfigDlg::loadFromCSVButtonPushed() { QString fileName = QFileDialog::getOpenFileName( 0, tr( "Select a file" ) ); if ( fileName.isNull() ) return; QFile f( fileName ); if ( !f.open( QIODevice::ReadOnly ) ) { QMessageBox::information( NULL, tr( "Error" ), tr( "Could not open file %1\nError was:%2" ).arg( fileName, f.errorString() ), QMessageBox::Cancel ); return; } QTextStream s( &f ); s.setAutoDetectUnicode( true ); QRegExp re0( "^([^;]*);(.*)$" ); re0.setMinimal( true ); QRegExp re1( "^([^,]*),(.*)$" ); re1.setMinimal( true ); QMap<QString, QVariant> map; s.readLine(); while ( !s.atEnd() ) { QString l = s.readLine().trimmed(); QString key, val; if ( re0.indexIn( l ) >= 0 && re0.captureCount() == 2 ) { key = re0.cap( 1 ).trimmed(); val = re0.cap( 2 ).trimmed(); } else if ( re1.indexIn( l ) >= 0 && re1.captureCount() == 2 ) { key = re1.cap( 1 ).trimmed(); val = re1.cap( 2 ).trimmed(); } else continue; if (( key.startsWith( "\"" ) && key.endsWith( "\"" ) ) || ( key.startsWith( "'" ) && key.endsWith( "'" ) ) ) { key = key.mid( 1, key.length() - 2 ); } if (( val.startsWith( "\"" ) && val.endsWith( "\"" ) ) || ( val.startsWith( "'" ) && val.endsWith( "'" ) ) ) { val = val.mid( 1, val.length() - 2 ); } map[ key ] = val; } updateMap( map, false ); }