summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDavid Boddie <david.boddie@nokia.com>2011-01-20 17:40:52 (GMT)
committerDavid Boddie <david.boddie@nokia.com>2011-01-20 17:40:52 (GMT)
commit425a718facbb2b4a8f9919516b98257ef98c6182 (patch)
treeb030b896207b4a2c768e00f89496ffc9632a4161 /tools
parent92e0bfee7efb1505dbff6860f925445214fc7a54 (diff)
downloadQt-425a718facbb2b4a8f9919516b98257ef98c6182.zip
Qt-425a718facbb2b4a8f9919516b98257ef98c6182.tar.gz
Qt-425a718facbb2b4a8f9919516b98257ef98c6182.tar.bz2
Allowed the indentation of marked up code to be customized.
Marked up code is indented according to its indentation relative to the snippet markers (//! for example) in the quoted source code.
Diffstat (limited to 'tools')
-rw-r--r--tools/qdoc3/quoter.cpp20
-rw-r--r--tools/qdoc3/quoter.h5
2 files changed, 17 insertions, 8 deletions
diff --git a/tools/qdoc3/quoter.cpp b/tools/qdoc3/quoter.cpp
index 8e08e9a..b82b760 100644
--- a/tools/qdoc3/quoter.cpp
+++ b/tools/qdoc3/quoter.cpp
@@ -221,10 +221,13 @@ QString Quoter::quoteSnippet(const Location &docLocation, const QString &identif
QString comment = commentForCode();
QString delimiter = comment + QString(" [%1]").arg(identifier);
QString t;
+ int indent = 0;
while (!plainLines.isEmpty()) {
if (match(docLocation, delimiter, plainLines.first())) {
- getLine();
+ QString startLine = getLine();
+ while (indent < startLine.length() && startLine[indent] == QLatin1Char(' '))
+ indent++;
break;
}
getLine();
@@ -232,7 +235,7 @@ QString Quoter::quoteSnippet(const Location &docLocation, const QString &identif
while (!plainLines.isEmpty()) {
QString line = plainLines.first();
if (match(docLocation, delimiter, line)) {
- QString lastLine = getLine();
+ QString lastLine = getLine(indent);
int dIndex = lastLine.indexOf(delimiter);
if (dIndex > 0) {
// The delimiter might be preceded on the line by other
@@ -249,7 +252,7 @@ QString Quoter::quoteSnippet(const Location &docLocation, const QString &identif
return t;
}
- t += removeSpecialLines(line, comment);
+ t += removeSpecialLines(line, comment, indent);
}
failedAtEnd(docLocation, QString("snippet (%1)").arg(delimiter));
return t;
@@ -286,7 +289,7 @@ QString Quoter::quoteUntil( const Location& docLocation, const QString& command,
return t;
}
-QString Quoter::getLine()
+QString Quoter::getLine(int unindent)
{
if ( plainLines.isEmpty() )
return QString();
@@ -294,6 +297,11 @@ QString Quoter::getLine()
plainLines.removeFirst();
QString t = markedLines.takeFirst();
+ int i = 0;
+ while (i < unindent && i < t.length() && t[i] == QLatin1Char(' '))
+ i++;
+
+ t = t.mid(i);
t += QLatin1Char('\n');
codeLocation.advanceLines( t.count( QLatin1Char('\n') ) );
return t;
@@ -342,7 +350,7 @@ QString Quoter::commentForCode() const
return commentHash.value(suffix, "//!");
}
-QString Quoter::removeSpecialLines(const QString &line, const QString &comment)
+QString Quoter::removeSpecialLines(const QString &line, const QString &comment, int unindent)
{
QString t;
@@ -355,7 +363,7 @@ QString Quoter::removeSpecialLines(const QString &line, const QString &comment)
t += QLatin1Char('\n');
} else if (!trimmed.startsWith(comment)) {
// Ordinary code
- t += getLine();
+ t += getLine(unindent);
} else {
// Comments
if (line.contains(QLatin1Char('\n')))
diff --git a/tools/qdoc3/quoter.h b/tools/qdoc3/quoter.h
index e1728d1..5ce38ef 100644
--- a/tools/qdoc3/quoter.h
+++ b/tools/qdoc3/quoter.h
@@ -70,12 +70,13 @@ public:
QString quoteSnippet(const Location &docLocation, const QString &identifier);
private:
- QString getLine();
+ QString getLine(int unindent = 0);
void failedAtEnd( const Location& docLocation, const QString& command );
bool match( const Location& docLocation, const QString& pattern,
const QString& line );
QString commentForCode() const;
- QString removeSpecialLines(const QString &line, const QString &comment);
+ QString removeSpecialLines(const QString &line, const QString &comment,
+ int unindent = 0);
bool silent;
bool validRegExp;