Skip to content

Commit 23c71a3

Browse files
committed
Moved stripIndentation() to util, make it safe for empty input
1 parent c75c384 commit 23c71a3

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

src/pyscanner.l

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ static void initSpecialBlock(yyscan_t yyscanner);
141141
static void searchFoundDef(yyscan_t yyscanner);
142142
static void searchFoundClass(yyscan_t yyscanner);
143143
static QCString findPackageScope(yyscan_t yyscanner,const char *fileName);
144-
static void stripIndentation(QCString &doc,const int indentationLevel);
145144

146145
static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size);
147146

@@ -1528,55 +1527,6 @@ static inline int computeIndent(const char *s)
15281527
return col;
15291528
}
15301529

1531-
// strip up to \a indentationLevel spaces from each line in \a doc (excluding the first line)
1532-
static void stripIndentation(QCString &doc,const int indentationLevel)
1533-
{
1534-
if (indentationLevel <= 0) return; // nothing to strip
1535-
1536-
// by stripping content the string will only become shorter so we write the results
1537-
// back into the input string and then resize it at the end.
1538-
char c;
1539-
const char *src = doc.data();
1540-
char *dst = doc.rawData();
1541-
bool insideIndent = false; // skip the initial line from stripping
1542-
int cnt = 0;
1543-
while ((c=*src++)!=0)
1544-
{
1545-
// invariant: dst<=src
1546-
switch(c)
1547-
{
1548-
case '\n':
1549-
*dst++ = c;
1550-
insideIndent = true;
1551-
cnt = indentationLevel;
1552-
break;
1553-
case ' ':
1554-
if (insideIndent)
1555-
{
1556-
if (cnt>0) // count down the spacing until the end of the indent
1557-
{
1558-
cnt--;
1559-
}
1560-
else // reached the end of the indent, start of the part of the line to keep
1561-
{
1562-
insideIndent = false;
1563-
*dst++ = c;
1564-
}
1565-
}
1566-
else // part after indent, copy to the output
1567-
{
1568-
*dst++ = c;
1569-
}
1570-
break;
1571-
default:
1572-
insideIndent = false;
1573-
*dst++ = c;
1574-
break;
1575-
}
1576-
}
1577-
doc.resize(dst-doc.data()+1);
1578-
}
1579-
15801530
static QCString findPackageScopeFromPath(yyscan_t yyscanner,const QCString &path)
15811531
{
15821532
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;

src/util.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7920,6 +7920,55 @@ QCString stripIndentation(const QCString &s)
79207920
return result.data();
79217921
}
79227922

7923+
// strip up to \a indentationLevel spaces from each line in \a doc (excluding the first line)
7924+
static void stripIndentation(QCString &doc,const int indentationLevel)
7925+
{
7926+
if (indentationLevel <= 0 || doc.isEmpty()) return; // nothing to strip
7927+
7928+
// by stripping content the string will only become shorter so we write the results
7929+
// back into the input string and then resize it at the end.
7930+
char c;
7931+
const char *src = doc.data();
7932+
char *dst = doc.rawData();
7933+
bool insideIndent = false; // skip the initial line from stripping
7934+
int cnt = 0;
7935+
while ((c=*src++)!=0)
7936+
{
7937+
// invariant: dst<=src
7938+
switch(c)
7939+
{
7940+
case '\n':
7941+
*dst++ = c;
7942+
insideIndent = true;
7943+
cnt = indentationLevel;
7944+
break;
7945+
case ' ':
7946+
if (insideIndent)
7947+
{
7948+
if (cnt>0) // count down the spacing until the end of the indent
7949+
{
7950+
cnt--;
7951+
}
7952+
else // reached the end of the indent, start of the part of the line to keep
7953+
{
7954+
insideIndent = false;
7955+
*dst++ = c;
7956+
}
7957+
}
7958+
else // part after indent, copy to the output
7959+
{
7960+
*dst++ = c;
7961+
}
7962+
break;
7963+
default:
7964+
insideIndent = false;
7965+
*dst++ = c;
7966+
break;
7967+
}
7968+
}
7969+
doc.resize(dst-doc.data()+1);
7970+
}
7971+
79237972

79247973
bool fileVisibleInIndex(const FileDef *fd,bool &genSourceFile)
79257974
{

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ QCString processMarkup(const QCString &s);
472472
bool protectionLevelVisible(Protection prot);
473473

474474
QCString stripIndentation(const QCString &s);
475+
void stripIndentation(QCString &doc,const int indentationLevel);
475476

476477
QCString getDotImageExtension(void);
477478

0 commit comments

Comments
 (0)