0

Example:

QFile controller_selected_file(loaded_file);

if (controller_selected_file.open(QIODevice::ReadOnly))
{
    // grab a data
    QTextStream in(&controller_selected_file);

    // read all
    QString read_data = in.readAll();

    // Regex for match function "public function something()"
    QRegExp reg("(static|public|final)(.*)function(.*)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]", Qt::CaseInsensitive);

    // Read by regex and file
    reg.indexIn(read_data);

    QStringList data_render = reg.capturedTexts();

    qDebug() << data_render;

    qDebug() << data_render[0];
    qDebug() << data_render[1];
    qDebug() << data_render[3];

    // ...
}

I want grab in a file all where appears public function somefunction() and another public function something($a,$b = "example") where appears in file, but I only receives full of file string or receive only public on first array.

So I want grab all data where appears as arrays:

public function somefunction().

So in simple, parse all function names in file.

Full function of regex in QRegexp expression:

(static|public|final)(.*)function(.*)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]

Edit: I want grab all appears in strings on PHP file. Problems appears when you receive all strings in file instead strings defined with regular expression.

Thank you for respect!

Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53

1 Answers1

0

If I understand you question right, I think you need to modify the regex as QRegExp reg( "((static|public|final).*function.*\([\\w\\s,]*\))" );

With the above RegExp, you can match something like static function newFunc( int gen_x, float A_b_c )

QFile controller_selected_file(loaded_file);

if (controller_selected_file.open(QIODevice::ReadOnly)) {
    // grab a data
    QTextStream in(&controller_selected_file);

    // read all
    QString read_data = in.readAll();

    // Regex for match function "public function something()"
    QRegExp reg( "((static|public|final).*function.*\([\\w\\s,]*\))" );

    // Read by regex and file
    qDebug() << reg.indexIn( read_data );
    qDebug() << reg.cap( 1 );
    // ...
}

Say read_data contains the following text

"This is some text: static function newFunc( int generic, float special )
And it also contains some other text, but that is not important"

Then the output will be

19
"static function newFunc( int generic, float special )"

I hope this is what you want.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Marcus
  • 1,685
  • 1
  • 18
  • 33