Skip to content

Commit f27dbdb

Browse files
committed
Refactoring: replace QRegExp by std::regex in scanner.l
1 parent 58d1307 commit f27dbdb

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/scanner.l

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*****************************************************************************
22
*
3-
*
4-
*
5-
* Copyright (C) 1997-2015 by Dimitri van Heesch.
3+
* Copyright (C) 1997-2021 by Dimitri van Heesch.
64
*
75
* Permission to use, copy, modify, and distribute this software and its
86
* documentation under the terms of the GNU General Public License is hereby
@@ -31,13 +29,13 @@
3129
#include <algorithm>
3230
#include <vector>
3331
#include <utility>
32+
#include <regex>
3433

3534
#include <stdio.h>
3635
#include <stdlib.h>
3736
#include <assert.h>
3837
#include <ctype.h>
3938

40-
#include <qregexp.h>
4139
#include <qfile.h>
4240

4341
#include "scanner.h"
@@ -3741,9 +3739,9 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
37413739
}
37423740
else
37433741
{
3744-
static QRegExp re("@[0-9]+$");
3742+
static std::regex re("@[0-9]+$");
37453743
if (!yyextra->isTypedef && yyextra->memspecEntry &&
3746-
yyextra->memspecEntry->name.find(re)==-1) // not typedef or anonymous type (see bug691071)
3744+
!std::regex_search(yyextra->memspecEntry->name.str(),re)) // not typedef or anonymous type (see bug691071)
37473745
{
37483746
// enabled the next two lines for bug 623424
37493747
yyextra->current->doc.resize(0);
@@ -4833,10 +4831,16 @@ OPERATOR "operator"{B}*({ARITHOP}|{ASSIGNOP}|{LOGICOP}|{BITOP})
48334831
yyextra->current->fileName = yyextra->yyFileName;
48344832
yyextra->current->startLine = yyextra->yyBegLineNr;
48354833
yyextra->current->startColumn = yyextra->yyBegColNr;
4836-
static QRegExp re("([^)]*[*&][^)]*)"); // (...*...)
4834+
static std::regex re("\\([^)]*[*&][^]*\\)");
4835+
std::smatch match;
4836+
std::string type = yyextra->current->type.str();
4837+
int ti=-1;
4838+
if (std::regex_search(type,match,re))
4839+
{
4840+
ti = (int)match.position();
4841+
}
48374842
int ts=yyextra->current->type.find('<');
48384843
int te=yyextra->current->type.findRev('>');
4839-
int ti=yyextra->current->type.find(re,0);
48404844
48414845
// bug677315: A<int(void *, char *)> get(); is not a function pointer
48424846
bool isFunction = ti==-1 || // not a (...*...) pattern
@@ -6891,28 +6895,29 @@ static void splitKnRArg(yyscan_t yyscanner,QCString &oldStyleArgPtr,QCString &ol
68916895
int si = yyextra->current->args.length();
68926896
if (yyextra->oldStyleArgType.isEmpty()) // new argument
68936897
{
6894-
static QRegExp re("([^)]*)");
6895-
int bi1 = yyextra->current->args.findRev(re);
6896-
int bi2 = bi1!=-1 ? yyextra->current->args.findRev(re,bi1-1) : -1;
6898+
static std::regex re("(\\([^)]*\\))[[:space:]]*(\\([^)]*\\))?");
6899+
std::string args = yyextra->current->args.str();
6900+
std::smatch matches;
6901+
std::regex_search(args,matches,re);
68976902
char c;
6898-
if (bi1!=-1 && bi2!=-1) // found something like "int (*func)(int arg)"
6903+
if (matches.length()==3 && !matches[2].str().empty()) // found something like "int (*func)(int arg)"
68996904
{
6900-
int s=bi2+1;
6905+
size_t s = matches.position()+1; // keep opening (
69016906
yyextra->oldStyleArgType = yyextra->current->args.left(s);
6902-
int i=s;
6907+
int i=(int)s;
69036908
while (i<si && ((c=yyextra->current->args.at(i))=='*' || isspace((uchar)c))) i++;
69046909
yyextra->oldStyleArgType += yyextra->current->args.mid(s,i-s);
69056910
s=i;
69066911
while (i<si && isId(yyextra->current->args.at(i))) i++;
69076912
oldStyleArgName = yyextra->current->args.mid(s,i-s);
69086913
yyextra->oldStyleArgType+=yyextra->current->args.mid(i);
69096914
}
6910-
else if (bi1!=-1) // redundant braces like in "int (*var)"
6915+
else if (matches.length()==3) // redundant braces like in "int (*var)"
69116916
{
6912-
int s=bi1;
6917+
size_t s = matches.position(); // strip opening (
69136918
yyextra->oldStyleArgType = yyextra->current->args.left(s);
69146919
s++;
6915-
int i=s+1;
6920+
int i=(int)s+1;
69166921
while (i<si && ((c=yyextra->current->args.at(i))=='*' || isspace((uchar)c))) i++;
69176922
yyextra->oldStyleArgType += yyextra->current->args.mid(s,i-s);
69186923
s=i;

0 commit comments

Comments
 (0)