QString Quoter::quoteLine( const Location& docLocation, const QString& command, const QString& pattern ) { if ( plainLines.isEmpty() ) { failedAtEnd( docLocation, command ); return ""; } if ( pattern.isEmpty() ) { docLocation.warning( tr("Missing pattern after '\\%1'").arg(command) ); return ""; } if ( match(docLocation, pattern, plainLines.first()) ) { return getLine(); } else { if ( !silent ) { docLocation.warning( tr("Command '\\%1' failed").arg(command) ); codeLocation.warning( tr("Pattern '%1' didn't match here") .arg(pattern) ); silent = true; } return ""; } }
QString Quoter::quoteSnippet(const Location &docLocation, const QString &identifier) { QString comment = commentForCode(); QString delimiter = comment + QString(" [%1]").arg(identifier); QString t; while (!plainLines.isEmpty()) { if (match(docLocation, delimiter, plainLines.first())) { getLine(); break; } getLine(); } while (!plainLines.isEmpty()) { QString line = plainLines.first(); if (match(docLocation, delimiter, line)) { QString lastLine = getLine(); int dIndex = lastLine.indexOf(delimiter); if (dIndex > 0) { QString leading = lastLine.left(dIndex); dIndex = leading.indexOf(comment); if (dIndex != -1) leading = leading.left(dIndex); 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(); } } failedAtEnd(docLocation, QString("snippet (%1)").arg(delimiter)); return t; }
QString Quoter::quoteTo( const Location& docLocation, const QString& command, const QString& pattern ) { QString t; if ( pattern.isEmpty() ) { while ( !plainLines.isEmpty() ) t += getLine(); } else { while ( !plainLines.isEmpty() ) { if ( match(docLocation, pattern, plainLines.first()) ) return t; t += getLine(); } failedAtEnd( docLocation, command ); } return t; }
QString Quoter::quoteSnippet(const Location &docLocation, const QString &identifier) { QString comment = commentForCode(); QString delimiter = comment + QString(" [%1]").arg(identifier); QString t; int indent = 0; while (!plainLines.isEmpty()) { if (match(docLocation, delimiter, plainLines.first())) { QString startLine = getLine(); while (indent < startLine.length() && startLine[indent] == QLatin1Char(' ')) indent++; break; } getLine(); } while (!plainLines.isEmpty()) { QString line = plainLines.first(); if (match(docLocation, delimiter, line)) { 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; } t += removeSpecialLines(line, comment, indent); } failedAtEnd(docLocation, QString("snippet (%1)").arg(delimiter)); return t; }
QString Quoter::quoteTo( const Location& docLocation, const QString& command, const QString& pattern ) { QString t; QString comment = commentForCode(); if ( pattern.isEmpty() ) { while ( !plainLines.isEmpty() ) { QString line = plainLines.first(); t += removeSpecialLines(line, comment); } } else { while ( !plainLines.isEmpty() ) { if ( match(docLocation, pattern, plainLines.first()) ) { return t; } t += getLine(); } failedAtEnd( docLocation, command ); } return t; }
QString Quoter::quoteTo( const Location& docLocation, const QString& command, const QString& pattern ) { QString t; QString comment = commentForCode(); 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(); } } } else { while ( !plainLines.isEmpty() ) { if ( match(docLocation, pattern, plainLines.first()) ) { return t; } t += getLine(); } failedAtEnd( docLocation, command ); } return t; }