From dfa3a285c140f57dfa08f4465ab1432853e92551 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Thu, 18 Feb 2021 21:15:21 +0100 Subject: Refactoring: replace QRegExp by std::regex in vhdlcode.l --- src/util.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/util.h | 5 +++++ src/vhdlcode.l | 35 ++++++++++++++++++++--------------- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index e8fcab9..36866dd 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -7485,3 +7485,42 @@ QCString removeEmptyLines(const QCString &s) //printf("removeEmptyLines(%s)=%s\n",s.data(),out.data()); return out.data(); } + +/// split input string \a s by string delimiter \a delimiter. +/// returns a vector of non-empty strings that are between the delimiters +StringVector split(const std::string &s,const std::string &delimiter) +{ + StringVector result; + size_t prev = 0, pos = 0, len = s.length(); + do + { + pos = s.find(delimiter, prev); + if (pos == std::string::npos) pos = len; + if (pos>prev) result.push_back(s.substr(prev,pos-prev)); + prev = pos + delimiter.length(); + } + while (pos #include #include +#include #include #include "types.h" @@ -458,6 +459,10 @@ bool openOutputFile(const char *outFile,QFile &f); void writeExtraLatexPackages(FTextStream &t); void writeLatexSpecialFormulaChars(FTextStream &t); +StringVector split(const std::string &s,const std::string &delimiter); +StringVector split(const std::string &s,const std::regex &delimiter); +int findIndex(StringVector &sv,const std::string &s); + bool recognizeFixedForm(const char* contents, FortranFormat format); FortranFormat convertFileNameFortranParserCode(QCString fn); diff --git a/src/vhdlcode.l b/src/vhdlcode.l index 59872f3..37cc720 100644 --- a/src/vhdlcode.l +++ b/src/vhdlcode.l @@ -30,6 +30,7 @@ #include #include +#include /* * includes @@ -37,7 +38,6 @@ #include #include #include -#include #include #include @@ -226,9 +226,8 @@ XILINX "INST"|"NET"|"PIN"|"BLKNM"|"BUFG"|"COLLAPSE"|"CPLD"|"COMPGRP"|"CONFI [^()\n,--]* { /* write and link a port map lines */ QCString tt(yytext); VhdlDocGen::deleteAllChars(tt,','); - QRegExp r("=>"); - QCStringList ql=QCStringList::split(r,tt); - if (ql.count()>=2) + auto ql = split(tt.str(),"=>"); + if (ql.size()>=2) { unsigned int index=0; QCString t1=ql[0]; @@ -355,17 +354,17 @@ XILINX "INST"|"NET"|"PIN"|"BLKNM"|"BUFG"|"COLLAPSE"|"CPLD"|"COMPGRP"|"CONFI } {ENDEFUNC} { - QRegExp regg("[\\s]"); QCString tt(yytext); codifyLines(yyscanner,yytext,yyextra->currClass.data()); tt=tt.lower(); VhdlDocGen::deleteAllChars(tt,';'); tt.stripWhiteSpace(); - QCStringList ql=QCStringList::split(regg,tt); - int index=ql.findIndex(QCString("if"))+1; - index+=ql.findIndex(QCString("case"))+1; - index+=ql.findIndex(QCString("loop"))+1; - index+=ql.findIndex(QCString("generate"))+1; + static std::regex regg("[[:space:]]+"); + auto ql = split(tt.str(),regg); + int index=findIndex(ql,"if")+1; + index+=findIndex(ql,"case")+1; + index+=findIndex(ql,"loop")+1; + index+=findIndex(ql,"generate")+1; if (index==0) { BEGIN(Bases); @@ -955,18 +954,18 @@ static bool checkVhdlString(yyscan_t yyscanner,QCString &name) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; if (name.isEmpty()) return false; - static QRegExp regg("[\\s\"]"); int len=name.length(); if (name.at(0)=='"' && name.at(len-1)=='"' && len > 2) { - QCStringList qrl=QCStringList::split(regg,name); + std::string inside = name.str().substr(1,len-2); + static std::regex regg("[[:space:]]+"); + auto qrl=split(inside,regg); if (VhdlDocGen::isNumber(qrl[0])) { yyextra->code->codify("\""); startFontClass(yyscanner,"vhdllogic"); - QCString mid=name.mid(1,len-2); //" 1223 " - yyextra->code->codify(mid.data()); + yyextra->code->codify(inside.c_str()); endFontClass(yyscanner); yyextra->code->codify("\""); } @@ -1329,7 +1328,13 @@ static void generateClassOrGlobalLink(yyscan_t yyscanner,CodeOutputInterface &ol cd = getClass(className.data()); if (!cd && curr_class) { - if (QCString(curr_class).contains(QRegExp("::"+QCString(clName)+"$"))) cd = getClass(curr_class); + QCString cls = curr_class; + QCString suffix = "::"; + suffix+=clName; + if (cls.right(suffix.length())==suffix) + { + cd = getClass(curr_class); + } } while (cd) -- cgit v0.12