コード例 #1
0
void tst_QTemporaryFile::fileNameIsEmpty()
{
    QString filename;
    {
        QTemporaryFile file;
        QVERIFY(file.fileName().isEmpty());

        QVERIFY(file.open());
        QVERIFY(!file.fileName().isEmpty());

        filename = file.fileName();
        QVERIFY(QFile::exists(filename));

        file.close();
        QVERIFY(!file.isOpen());
        QVERIFY(QFile::exists(filename));
        QVERIFY(!file.fileName().isEmpty());
    }
    QVERIFY(!QFile::exists(filename));
}
コード例 #2
0
ファイル: commandxmltoprep.cpp プロジェクト: karelklic/wikt
/// @brief Adds entry to the file.
///
/// Some entries may be ignored because of their namespace. Entries from Wiktionary
/// namespace are ignored for now.
///
/// The contents of the entry can be changed before saving.
///
/// Prep modifies entry content:
///  - <nowiki> sections are converted to HTML entities and the tags are removed.
///  - <noinclude> blocks are removed with their content
///  - HTML comments <!-- --> are removed with their content
///  - <includeonly> tags are removed, but not the contents between them
///
/// @param name
///   Name of entry. Includes the optional namespace.
/// @param contents
///   Entry contents in wiki syntax.
static void addPrepEntry(const QString &name, QString contents)
{
  // Skip pages from Wikitonary namespace.
  if (name.contains("Wiktionary:")) return;

  // Apply errata if it exists.
  contents = errata.value(name, contents);

  // Remove comments from contents.
  contents = StringUtils::removeBlock(QRegExp("<!--"), QRegExp("-->"), contents);

  // Remove includeonly tags, but not the content between them.
  contents.remove(QRegExp("<includeonly\\s*>"))
    .remove(QRegExp("</includeonly\\s*>"));

  // Remove __TOC__ magic word, because we handle Table of Contents in
  // a separate window.
  contents.remove("__TOC__");

  // Do not remove <nowiki/> tags. They are used as a separator between wikisyntax
  // that cannot be parsed together.

  // Substitute special wiki characters in <nowiki> sections with
  // html chars and removes the <nowiki> tags.
  contents = substituteSpecialCharactersNoWiki(contents);

  if (!temporaryFile.isOpen())
      temporaryFile.open();
  qint64 offset = temporaryFile.pos();

  // Save data to the content file.
  FileUtils::writeString(temporaryFile, name);
  FileUtils::writeString(temporaryFile, contents);

  // Add an entry to the link list.
  links.push_back(Link(name, offset));
}