summaryrefslogtreecommitdiffstats
path: root/tools/qdoc3/quoter.cpp
diff options
context:
space:
mode:
authorJoona Petrell <joona.t.petrell@nokia.com>2011-02-22 04:12:05 (GMT)
committerJoona Petrell <joona.t.petrell@nokia.com>2011-02-22 04:12:05 (GMT)
commitbf9ca539dc4c5efff801856ad9d3f7e14dabad26 (patch)
treea5ae494b6e8a2b33f4345f484ba2ead04aca761e /tools/qdoc3/quoter.cpp
parentb254be20c03d4dbfc1803cd40dc95d52115b955c (diff)
parenta34e2ab6f50cc91a4fca5cd7fd7bd22e6495b0c1 (diff)
downloadQt-bf9ca539dc4c5efff801856ad9d3f7e14dabad26.zip
Qt-bf9ca539dc4c5efff801856ad9d3f7e14dabad26.tar.gz
Qt-bf9ca539dc4c5efff801856ad9d3f7e14dabad26.tar.bz2
Merge branch '4.7' of git://scm.dev.nokia.troll.no/qt/qt into 4.7
Conflicts: tools/qml/qml.pri
Diffstat (limited to 'tools/qdoc3/quoter.cpp')
-rw-r--r--tools/qdoc3/quoter.cpp79
1 files changed, 43 insertions, 36 deletions
diff --git a/tools/qdoc3/quoter.cpp b/tools/qdoc3/quoter.cpp
index 1892f89..dadf67c 100644
--- a/tools/qdoc3/quoter.cpp
+++ b/tools/qdoc3/quoter.cpp
@@ -41,7 +41,6 @@
#include <qfileinfo.h>
#include <qregexp.h>
-#include <qdebug.h>
#include "quoter.h"
@@ -123,9 +122,9 @@ Quoter::Quoter()
/* We're going to hard code these delimiters:
* C++, Qt, Qt Script, Java:
//! [<id>]
- * .pro files:
+ * .pro, .py files:
#! [<id>]
- * .xq, .xml, .html files:
+ * .html, .qrc, .ui, .xq, .xml files:
<!-- [<id>] -->
*/
commentHash["pro"] = "#!";
@@ -222,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();
@@ -233,33 +235,24 @@ 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
+ // delimeters, so look for the first comment on the line.
QString leading = lastLine.left(dIndex);
dIndex = leading.indexOf(comment);
if (dIndex != -1)
leading = leading.left(dIndex);
+ if (leading.endsWith(QLatin1String("<@comment>")))
+ leading.chop(10);
if (!leading.trimmed().isEmpty())
t += leading;
}
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;
@@ -274,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() ) {
@@ -310,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();
@@ -318,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;
@@ -366,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