summaryrefslogtreecommitdiffstats
path: root/tools/qdoc3/quoter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/qdoc3/quoter.cpp')
-rw-r--r--tools/qdoc3/quoter.cpp72
1 files changed, 38 insertions, 34 deletions
diff --git a/tools/qdoc3/quoter.cpp b/tools/qdoc3/quoter.cpp
index 84c6fb1..dadf67c 100644
--- a/tools/qdoc3/quoter.cpp
+++ b/tools/qdoc3/quoter.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -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
@@ -248,21 +251,8 @@ QString Quoter::quoteSnippet(const Location &docLocation, const QString &identif
}
return t;
}
- // Remove special macros to support Qt namespacing.
- if (line.startsWith("QT_BEGIN_NAMESPACE")) {
- getLine();
- } else if (line.startsWith("QT_END_NAMESPACE")) {
- getLine();
- t += QLatin1Char('\n');
- } else if (!line.startsWith(comment)) {
- // Ordinary code
- t += getLine();
- } else {
- // Normal comments
- if (line.contains(QLatin1Char('\n')))
- t += QLatin1Char('\n');
- getLine();
- }
+
+ t += removeSpecialLines(line, comment, indent);
}
failedAtEnd(docLocation, QString("snippet (%1)").arg(delimiter));
return t;
@@ -277,21 +267,7 @@ QString Quoter::quoteTo( const Location& docLocation, const QString& command,
if ( pattern.isEmpty() ) {
while ( !plainLines.isEmpty() ) {
QString line = plainLines.first();
- // Remove special macros to support Qt namespacing.
- if (line.startsWith("QT_BEGIN_NAMESPACE")) {
- getLine();
- } else if (line.startsWith("QT_END_NAMESPACE")) {
- getLine();
- t += QLatin1Char('\n');
- } else if (!line.startsWith(comment))
- // Ordinary code
- t += getLine();
- else {
- // Normal comments
- if (line.contains(QLatin1Char('\n')))
- t += QLatin1Char('\n');
- getLine();
- }
+ t += removeSpecialLines(line, comment);
}
} else {
while ( !plainLines.isEmpty() ) {
@@ -313,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();
@@ -321,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;
@@ -369,4 +350,27 @@ QString Quoter::commentForCode() const
return commentHash.value(suffix, "//!");
}
+QString Quoter::removeSpecialLines(const QString &line, const QString &comment, int unindent)
+{
+ QString t;
+
+ // Remove special macros to support Qt namespacing.
+ QString trimmed = line.trimmed();
+ if (trimmed.startsWith("QT_BEGIN_NAMESPACE")) {
+ getLine();
+ } else if (trimmed.startsWith("QT_END_NAMESPACE")) {
+ getLine();
+ t += QLatin1Char('\n');
+ } else if (!trimmed.startsWith(comment)) {
+ // Ordinary code
+ t += getLine(unindent);
+ } else {
+ // Comments
+ if (line.contains(QLatin1Char('\n')))
+ t += QLatin1Char('\n');
+ getLine();
+ }
+ return t;
+}
+
QT_END_NAMESPACE