Skip to content

Commit 46599bf

Browse files
committed
Refactoring: replace QRegExp by std::regex in classdef.cpp
1 parent 37deea7 commit 46599bf

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

src/classdef.cpp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
#include <cstdio>
1919
#include <algorithm>
20+
#include <regex>
2021

2122
#include <qfile.h>
2223
#include <qfileinfo.h>
23-
#include <qregexp.h>
2424
#include "classdef.h"
2525
#include "classlist.h"
2626
#include "entry.h"
@@ -1630,18 +1630,22 @@ void ClassDefImpl::writeInheritanceGraph(OutputList &ol) const
16301630
ol.startParagraph();
16311631
//parseText(ol,theTranslator->trInherits()+" ");
16321632

1633-
QCString inheritLine = theTranslator->trInheritsList((int)m_impl->inherits.size());
1634-
QRegExp marker("@[0-9]+");
1635-
int index=0,newIndex,matchLen;
1633+
std::string inheritLine = theTranslator->trInheritsList((int)m_impl->inherits.size()).str();
1634+
static std::regex marker("@[[:digit:]]+");
1635+
std::sregex_iterator it(inheritLine.begin(),inheritLine.end(),marker);
1636+
std::sregex_iterator end;
1637+
size_t index=0;
16361638
// now replace all markers in inheritLine with links to the classes
1637-
while ((newIndex=marker.match(inheritLine,index,&matchLen))!=-1)
1639+
for ( ; it!=end ; ++it)
16381640
{
1639-
ol.parseText(inheritLine.mid(index,newIndex-index));
1640-
bool ok;
1641-
uint entryIndex = inheritLine.mid(newIndex+1,matchLen-1).toUInt(&ok);
1642-
BaseClassDef &bcd=m_impl->inherits.at(entryIndex);
1643-
if (ok)
1641+
const auto &match = *it;
1642+
size_t newIndex = match.position();
1643+
size_t matchLen = match.length();
1644+
ol.parseText(inheritLine.substr(index,newIndex-index));
1645+
unsigned long entryIndex = std::stoul(match.str().substr(1));
1646+
if (entryIndex<(unsigned long)m_impl->inherits.size())
16441647
{
1648+
BaseClassDef &bcd=m_impl->inherits[entryIndex];
16451649
ClassDef *cd=bcd.classDef;
16461650

16471651
// use the class name but with the template arguments as given
@@ -1663,30 +1667,34 @@ void ClassDefImpl::writeInheritanceGraph(OutputList &ol) const
16631667
}
16641668
else
16651669
{
1666-
err("invalid marker %d in inherits list!\n",entryIndex);
1670+
err("invalid marker %zu in inherits list!\n",entryIndex);
16671671
}
16681672
index=newIndex+matchLen;
16691673
}
1670-
ol.parseText(inheritLine.right(inheritLine.length()-(uint)index));
1674+
ol.parseText(inheritLine.substr(index));
16711675
ol.endParagraph();
16721676
}
16731677

16741678
// write subclasses
16751679
if (!m_impl->inheritedBy.empty())
16761680
{
16771681
ol.startParagraph();
1678-
QCString inheritLine = theTranslator->trInheritedByList((int)m_impl->inheritedBy.size());
1679-
QRegExp marker("@[0-9]+");
1680-
int index=0,newIndex,matchLen;
1682+
std::string inheritLine = theTranslator->trInheritedByList((int)m_impl->inheritedBy.size()).str();
1683+
static std::regex marker("@[[:digit:]]+");
1684+
std::sregex_iterator it(inheritLine.begin(),inheritLine.end(),marker);
1685+
std::sregex_iterator end;
1686+
size_t index=0;
16811687
// now replace all markers in inheritLine with links to the classes
1682-
while ((newIndex=marker.match(inheritLine,index,&matchLen))!=-1)
1688+
for ( ; it!=end ; ++it)
16831689
{
1684-
ol.parseText(inheritLine.mid(index,newIndex-index));
1685-
bool ok;
1686-
uint entryIndex = inheritLine.mid(newIndex+1,matchLen-1).toUInt(&ok);
1687-
BaseClassDef &bcd=m_impl->inheritedBy.at(entryIndex);
1688-
if (ok)
1690+
const auto &match = *it;
1691+
size_t newIndex = match.position();
1692+
size_t matchLen = match.length();
1693+
ol.parseText(inheritLine.substr(index,newIndex-index));
1694+
unsigned long entryIndex = std::stoul(match.str().substr(1));
1695+
if (entryIndex<(unsigned long)m_impl->inherits.size())
16891696
{
1697+
BaseClassDef &bcd=m_impl->inheritedBy[entryIndex];
16901698
ClassDef *cd=bcd.classDef;
16911699
if (cd->isLinkable())
16921700
{
@@ -1698,9 +1706,13 @@ void ClassDefImpl::writeInheritanceGraph(OutputList &ol) const
16981706
}
16991707
writeInheritanceSpecifier(ol,bcd);
17001708
}
1709+
else
1710+
{
1711+
err("invalid marker %zu in inheritedBy list!\n",entryIndex);
1712+
}
17011713
index=newIndex+matchLen;
17021714
}
1703-
ol.parseText(inheritLine.right(inheritLine.length()-(uint)index));
1715+
ol.parseText(inheritLine.substr(index));
17041716
ol.endParagraph();
17051717
}
17061718

0 commit comments

Comments
 (0)