Supportnet Computer
Planet of Tech

Supportnet / Forum / Anwendungen(Java,C++...)

kleines Projekt in C++





Frage

Hallo, ich habe hier ein kleines Projekt in C++, welches reguläre Ausdrücke nutzt. Dazu habe ich mir GRETA ( http://research.microsoft.com/proje...tauserguide.htm ) geholt. Die Ausdrücke klappen recht gut, doch schaffe ich es nicht mehrere Matches abzufragen. Er gibt mir immer nur ein Ergebniss. Ich bräuchte aber sowas wie in PHP "preg_match_all()" mein Progcode: void Set::load(char* _name) { strstream buffer; buffer << this->path << "/" << _name << ends; char* file = buffer.str(); #ifdef _DEBUG fprintf(stderr,"Set : loading file \""); fprintf(stderr,file); fprintf(stderr,"\"\n"); #endif int fh, count = 0; char reader[10240]; char all[102400]=""; if( (fh = _open( file, _O_RDONLY )) != -1 ) { while (!_eof(fh))// && ((count=_read(fh,reader,10240)) >= 0) ) { if( (count = _read( fh, reader, 10240 )) == -1 ) { perror( "Read error" ); break; } strncat(all,reader,count); } _close( fh ); #ifdef _DEBUG fprintf(stderr,"Set : file loaded\n"); fprintf(stderr,"Set : splitting file\n"); #endif regex::match_results results; string str( all ); static const regex::rpattern pat( "\\[block ([a-z_]*)\\](.*)\\[/block\\]" ); // The double-escapes are necessary to satisfy the compiler. regex::match_results::backref_type br = pat.match( str, results ); if( br.matched ) { #ifdef _DEBUG strstream b; b << pat.cgroups() << ends; strstream buffer; buffer << results.cbackrefs() << ends; fprintf(stderr,"Set : match success!\n" ); fprintf(stderr,"Gesammtreferenzen: "); fprintf(stderr,buffer.str()); fprintf(stderr," Groups: "); fprintf(stderr,b.str()); fprintf(stderr,"\n"); for(uint i = 0; i< results.cbackrefs(); ++i ) { br = results.backref(i); string str2(br.str()); fprintf(stderr,"\n*********************\n"); fprintf(stderr,str2.c_str()); fprintf(stderr,"\n*********************\n\n"); } #endif // here follow the real code } else { #ifdef _DEBUG fprintf(stderr, "Set : match failed!\n" ); #endif // no block found ! } } buffer.freeze(0); } gut, ist noch nicht perfekt, aber derzeit gehts mir nur um die regulären Ausdrücke. Irgendjemand eine Idee ?

Antwort 1 von ooooooooooooooooooooooooo

00000 wieder nach oben ooooo

Ich möchte kostenlos eine Frage an die Mitglieder stellen:


Ähnliche Themen:


Suche in allen vorhandenen Beiträgen: