diff --git a/autotests/kconfigtest.cpp b/autotests/kconfigtest.cpp --- a/autotests/kconfigtest.cpp +++ b/autotests/kconfigtest.cpp @@ -530,15 +530,15 @@ file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out.setCodec("UTF-8"); - out << "[Test Group]" << endl - << "homePath=$HOME/foo" << endl - << "homePath2=file://$HOME/foo" << endl - << "withSlash=$WITHSLASH/foo" << endl - << "withSlash2=$WITHSLASH" << endl - << "withBraces[$e]=file://${HOME}/foo" << endl - << "URL[$e]=file://${HOME}/foo" << endl - << "hostname[$e]=$(hostname)" << endl - << "escapes=aaa,bb/b,ccc\\,ccc" << endl + out << "[Test Group]\n" + << "homePath=$HOME/foo\n" + << "homePath2=file://$HOME/foo\n" + << "withSlash=$WITHSLASH/foo\n" + << "withSlash2=$WITHSLASH\n" + << "withBraces[$e]=file://${HOME}/foo\n" + << "URL[$e]=file://${HOME}/foo\n" + << "hostname[$e]=$(hostname)\n" + << "escapes=aaa,bb/b,ccc\\,ccc\n" << "noeol=foo" // no EOL ; } @@ -592,10 +592,10 @@ file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out.setCodec("UTF-8"); - out << "[Test Group]" << endl - << "dataDir[$e]=$QT_DATA_HOME/kconfigtest" << endl - << "cacheDir[$e]=$QT_CACHE_HOME/kconfigtest" << endl - << "configDir[$e]=$QT_CONFIG_HOME/kconfigtest" << endl; + out << "[Test Group]\n" + << "dataDir[$e]=$QT_DATA_HOME/kconfigtest\n" + << "cacheDir[$e]=$QT_CACHE_HOME/kconfigtest\n" + << "configDir[$e]=$QT_CONFIG_HOME/kconfigtest\n"; } KConfig cf2(TEST_SUBDIR "pathtest"); KConfigGroup group = cf2.group("Test Group"); @@ -981,26 +981,26 @@ QFile global(globalConfigDir + "foo.desktop"); QVERIFY(global.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream globalOut(&global); - globalOut << "[Group]" << endl - << "FromGlobal=true" << endl - << "FromGlobal[fr]=vrai" << endl - << "Name=Testing" << endl - << "Name[fr]=FR" << endl - << "Other=Global" << endl - << "Other[fr]=Global_FR" << endl; + globalOut << "[Group]\n" + << "FromGlobal=true\n" + << "FromGlobal[fr]=vrai\n" + << "Name=Testing\n" + << "Name[fr]=FR\n" + << "Other=Global\n" + << "Other[fr]=Global_FR\n"; global.close(); const QString middleConfigDir = middleDir.path() + "/" TEST_SUBDIR; QVERIFY(QDir().mkpath(middleConfigDir)); QFile local(middleConfigDir + "foo.desktop"); QVERIFY(local.open(QIODevice::WriteOnly | QIODevice::Text)); QTextStream out(&local); - out << "[Group]" << endl - << "FromLocal=true" << endl - << "FromLocal[fr]=vrai" << endl - << "Name=Local Testing" << endl - << "Name[fr]=FR" << endl - << "Other=English Only" << endl; + out << "[Group]\n" + << "FromLocal=true\n" + << "FromLocal[fr]=vrai\n" + << "Name=Local Testing\n" + << "Name[fr]=FR\n" + << "Other=English Only\n"; local.close(); KConfig config(TEST_SUBDIR "foo.desktop"); @@ -1032,13 +1032,13 @@ file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out.setCodec("UTF-8"); - out << "[Merged Group]" << endl - << "entry1=Testing" << endl - << "entry2=More Testing" << endl - << "[some group]" << endl - << "entry[fr]=French" << endl - << "entry[es]=Spanish" << endl - << "entry[de]=German" << endl; + out << "[Merged Group]\n" + << "entry1=Testing\n" + << "entry2=More Testing\n" + << "[some group]\n" + << "entry[fr]=French\n" + << "entry[es]=Spanish\n" + << "entry[de]=German\n"; } QVERIFY(config.sync()); @@ -1070,10 +1070,10 @@ file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out.setCodec("UTF-8"); - out << "[$i]" << endl - << "entry1=Testing" << endl - << "[group][$i]" << endl - << "[group][subgroup][$i]" << endl; + out << "[$i]\n" + << "entry1=Testing\n" + << "[group][$i]\n" + << "[group][subgroup][$i]\n"; } KConfig config(TEST_SUBDIR "immutabletest", KConfig::SimpleConfig); @@ -1095,9 +1095,9 @@ file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file); out.setCodec("UTF-8"); - out << "[group3]" << endl - << "entry2=unlocalized" << endl - << "entry2[$i][de_DE]=t2" << endl; + out << "[group3]\n" + << "entry2=unlocalized\n" + << "entry2[$i][de_DE]=t2\n"; } KConfig config(TEST_SUBDIR "doubleattrtest", KConfig::SimpleConfig); config.setLocale(QStringLiteral("de_DE")); @@ -1836,14 +1836,14 @@ QTemporaryFile file; QVERIFY(file.open()); QTextStream out(&file); - out << "[General]" << endl - << "Key1=" << endl // empty list + out << "[General]\n" + << "Key1=\n" // empty list // emtpty entries - << "Key2=;" << endl - << "Key3=;;" << endl - << "Key4=;;;" << endl - << "Key5=\\;" << endl - << "Key6=1;2\\;3;;" << endl; + << "Key2=;\n" + << "Key3=;;\n" + << "Key4=;;;\n" + << "Key5=\\;\n" + << "Key6=1;2\\;3;;\n"; out.flush(); file.close(); KConfig anonConfig(file.fileName(), KConfig::SimpleConfig); diff --git a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp --- a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp +++ b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp @@ -34,13 +34,7 @@ #include #include -using std::endl; - -namespace -{ -QTextStream cout(stdout); -QTextStream cerr(stderr); -} +#include KConfigCodeGeneratorBase::KConfigCodeGeneratorBase( const QString &inputFile, @@ -52,7 +46,7 @@ { m_file.setFileName(m_fileName); if (!m_file.open(QIODevice::WriteOnly)) { - cerr << "Can not open '" << m_fileName << "for writing." << endl; + std::cerr << "Can not open '" << qPrintable(m_fileName) << "for writing." << std::endl; exit(1); } m_stream.setDevice(&m_file); @@ -106,7 +100,7 @@ void KConfigCodeGeneratorBase::startScope() { m_stream << whitespace() << QLatin1Char('{'); - m_stream << endl; + m_stream << '\n'; indent(); } @@ -117,23 +111,23 @@ if (finalizer == ScopeFinalizer::Semicolon) { m_stream << ';'; } - m_stream << endl; + m_stream << '\n'; } void KConfigCodeGeneratorBase::start() { const QString m_fileName = QFileInfo(m_inputFile).fileName(); - m_stream << "// This file is generated by kconfig_compiler_kf5 from " << m_fileName << ".kcfg" << "." << endl; - m_stream << "// All changes you do to this file will be lost." << endl; + m_stream << "// This file is generated by kconfig_compiler_kf5 from " << m_fileName << ".kcfg" << ".\n"; + m_stream << "// All changes you do to this file will be lost.\n"; } void KConfigCodeGeneratorBase::addHeaders(const QStringList &headerList) { for (auto include : qAsConst(headerList)) { if (include.startsWith(QLatin1Char('"'))) { - m_stream << "#include " << include << endl; + m_stream << "#include " << include << '\n'; } else { - m_stream << "#include <" << include << ">" << endl; + m_stream << "#include <" << include << ">\n"; } } } @@ -144,21 +138,21 @@ { if (!m_cfg.nameSpace.isEmpty()) { for (const QString &ns : m_cfg.nameSpace.split(QStringLiteral("::"))) { - m_stream << "namespace " << ns << " {" << endl; + m_stream << "namespace " << ns << " {\n"; } - m_stream << endl; + m_stream << '\n'; } } // adds as many '}' lines to p_out as // there are namespaces in p_ns void KConfigCodeGeneratorBase::endNamespaces() { if (!m_cfg.nameSpace.isEmpty()) { - m_stream << endl; + m_stream << '\n'; const int namespaceCount = m_cfg.nameSpace.count(QStringLiteral("::")) + 1; for (int i = 0; i < namespaceCount; ++i) { - m_stream << "}" << endl; + m_stream << "}\n"; } } } @@ -185,7 +179,7 @@ if (useEnumType) { out << ")"; } - out << ";" << endl; + out << ";\n"; return result; } @@ -233,23 +227,23 @@ // HACK: Don't open '{' manually, use startScope / endScope to automatically handle whitespace indentation. if (!e->min.isEmpty()) { if (e->min != QLatin1String("0") || !isUnsigned(t)) { // skip writing "if uint<0" (#187579) - m_stream << whitespace() << "if (v < " << e->min << ")" << endl; - m_stream << whitespace() << "{" << endl; + m_stream << whitespace() << "if (v < " << e->min << ")\n"; + m_stream << whitespace() << "{\n"; m_stream << whitespace(); addDebugMethod(m_stream, m_cfg, n); - m_stream << ": value \" << v << \" is less than the minimum value of " << e->min << "\";" << endl; - m_stream << whitespace() << " v = " << e->min << ";" << endl; - m_stream << whitespace() << "}" << endl; + m_stream << ": value \" << v << \" is less than the minimum value of " << e->min << "\";\n"; + m_stream << whitespace() << " v = " << e->min << ";\n"; + m_stream << whitespace() << "}\n"; } } if (!e->max.isEmpty()) { - m_stream << endl; - m_stream << whitespace() << "if (v > " << e->max << ")" << endl; - m_stream << whitespace() << "{" << endl; + m_stream << '\n'; + m_stream << whitespace() << "if (v > " << e->max << ")\n"; + m_stream << whitespace() << "{\n"; m_stream << whitespace(); addDebugMethod(m_stream, m_cfg, n); - m_stream << ": value \" << v << \" is greater than the maximum value of " << e->max << "\";" << endl; - m_stream << whitespace() << " v = " << e->max << ";" << endl; - m_stream << whitespace() << "}" << endl << endl; + m_stream << ": value \" << v << \" is greater than the maximum value of " << e->max << "\";\n"; + m_stream << whitespace() << " v = " << e->max << ";\n"; + m_stream << whitespace() << "}\n\n"; } const QString varExpression = m_this + varPath(n, m_cfg) + (e->param.isEmpty() ? QString() : QStringLiteral("[i]")); @@ -259,19 +253,19 @@ // m_this call creates an `if (someTest ...) that's just to long to throw over the code. createIfSetLogic(e, varExpression); - m_stream << (hasBody ? " {" : "") << endl; - m_stream << whitespace() << " " << varExpression << " = v;" << endl; + m_stream << (hasBody ? " {" : "") << '\n'; + m_stream << whitespace() << " " << varExpression << " = v;\n"; const auto listSignal = e->signalList; for (const Signal &signal : qAsConst(listSignal)) { if (signal.modify) { - m_stream << whitespace() << " Q_EMIT " << m_this << signal.name << "();" << endl; + m_stream << whitespace() << " Q_EMIT " << m_this << signal.name << "();\n"; } else { m_stream << whitespace() << " " << m_this << varPath(QStringLiteral("settingsChanged"), m_cfg) - << " |= " << signalEnumName(signal.name) << ";" << endl; + << " |= " << signalEnumName(signal.name) << ";\n"; } } if (hasBody) { - m_stream << whitespace() << "}" << endl; + m_stream << whitespace() << "}\n"; } } diff --git a/src/kconfig_compiler/KConfigHeaderGenerator.cpp b/src/kconfig_compiler/KConfigHeaderGenerator.cpp --- a/src/kconfig_compiler/KConfigHeaderGenerator.cpp +++ b/src/kconfig_compiler/KConfigHeaderGenerator.cpp @@ -28,12 +28,7 @@ #include #include - -namespace -{ -QTextStream cout(stdout); -QTextStream cerr(stderr); -} +#include KConfigHeaderGenerator::KConfigHeaderGenerator( const QString &inputFile, @@ -62,14 +57,14 @@ void KConfigHeaderGenerator::doClassDefinition() { - stream() << "class " << cfg().visibility << cfg().className << " : public " << cfg().inherits << endl; + stream() << "class " << cfg().visibility << cfg().className << " : public " << cfg().inherits << '\n'; startScope(); // Add Q_OBJECT macro if the config need signals. if (!parseResult.signalList.isEmpty() || cfg().generateProperties) { - stream() << " Q_OBJECT" << endl; + stream() << " Q_OBJECT\n"; } - stream() << " public:" << endl; + stream() << " public:\n"; implementEnums(); createConstructor(); createDestructor(); @@ -90,32 +85,32 @@ } createSignals(); - stream() << " protected:" << endl; + stream() << " protected:\n"; createSingleton(); // TODO: Move those to functions too. if (parseResult.hasNonModifySignals) { - stream() << whitespace() << "bool usrSave() override;" << endl; + stream() << whitespace() << "bool usrSave() override;\n"; } // Member variables if (!cfg().memberVariables.isEmpty() && cfg().memberVariables != QLatin1String("private") && cfg().memberVariables != QLatin1String("dpointer")) { - stream() << " " << cfg().memberVariables << ":" << endl; + stream() << " " << cfg().memberVariables << ":\n"; } // Class Parameters for (const auto ¶meter : parseResult.parameters) { - stream() << whitespace() << "" << cppType(parameter.type) << " mParam" << parameter.name << ";" << endl; + stream() << whitespace() << "" << cppType(parameter.type) << " mParam" << parameter.name << ";\n"; } createNonDPointerHelpers(); createDPointer(); if (cfg().customAddons) { - stream() << whitespace() << "// Include custom additions" << endl; - stream() << whitespace() << "#include \"" << cfg().baseName << "_addons." << cfg().headerExtension << '"' << endl; + stream() << whitespace() << "// Include custom additions\n"; + stream() << whitespace() << "#include \"" << cfg().baseName << "_addons." << cfg().headerExtension << "\"\n"; } endScope(ScopeFinalizer::Semicolon); @@ -125,7 +120,7 @@ { addHeaders(cfg().headerIncludes); if (cfg().headerIncludes.size()) { - stream() << endl; + stream() << '\n'; } if (!cfg().singleton && parseResult.parameters.isEmpty()) { @@ -139,11 +134,11 @@ } addHeaders({QStringLiteral("QCoreApplication"), QStringLiteral("QDebug")}); - stream() << endl; + stream() << '\n'; addHeaders(parseResult.includes); if (parseResult.includes.size()) { - stream() << endl; + stream() << '\n'; } } @@ -154,18 +149,18 @@ const QString namespaceStr = hasNamespace ? namespaceName + QLatin1Char('_') : QStringLiteral(""); const QString defineName = namespaceStr + cfg().className.toUpper() + QStringLiteral("_H"); - stream() << "#ifndef " << defineName << endl; - stream() << "#define " << defineName << endl; - stream() << endl; + stream() << "#ifndef " << defineName << '\n'; + stream() << "#define " << defineName << '\n'; + stream() << '\n'; } void KConfigHeaderGenerator::endHeaderGuards() { - stream() << endl; + stream() << '\n'; stream() << "#endif"; - stream() << endl; + stream() << '\n'; // HACK: Original files ended with two last newlines, add them. - stream() << endl; + stream() << '\n'; } void KConfigHeaderGenerator::implementChoiceEnums(const CfgEntry *entry, const CfgEntry::Choices &choices) @@ -183,18 +178,18 @@ if (choices.name().isEmpty()) { if (cfg().globalEnums) { - stream() << whitespace() << "enum " << enumName(entry->name, entry->choices) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; + stream() << whitespace() << "enum " << enumName(entry->name, entry->choices) << " { " << values.join(QStringLiteral(", ")) << " };\n"; } else { // Create an automatically named enum - stream() << whitespace() << "class " << enumName(entry->name, entry->choices) << endl; - stream() << whitespace() << "{" << endl; - stream() << whitespace() << " public:" << endl; - stream() << whitespace() << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };" << endl; - stream() << whitespace() << "};" << endl; + stream() << whitespace() << "class " << enumName(entry->name, entry->choices) << '\n'; + stream() << whitespace() << "{\n"; + stream() << whitespace() << " public:\n"; + stream() << whitespace() << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };\n"; + stream() << whitespace() << "};\n"; } } else if (!choices.external()) { // Create a named enum - stream() << whitespace() << "enum " << enumName(entry->name, entry->choices) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; + stream() << whitespace() << "enum " << enumName(entry->name, entry->choices) << " { " << values.join(QStringLiteral(", ")) << " };\n"; } } @@ -208,15 +203,15 @@ // ### FIXME!! // make the following string table an index-based string search! // ### - stream() << whitespace() << "enum " << enumName(entry->param) << " { " << values.join(QStringLiteral(", ")) << " };" << endl; - stream() << whitespace() << "static const char* const " << enumName(entry->param) << "ToString[];" << endl; + stream() << whitespace() << "enum " << enumName(entry->param) << " { " << values.join(QStringLiteral(", ")) << " };\n"; + stream() << whitespace() << "static const char* const " << enumName(entry->param) << "ToString[];\n"; } else { - stream() << whitespace() << "class " << enumName(entry->param) << endl; - stream() << whitespace() << "{" << endl; - stream() << whitespace() << " public:" << endl; - stream() << whitespace() << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };" << endl; - stream() << whitespace() << " static const char* const enumToString[];" << endl; - stream() << whitespace() << "};" << endl; + stream() << whitespace() << "class " << enumName(entry->param) << '\n'; + stream() << whitespace() << "{\n"; + stream() << whitespace() << " public:\n"; + stream() << whitespace() << " enum type { " << values.join(QStringLiteral(", ")) << ", COUNT };\n"; + stream() << whitespace() << " static const char* const enumToString[];\n"; + stream() << whitespace() << "};\n"; } } @@ -233,7 +228,7 @@ implementChoiceEnums(entry, choices); implementValueEnums(entry, values); } - stream() << endl; + stream() << '\n'; } void KConfigHeaderGenerator::createSignals() @@ -243,15 +238,15 @@ unsigned val = 1 << parseResult.signalList.size(); if (!val) { - cerr << "Too many signals to create unique bit masks" << endl; + std::cerr << "Too many signals to create unique bit masks" << std::endl; exit(1); } if (!hasSignals) { return; } - stream() << "\n enum {" << endl; + stream() << "\n enum {\n"; val = 1; // HACK: Use C-Style for add a comma in all but the last element, @@ -262,21 +257,21 @@ auto signal = parseResult.signalList.at(i); stream() << whitespace() << " " << signalEnumName(signal.name) << " = 0x" << hex << val; if (i != end-1) { - stream() << "," << endl; + stream() << ",\n"; } val <<= 1; } - stream() << endl; - stream() << whitespace() << "};" << dec << endl << endl; + stream() << '\n'; + stream() << whitespace() << "};" << dec << "\n\n"; stream() << " Q_SIGNALS:"; for (const Signal &signal : parseResult.signalList) { - stream() << endl; + stream() << '\n'; if (!signal.label.isEmpty()) { - stream() << whitespace() << "/**" << endl; - stream() << whitespace() << " " << signal.label << endl; - stream() << whitespace() << "*/" << endl; + stream() << whitespace() << "/**\n"; + stream() << whitespace() << " " << signal.label << '\n'; + stream() << whitespace() << "*/\n"; } stream() << whitespace() << "void " << signal.name << "("; QList::ConstIterator it, itEnd = signal.arguments.constEnd(); @@ -296,13 +291,13 @@ stream() << ", "; } } - stream() << ");" << endl; + stream() << ");\n"; } - stream() << endl; + stream() << '\n'; - stream() << " private:" << endl; - stream() << whitespace() << "void itemChanged(quint64 flags);" << endl; - stream() << endl; + stream() << " private:\n"; + stream() << whitespace() << "void itemChanged(quint64 flags);\n"; + stream() << '\n'; } void KConfigHeaderGenerator::createDPointer() @@ -312,7 +307,7 @@ } // use a private class for both member variables and items - stream() << " private:" << endl; + stream() << " private:\n"; for (const auto &entry : parseResult.entries) { if (cfg().allDefaultGetters || cfg().defaultGetters.contains(entry->name)) { stream() << whitespace() << ""; @@ -323,19 +318,19 @@ if (!entry->param.isEmpty()) { stream() << " " << cppType(entry->paramType) << " i "; } - stream() << ")" << Const() << ";" << endl; + stream() << ")" << Const() << ";\n"; } } - stream() << whitespace() << "" << cfg().className << "Private *d;" << endl; + stream() << whitespace() << "" << cfg().className << "Private *d;\n"; } void KConfigHeaderGenerator::createConstructor() { if (cfg().singleton) { - stream() << whitespace() << "static " << cfg().className << " *self();" << endl; + stream() << whitespace() << "static " << cfg().className << " *self();\n"; if (parseResult.cfgFileNameArg) { - stream() << whitespace() << "static void instance(const QString& cfgfilename);" << endl; - stream() << whitespace() << "static void instance(KSharedConfig::Ptr config);" << endl; + stream() << whitespace() << "static void instance(const QString& cfgfilename);\n"; + stream() << whitespace() << "static void instance(KSharedConfig::Ptr config);\n"; } return; } @@ -365,19 +360,19 @@ } stream() << " QObject *parent = nullptr"; } - stream() << " );" << endl; + stream() << " );\n"; } void KConfigHeaderGenerator::createDestructor() { - stream() << whitespace() << "~" << cfg().className << "();" << endl << endl; + stream() << whitespace() << "~" << cfg().className << "();\n\n"; } void KConfigHeaderGenerator::createForwardDeclarations() { // Private class declaration if (cfg().dpointer) { - stream() << "class " << cfg().className << "Private;" << endl << endl; + stream() << "class " << cfg().className << "Private;\n\n"; } } @@ -403,7 +398,7 @@ } else { stream() << " CONSTANT"; } - stream() << ")" << endl; + stream() << ")\n"; } void KConfigHeaderGenerator::createSetters(const CfgEntry *entry) @@ -413,12 +408,12 @@ return; } - stream() << whitespace() << "/**" << endl; - stream() << whitespace() << " Set " << entry->label << endl; - stream() << whitespace() << "*/" << endl; + stream() << whitespace() << "/**\n"; + stream() << whitespace() << " Set " << entry->label << '\n'; + stream() << whitespace() << "*/\n"; if (cfg().staticAccessors) { - stream() << whitespace() << "static" << endl; + stream() << whitespace() << "static\n"; } stream() << whitespace() << "void " << setFunction(entry->name) << "( "; @@ -435,24 +430,24 @@ // function body inline only if not using dpointer // for BC mode if (!cfg().dpointer) { - stream() << endl; + stream() << '\n'; startScope(); memberMutatorBody(entry); endScope(); - stream() << endl; + stream() << '\n'; } else { - stream() << ";" << endl << endl; + stream() << ";\n\n"; } } void KConfigHeaderGenerator::createGetters(const CfgEntry *entry, const QString &returnType) { // Accessor - stream() << whitespace() << "/**" << endl; - stream() << whitespace() << " Get " << entry->label << endl; - stream() << whitespace() << "*/" << endl; + stream() << whitespace() << "/**\n"; + stream() << whitespace() << " Get " << entry->label << '\n'; + stream() << whitespace() << "*/\n"; if (cfg().staticAccessors) { - stream() << whitespace() << "static" << endl; + stream() << whitespace() << "static\n"; } stream() << whitespace() << ""; stream() << returnType; @@ -465,13 +460,13 @@ // function body inline only if not using dpointer // for BC mode if (!cfg().dpointer) { - stream() << endl; + stream() << '\n'; startScope(); stream() << whitespace() << memberAccessorBody(entry, cfg().globalEnums); endScope(); - stream() << endl; + stream() << '\n'; } else { - stream() << ";" << endl << endl; + stream() << ";\n\n"; } } @@ -481,23 +476,23 @@ if (!cfg().itemAccessors) { return; } - stream() << whitespace() << "/**" << endl; + stream() << whitespace() << "/**\n"; stream() << whitespace() << " Get Item object corresponding to " << entry->name << "()" - << endl; - stream() << whitespace() << "*/" << endl; + << '\n'; + stream() << whitespace() << "*/\n"; stream() << whitespace() << "Item" << itemType(entry->type) << " *" << getFunction(entry->name) << "Item("; if (!entry->param.isEmpty()) { stream() << " " << cppType(entry->paramType) << " i "; } stream() << ")"; if (!cfg().dpointer) { - stream() << endl; + stream() << '\n'; startScope(); stream() << whitespace() << itemAccessorBody(entry, cfg()); endScope(); } else { - stream() << ";" << endl; + stream() << ";\n"; } stream() <name)) && !entry->defaultValue.isEmpty())) { return; } - stream() << whitespace() << "/**" << endl; - stream() << whitespace() << " Get " << entry->label << " default value" << endl; - stream() << whitespace() << "*/" << endl; + stream() << whitespace() << "/**\n"; + stream() << whitespace() << " Get " << entry->label << " default value\n"; + stream() << whitespace() << "*/\n"; if (cfg().staticAccessors) { - stream() << whitespace() << "static" << endl; + stream() << whitespace() << "static\n"; } stream() << whitespace() << ""; if (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) { @@ -525,8 +520,8 @@ if (!entry->param.isEmpty()) { stream() << " " << cppType(entry->paramType) << " i "; } - stream() << ")" << Const() << endl; - stream() << whitespace() << "{" << endl; + stream() << ")" << Const() << '\n'; + stream() << whitespace() << "{\n"; stream() << whitespace() << " return "; if (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) { stream() << "static_cast<" << enumType(entry, cfg().globalEnums) << ">("; @@ -539,9 +534,9 @@ if (cfg().useEnumTypes && entry->type == QLatin1String("Enum")) { stream() << ")"; } - stream() << ";" << endl; - stream() << whitespace() << "}" << endl; - stream() << endl; + stream() << ";\n"; + stream() << whitespace() << "}\n"; + stream() << '\n'; } void KConfigHeaderGenerator::createSingleton() @@ -561,8 +556,8 @@ } stream() << "QObject *parent = nullptr"; } - stream() << ");" << endl; - stream() << whitespace() << "friend class " << cfg().className << "Helper;" << endl << endl; + stream() << ");\n"; + stream() << whitespace() << "friend class " << cfg().className << "Helper;\n\n"; } void KConfigHeaderGenerator::createNonDPointerHelpers() @@ -575,14 +570,14 @@ for (auto *entry : parseResult.entries) { if (entry->group != group) { group = entry->group; - stream() << endl; - stream() << whitespace() << "// " << group << endl; + stream() << '\n'; + stream() << whitespace() << "// " << group << '\n'; } stream() << whitespace() << "" << cppType(entry->type) << " " << varName(entry->name, cfg()); if (!entry->param.isEmpty()) { stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); } - stream() << ";" << endl; + stream() << ";\n"; if (cfg().allDefaultGetters || cfg().defaultGetters.contains(entry->name)) { stream() << whitespace() << ""; @@ -593,22 +588,22 @@ if (!entry->param.isEmpty()) { stream() << " " << cppType(entry->paramType) << " i "; } - stream() << ")" << Const() << ";" << endl; + stream() << ")" << Const() << ";\n"; } } - stream() << endl << " private:" << endl; + stream() << "\n private:\n"; if (cfg().itemAccessors) { for (auto *entry : parseResult.entries) { stream() << whitespace() << "Item" << itemType(entry->type) << " *" << itemVar(entry, cfg()); if (!entry->param.isEmpty()) { stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); } - stream() << ";" << endl; + stream() << ";\n"; } } if (parseResult.hasNonModifySignals) { - stream() << whitespace() << "uint " << varName(QStringLiteral("settingsChanged"), cfg()) << ";" << endl; + stream() << whitespace() << "uint " << varName(QStringLiteral("settingsChanged"), cfg()) << ";\n"; } } diff --git a/src/kconfig_compiler/KConfigParameters.cpp b/src/kconfig_compiler/KConfigParameters.cpp --- a/src/kconfig_compiler/KConfigParameters.cpp +++ b/src/kconfig_compiler/KConfigParameters.cpp @@ -31,16 +31,12 @@ #include #include -namespace -{ -QTextStream cout(stdout); -QTextStream cerr(stderr); -} +#include KConfigParameters::KConfigParameters(const QString &codegenFilename) { if (!codegenFilename.endsWith(QLatin1String(".kcfgc"))) { - cerr << "Codegen options file must have extension .kcfgc" << endl; + std::cerr << "Codegen options file must have extension .kcfgc" << std::endl; exit(1); } @@ -53,7 +49,7 @@ nameSpace = codegenConfig.value(QStringLiteral("NameSpace")).toString(); className = codegenConfig.value(QStringLiteral("ClassName")).toString(); if (className.isEmpty()) { - cerr << "Class name missing" << endl; + std::cerr << "Class name missing" << std::endl; exit(1); } inherits = codegenConfig.value(QStringLiteral("Inherits")).toString(); @@ -90,7 +86,7 @@ translationDomain = codegenConfig.value(QStringLiteral("TranslationDomain")).toString(); } else { if (!trString.isEmpty() && trString != QLatin1String("qt")) { - cerr << "Unknown translation system, falling back to Qt tr()" << endl; + std::cerr << "Unknown translation system, falling back to Qt tr()" << std::endl; } translationSystem = QtTranslation; } diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -39,12 +39,12 @@ void KConfigSourceGenerator::start() { KConfigCodeGeneratorBase::start(); - stream() << endl; + stream() << '\n'; createHeaders(); if (!cfg().nameSpace.isEmpty()) { stream() << "using namespace " << cfg().nameSpace << ";"; - stream() << endl << endl; + stream() << endl << '\n'; } createPrivateDPointerImplementation(); @@ -67,30 +67,30 @@ addQuotes(headerName); addHeaders({ headerName }); - stream() << endl; + stream() << '\n'; addHeaders(cfg().sourceIncludes); if (cfg().setUserTexts && cfg().translationSystem == KConfigParameters::KdeTranslation) { addHeaders({QStringLiteral("klocalizedstring.h")}); - stream() << endl; + stream() << '\n'; } // Header required by singleton implementation if (cfg().singleton) { addHeaders({QStringLiteral("qglobal.h"), QStringLiteral("QFile")}); // HACK: Add single line to fix test. if (cfg().singleton && parseResult.cfgFileNameArg) { - stream() << endl; + stream() << '\n'; } } if (cfg().singleton && parseResult.cfgFileNameArg) { addHeaders({QStringLiteral("QDebug")}); } if (cfg().singleton) { - stream() << endl; + stream() << '\n'; } } @@ -103,24 +103,24 @@ QString group; beginNamespaces(); - stream() << "class " << cfg().className << "Private" << endl; - stream() << "{" << endl; - stream() << " public:" << endl; + stream() << "class " << cfg().className << "Private\n"; + stream() << "{\n"; + stream() << " public:\n"; // Create Members for (auto *entry : parseResult.entries) { if (entry->group != group) { group = entry->group; - stream() << endl; - stream() << " // " << group << endl; + stream() << '\n'; + stream() << " // " << group << '\n'; } stream() << " " << cppType(entry->type) << " " << varName(entry->name, cfg()); if (!entry->param.isEmpty()) { stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); } - stream() << ";" << endl; + stream() << ";\n"; } - stream() << endl << " // items" << endl; + stream() << endl << " // items\n"; // Create Items. for (auto *entry : parseResult.entries) { @@ -132,14 +132,14 @@ if (!entry->param.isEmpty()) { stream() << QStringLiteral("[%1]").arg(entry->paramMax + 1); } - stream() << ";" << endl; + stream() << ";\n"; } if (parseResult.hasNonModifySignals) { - stream() << " uint " << varName(QStringLiteral("settingsChanged"), cfg()) << ";" << endl; + stream() << " uint " << varName(QStringLiteral("settingsChanged"), cfg()) << ";\n"; } - stream() << "};" << endl << endl; + stream() << "};" << endl << '\n'; endNamespaces(); } @@ -151,50 +151,50 @@ } beginNamespaces(); - stream() << "class " << cfg().className << "Helper" << endl; - stream() << '{' << endl; - stream() << " public:" << endl; - stream() << " " << cfg().className << "Helper() : q(nullptr) {}" << endl; - stream() << " ~" << cfg().className << "Helper() { delete q; }" << endl; - stream() << " " << cfg().className << "Helper(const " << cfg().className << "Helper&) = delete;" << endl; - stream() << " " << cfg().className << "Helper& operator=(const " << cfg().className << "Helper&) = delete;" << endl; - stream() << " " << cfg().className << " *q;" << endl; - stream() << "};" << endl; + stream() << "class " << cfg().className << "Helper\n"; + stream() << '{' << '\n'; + stream() << " public:\n"; + stream() << " " << cfg().className << "Helper() : q(nullptr) {}\n"; + stream() << " ~" << cfg().className << "Helper() { delete q; }\n"; + stream() << " " << cfg().className << "Helper(const " << cfg().className << "Helper&) = delete;\n"; + stream() << " " << cfg().className << "Helper& operator=(const " << cfg().className << "Helper&) = delete;\n"; + stream() << " " << cfg().className << " *q;\n"; + stream() << "};\n"; endNamespaces(); - stream() << "Q_GLOBAL_STATIC(" << cfg().className << "Helper, s_global" << cfg().className << ")" << endl; + stream() << "Q_GLOBAL_STATIC(" << cfg().className << "Helper, s_global" << cfg().className << ")\n"; - stream() << cfg().className << " *" << cfg().className << "::self()" << endl; - stream() << "{" << endl; + stream() << cfg().className << " *" << cfg().className << "::self()\n"; + stream() << "{\n"; if (parseResult.cfgFileNameArg) { - stream() << " if (!s_global" << cfg().className << "()->q)" << endl; - stream() << " qFatal(\"you need to call " << cfg().className << "::instance before using\");" << endl; + stream() << " if (!s_global" << cfg().className << "()->q)\n"; + stream() << " qFatal(\"you need to call " << cfg().className << "::instance before using\");\n"; } else { - stream() << " if (!s_global" << cfg().className << "()->q) {" << endl; - stream() << " new " << cfg().className << ';' << endl; - stream() << " s_global" << cfg().className << "()->q->read();" << endl; - stream() << " }" << endl << endl; + stream() << " if (!s_global" << cfg().className << "()->q) {\n"; + stream() << " new " << cfg().className << ';' << '\n'; + stream() << " s_global" << cfg().className << "()->q->read();\n"; + stream() << " }" << endl << '\n'; } - stream() << " return s_global" << cfg().className << "()->q;" << endl; - stream() << "}" << endl << endl; + stream() << " return s_global" << cfg().className << "()->q;\n"; + stream() << "}" << endl << '\n'; if (parseResult.cfgFileNameArg) { auto instance = [this] (const QString &type, const QString &arg, bool isString) { - stream() << "void " << cfg().className << "::instance(" << type << " " << arg << ")" << endl; - stream() << "{" << endl; - stream() << " if (s_global" << cfg().className << "()->q) {" << endl; - stream() << " qDebug() << \"" << cfg().className << "::instance called after the first use - ignoring\";" << endl; - stream() << " return;" << endl; - stream() << " }" << endl; + stream() << "void " << cfg().className << "::instance(" << type << " " << arg << ")\n"; + stream() << "{\n"; + stream() << " if (s_global" << cfg().className << "()->q) {\n"; + stream() << " qDebug() << \"" << cfg().className << "::instance called after the first use - ignoring\";\n"; + stream() << " return;\n"; + stream() << " }\n"; stream() << " new " << cfg().className << "("; if (isString) { stream() << "KSharedConfig::openConfig(" << arg << ")"; } else { stream() << "std::move(" << arg << ")"; } - stream() << ");" << endl; - stream() << " s_global" << cfg().className << "()->q->read();" << endl; - stream() << "}" << endl << endl; + stream() << ");\n"; + stream() << " s_global" << cfg().className << "()->q->read();\n"; + stream() << "}" << endl << '\n'; }; instance(QStringLiteral("const QString&"), QStringLiteral("cfgfilename"), true); instance(QStringLiteral("KSharedConfig::Ptr"), QStringLiteral("config"), false); @@ -216,7 +216,7 @@ } if (!cppPreamble.isEmpty()) { - stream() << cppPreamble << endl; + stream() << cppPreamble << '\n'; } } @@ -264,80 +264,80 @@ if (!parseResult.cfgFileName.isEmpty()) { stream() << ") "; } - stream() << ")" << endl; + stream() << ")\n"; } void KConfigSourceGenerator::createInitializerList() { for (const auto ¶meter : parseResult.parameters) { - stream() << " , mParam" << parameter.name << "(" << parameter.name << ")" << endl; + stream() << " , mParam" << parameter.name << "(" << parameter.name << ")\n"; } if (parseResult.hasNonModifySignals && !cfg().dpointer) { - stream() << " , " << varName(QStringLiteral("settingsChanged"), cfg()) << "(0)" << endl; + stream() << " , " << varName(QStringLiteral("settingsChanged"), cfg()) << "(0)\n"; } } void KConfigSourceGenerator::createEnums(const CfgEntry *entry) { if (entry->type != QLatin1String("Enum")) { return; } - stream() << " QList<" << cfg().inherits << "::ItemEnum::Choice> values" << entry->name << ";" << endl; + stream() << " QList<" << cfg().inherits << "::ItemEnum::Choice> values" << entry->name << ";\n"; for (const auto &choice : qAsConst(entry->choices.choices)) { - stream() << " {" << endl; - stream() << " " << cfg().inherits << "::ItemEnum::Choice choice;" << endl; - stream() << " choice.name = QStringLiteral(\"" << choice.name << "\");" << endl; + stream() << " {\n"; + stream() << " " << cfg().inherits << "::ItemEnum::Choice choice;\n"; + stream() << " choice.name = QStringLiteral(\"" << choice.name << "\");\n"; if (cfg().setUserTexts) { if (!choice.label.isEmpty()) { stream() << " choice.label = " << translatedString(cfg(), choice.label, choice.context) - << ";" << endl; + << ";\n"; } if (!choice.toolTip.isEmpty()) { stream() << " choice.toolTip = " << translatedString(cfg(), choice.toolTip, choice.context) - << ";" << endl; + << ";\n"; } if (!choice.whatsThis.isEmpty()) { stream() << " choice.whatsThis = " << translatedString(cfg(), choice.whatsThis, choice.context) - << ";" << endl; + << ";\n"; } } - stream() << " values" << entry->name << ".append( choice );" << endl; - stream() << " }" << endl; + stream() << " values" << entry->name << ".append( choice );\n"; + stream() << " }\n"; } } void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QString &key) { stream() << " " << itemPath(entry, cfg()) << " = " - << newItem(entry, key, entry->defaultValue, cfg()) << endl; + << newItem(entry, key, entry->defaultValue, cfg()) << '\n'; if (!entry->min.isEmpty()) { - stream() << " " << itemPath(entry, cfg()) << "->setMinValue(" << entry->min << ");" << endl; + stream() << " " << itemPath(entry, cfg()) << "->setMinValue(" << entry->min << ");\n"; } if (!entry->max.isEmpty()) { - stream() << " " << itemPath(entry, cfg()) << "->setMaxValue(" << entry->max << ");" << endl; + stream() << " " << itemPath(entry, cfg()) << "->setMaxValue(" << entry->max << ");\n"; } if (cfg().setUserTexts) { stream() << userTextsFunctions(entry, cfg()); } if (cfg().allNotifiers || cfg().notifiers.contains(entry->name)) { - stream() << " " << itemPath(entry, cfg()) << "->setWriteFlags(KConfigBase::Notify);" << endl; + stream() << " " << itemPath(entry, cfg()) << "->setWriteFlags(KConfigBase::Notify);\n"; } stream() << " addItem( " << itemPath(entry, cfg()); QString quotedName = entry->name; addQuotes(quotedName); if (quotedName != key) { stream() << ", QStringLiteral( \"" << entry->name << "\" )"; } - stream() << " );" << endl; + stream() << " );\n"; } void KConfigSourceGenerator::createIndexedEntry(const CfgEntry *entry, const QString &key) @@ -350,7 +350,7 @@ : defaultValue(entry->type); stream() << " " << itemVarStr << " = " - << newItem(entry, paramString(key, entry, i), defaultStr, cfg(), QStringLiteral("[%1]").arg(i)) << endl; + << newItem(entry, paramString(key, entry, i), defaultStr, cfg(), QStringLiteral("[%1]").arg(i)) << '\n'; if (cfg().setUserTexts) { stream() << userTextsFunctions(entry, cfg(), itemVarStr, entry->paramName); @@ -367,7 +367,7 @@ stream() << " addItem( " << itemVarStr << ", QStringLiteral( \""; stream() << paramName.replace(QStringLiteral("$(") + entry->param + QLatin1Char(')'), QLatin1String("%1")).arg( arg ); - stream() << "\" ) );" << endl; + stream() << "\" ) );\n"; } } @@ -381,62 +381,62 @@ static bool first = true; if (!entry->group.isEmpty()) { if (!first) { - stream() << endl; + stream() << '\n'; } first = false; } mCurrentGroup = entry->group; stream() << " setCurrentGroup( " << paramString(mCurrentGroup, parseResult.parameters) << " );"; - stream() << endl << endl; + stream() << endl << '\n'; } void KConfigSourceGenerator::doConstructor() { // Constructor stream() << cfg().className << "::" << cfg().className << "("; createConstructorParameterList(); - stream() << " )" << endl; + stream() << " )\n"; stream() << " : "; createParentConstructorCall(); createInitializerList(); - stream() << "{" << endl; + stream() << "{\n"; if (cfg().parentInConstructor) { - stream() << " setParent(parent);" << endl; + stream() << " setParent(parent);\n"; } if (cfg().dpointer) { - stream() << " d = new " << cfg().className << "Private;" << endl; + stream() << " d = new " << cfg().className << "Private;\n"; if (parseResult.hasNonModifySignals) { - stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;" << endl; + stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;\n"; } } // Needed in case the singleton class is used as baseclass for // another singleton. if (cfg().singleton) { - stream() << " Q_ASSERT(!s_global" << cfg().className << "()->q);" << endl; - stream() << " s_global" << cfg().className << "()->q = this;" << endl; + stream() << " Q_ASSERT(!s_global" << cfg().className << "()->q);\n"; + stream() << " s_global" << cfg().className << "()->q = this;\n"; } if (!parseResult.signalList.isEmpty()) { // this cast to base-class pointer-to-member is valid C++ // https://stackoverflow.com/questions/4272909/is-it-safe-to-upcast-a-method-pointer-and-use-it-with-base-class-pointer/ stream() << " KConfigCompilerSignallingItem::NotifyFunction notifyFunction =" << " static_cast(&" - << cfg().className << "::itemChanged);" << endl; + << cfg().className << "::itemChanged);\n"; - stream() << endl; + stream() << '\n'; } for (auto *entry : parseResult.entries) { handleCurrentGroupChange(entry); const QString key = paramString(entry->key, parseResult.parameters); if (!entry->code.isEmpty()) { - stream() << entry->code << endl; + stream() << entry->code << '\n'; } createEnums(entry); @@ -451,7 +451,7 @@ } } - stream() << "}" << endl << endl; + stream() << "}\n\n"; } void KConfigSourceGenerator::createGetterDPointerMode(const CfgEntry *entry) @@ -467,15 +467,15 @@ if (!entry->param.isEmpty()) { stream() << " " << cppType(entry->paramType) << " i "; } - stream() << ")" << Const() << endl; + stream() << ")" << Const() << '\n'; // function body inline only if not using dpointer // for BC mode startScope(); // HACK: Fix memberAccessorBody stream() << " " << memberAccessorBody(entry, cfg().globalEnums); endScope(); - stream() << endl; + stream() << '\n'; } void KConfigSourceGenerator::createSetterDPointerMode(const CfgEntry *entry) @@ -495,29 +495,29 @@ } else { stream() << param(entry->type); } - stream() << " v )" << endl; + stream() << " v )\n"; // function body inline only if not using dpointer // for BC mode startScope(); memberMutatorBody(entry); endScope(); - stream() << endl; + stream() << '\n'; } void KConfigSourceGenerator::createItemGetterDPointerMode(const CfgEntry *entry) { // Item accessor if (!cfg().itemAccessors) { return; } - stream() << endl; + stream() << '\n'; stream() << cfg().inherits << "::Item" << itemType(entry->type) << " *" << getFunction(entry->name, cfg().className) << "Item("; if (!entry->param.isEmpty()) { stream() << " " << cppType(entry->paramType) << " i "; } - stream() << ")" << endl; + stream() << ")\n"; startScope(); stream() << " " << itemAccessorBody(entry, cfg()); endScope(); @@ -534,7 +534,7 @@ createSetterDPointerMode(entry); createGetterDPointerMode(entry); createItemGetterDPointerMode(entry); - stream() << endl; + stream() << '\n'; } } @@ -551,44 +551,44 @@ if (!entry->param.isEmpty()) { stream() << " " << cppType(entry->paramType) << " i "; } - stream() << ")" << Const() << endl; + stream() << ")" << Const() << '\n'; startScope(); - stream() << memberGetDefaultBody(entry) << endl; + stream() << memberGetDefaultBody(entry) << '\n'; endScope(); - stream() << endl; + stream() << '\n'; } } } void KConfigSourceGenerator::createDestructor() { - stream() << cfg().className << "::~" << cfg().className << "()" << endl; + stream() << cfg().className << "::~" << cfg().className << "()\n"; startScope(); if (cfg().dpointer) { - stream() << " delete d;" << endl; + stream() << " delete d;\n"; } if (cfg().singleton) { - stream() << " s_global" << cfg().className << "()->q = nullptr;" << endl; + stream() << " s_global" << cfg().className << "()->q = nullptr;\n"; } endScope(); - stream() << endl; + stream() << '\n'; } void KConfigSourceGenerator::createNonModifyingSignalsHelper() { if (!parseResult.hasNonModifySignals) { return; } - stream() << "bool " << cfg().className << "::" << "usrSave()" << endl; + stream() << "bool " << cfg().className << "::" << "usrSave()\n"; startScope(); - stream() << " const bool res = " << cfg().inherits << "::usrSave();" << endl; - stream() << " if (!res) return false;" << endl << endl; + stream() << " const bool res = " << cfg().inherits << "::usrSave();\n"; + stream() << " if (!res) return false;\n\n"; for (const Signal &signal : parseResult.signalList) { if (signal.modify) { continue; } - stream() << " if ( " << varPath(QStringLiteral("settingsChanged"), cfg()) << " & " << signalEnumName(signal.name) << " )" << endl; + stream() << " if ( " << varPath(QStringLiteral("settingsChanged"), cfg()) << " & " << signalEnumName(signal.name) << " )\n"; stream() << " Q_EMIT " << signal.name << "("; QList::ConstIterator it, itEnd = signal.arguments.constEnd(); for (it = signal.arguments.constBegin(); it != itEnd;) { @@ -612,11 +612,11 @@ } } - stream() << ");" << endl; + stream() << ");\n"; } - stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;" << endl; - stream() << " return true;" << endl; + stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " = 0;\n"; + stream() << " return true;\n"; endScope(); } @@ -626,32 +626,32 @@ return; } - stream() << endl; - stream() << "void " << cfg().className << "::" << "itemChanged(quint64 flags) {" << endl; + stream() << '\n'; + stream() << "void " << cfg().className << "::" << "itemChanged(quint64 flags) {\n"; if (parseResult.hasNonModifySignals) - stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " |= flags;" << endl; + stream() << " " << varPath(QStringLiteral("settingsChanged"), cfg()) << " |= flags;\n"; if (!parseResult.signalList.isEmpty()) - stream() << endl; + stream() << '\n'; for (const Signal &signal : parseResult.signalList) { if (signal.modify) { - stream() << " if ( flags & " << signalEnumName(signal.name) << " ) {" << endl; - stream() << " Q_EMIT " << signal.name << "();" << endl; - stream() << " }" << endl; + stream() << " if ( flags & " << signalEnumName(signal.name) << " ) {\n"; + stream() << " Q_EMIT " << signal.name << "();\n"; + stream() << " }\n"; } } - stream() << "}" << endl; + stream() << "}\n"; } void KConfigSourceGenerator::includeMoc() { const QString mocFileName = cfg().baseName + QStringLiteral(".moc"); if (parseResult.signalList.count() || cfg().generateProperties) { // Add includemoc if they are signals defined. - stream() << endl; - stream() << "#include \"" << mocFileName << "\"" << endl; - stream() << endl; + stream() << '\n'; + stream() << "#include \"" << mocFileName << "\"\n"; + stream() << '\n'; } } diff --git a/src/kconfig_compiler/KConfigXmlParser.cpp b/src/kconfig_compiler/KConfigXmlParser.cpp --- a/src/kconfig_compiler/KConfigXmlParser.cpp +++ b/src/kconfig_compiler/KConfigXmlParser.cpp @@ -32,13 +32,7 @@ #include #include #include - -namespace -{ -QTextStream cout(stdout); -QTextStream cerr(stderr); -} - +#include //TODO: Move preprocessDefault to Header / CPP implementation. // it makes no sense for a parser to process those values and generate code. @@ -58,13 +52,13 @@ } else if ((type == QLatin1String("UrlList") || type == QLatin1String("StringList") || type == QLatin1String("PathList")) && !defaultValue.isEmpty()) { QTextStream cpp(&code, QIODevice::WriteOnly | QIODevice::Append); if (!code.isEmpty()) { - cpp << endl; + cpp << '\n'; } if (type == QLatin1String("UrlList")) { - cpp << " QList default" << name << ";" << endl; + cpp << " QList default" << name << ";\n"; } else { - cpp << " QStringList default" << name << ";" << endl; + cpp << " QStringList default" << name << ";\n"; } const QStringList defaults = defaultValue.split(QLatin1Char(',')); QStringList::ConstIterator it; @@ -77,7 +71,7 @@ if (type == QLatin1String("UrlList")) { cpp << ") "; } - cpp << ");" << endl; + cpp << ");\n"; } defaultValue = QLatin1String("default") + name; @@ -107,16 +101,15 @@ } else if (type == QLatin1String("IntList")) { QTextStream cpp(&code, QIODevice::WriteOnly | QIODevice::Append); if (!code.isEmpty()) { - cpp << endl; + cpp << '\n'; } - cpp << " QList default" << name << ";" << endl; + cpp << " QList default" << name << ";\n"; if (!defaultValue.isEmpty()) { const QStringList defaults = defaultValue.split(QLatin1Char(',')); QStringList::ConstIterator it; for (it = defaults.constBegin(); it != defaults.constEnd(); ++it) { - cpp << " default" << name << ".append( " << *it << " );" - << endl; + cpp << " default" << name << ".append( " << *it << " );\n"; } } defaultValue = QLatin1String("default") + name; @@ -142,20 +135,20 @@ readEntry.paramType = e.attribute(QStringLiteral("type")); if (readEntry.param.isEmpty()) { - cerr << "Parameter must have a name: " << dumpNode(e) << endl; + std::cerr << "Parameter must have a name: " << qPrintable(dumpNode(e)) << std::endl; exit (1); } if (readEntry.paramType.isEmpty()) { - cerr << "Parameter must have a type: " << dumpNode(e) << endl; + std::cerr << "Parameter must have a type: " << qPrintable(dumpNode(e)) << std::endl; exit(1); } if ((readEntry.paramType == QLatin1String("Int")) || (readEntry.paramType == QLatin1String("UInt"))) { bool ok; readEntry.paramMax = e.attribute(QStringLiteral("max")).toInt(&ok); if (!ok) { - cerr << "Integer parameter must have a maximum (e.g. max=\"0\"): " << dumpNode(e) << endl; + std::cerr << "Integer parameter must have a maximum (e.g. max=\"0\"): " << qPrintable(dumpNode(e)) << std::endl; exit(1); } } else if (readEntry.paramType == QLatin1String("Enum")) { @@ -170,13 +163,13 @@ } } if (readEntry.paramValues.isEmpty()) { - cerr << "No values specified for parameter '" << readEntry.param << "'." << endl; + std::cerr << "No values specified for parameter '" << qPrintable(readEntry.param) << "'." << std::endl; exit(1); } readEntry.paramMax = readEntry.paramValues.count() - 1; } else { - cerr << "Parameter '" << readEntry.param << "' has type " << readEntry.paramType - << " but must be of type int, uint or Enum." << endl; + std::cerr << "Parameter '" << qPrintable(readEntry.param) << "' has type " << qPrintable(readEntry.paramType) + << " but must be of type int, uint or Enum." << std::endl; exit(1); } } @@ -204,7 +197,7 @@ CfgEntry::Choice choice; choice.name = e2.attribute(QStringLiteral("name")); if (choice.name.isEmpty()) { - cerr << "Tag requires attribute 'name'." << endl; + std::cerr << "Tag requires attribute 'name'." << std::endl; } for (QDomElement e3 = e2.firstChildElement(); !e3.isNull(); e3 = e3.nextSiblingElement()) { if (e3.tagName() == QLatin1String("label")) { @@ -278,7 +271,7 @@ { bool nameIsEmpty = readEntry.name.isEmpty(); if (nameIsEmpty && readEntry.key.isEmpty()) { - cerr << "Entry must have a name or a key: " << dumpNode(element) << endl; + std::cerr << "Entry must have a name or a key: " << qPrintable(dumpNode(element)) << std::endl; exit (1); } @@ -290,18 +283,18 @@ readEntry.name = readEntry.key; readEntry.name.remove(QLatin1Char(' ')); } else if (readEntry.name.contains(QLatin1Char(' '))) { - cout << "Entry '" << readEntry.name << "' contains spaces! elements can not contain spaces!" << endl; + std::cout << "Entry '" << qPrintable(readEntry.name) << "' contains spaces! elements can not contain spaces!" << std::endl; readEntry.name.remove(QLatin1Char(' ')); } if (readEntry.name.contains(QStringLiteral("$("))) { if (readEntry.param.isEmpty()) { - cerr << "Name may not be parameterized: " << readEntry.name << endl; + std::cerr << "Name may not be parameterized: " << qPrintable(readEntry.name) << std::endl; exit (1); } } else { if (!readEntry.param.isEmpty()) { - cerr << "Name must contain '$(" << readEntry.param << ")': " << readEntry.name << endl; + std::cerr << "Name must contain '$(" << qPrintable(readEntry.param) << ")': " << qPrintable(readEntry.name) << std::endl; exit (1); } } @@ -336,13 +329,13 @@ if (!ok) { i = readEntry.paramValues.indexOf(index); if (i == -1) { - cerr << "Index '" << index << "' for default value is unknown." << endl; + std::cerr << "Index '" << qPrintable(index) << "' for default value is unknown." << std::endl; exit (1); } } if ((i < 0) || (i > readEntry.paramMax)) { - cerr << "Index '" << i << "' for default value is out of range [0, " << readEntry.paramMax << "]." << endl; + std::cerr << "Index '" << i << "' for default value is out of range [0, " << readEntry.paramMax << "]." << std::endl; exit (1); } @@ -384,20 +377,20 @@ if (!mValidNameRegexp.match(readEntry.name).hasMatch()) { if (nameIsEmpty) - cerr << "The key '" << readEntry.key << "' can not be used as name for the entry because " - "it is not a valid name. You need to specify a valid name for this entry." << endl; + std::cerr << "The key '" << qPrintable(readEntry.key) << "' can not be used as name for the entry because " + "it is not a valid name. You need to specify a valid name for this entry." << std::endl; else { - cerr << "The name '" << readEntry.name << "' is not a valid name for an entry." << endl; + std::cerr << "The name '" << qPrintable(readEntry.name) << "' is not a valid name for an entry." << std::endl; } exit (1); } if (mAllNames.contains(readEntry.name)) { if (nameIsEmpty) - cerr << "The key '" << readEntry.key << "' can not be used as name for the entry because " - "it does not result in a unique name. You need to specify a unique name for this entry." << endl; + std::cerr << "The key '" << qPrintable(readEntry.key) << "' can not be used as name for the entry because " + "it does not result in a unique name. You need to specify a unique name for this entry." << std::endl; else { - cerr << "The name '" << readEntry.name << "' is not unique." << endl; + std::cerr << "The name '" << qPrintable(readEntry.name) << "' is not unique." << std::endl; } exit (1); } @@ -457,14 +450,14 @@ int errorRow; int errorCol; if (!doc.setContent(&input, &errorMsg, &errorRow, &errorCol)) { - cerr << "Unable to load document." << endl; - cerr << "Parse error in " << mInputFileName << ", line " << errorRow << ", col " << errorCol << ": " << errorMsg << endl; + std::cerr << "Unable to load document." << std::endl; + std::cerr << "Parse error in " << qPrintable(mInputFileName) << ", line " << errorRow << ", col " << errorCol << ": " << qPrintable(errorMsg) << std::endl; exit (1); } QDomElement cfgElement = doc.documentElement(); if (cfgElement.isNull()) { - cerr << "No document in kcfg file" << endl; + std::cerr << "No document in kcfg file" << std::endl; exit (1); } @@ -500,7 +493,7 @@ { QString group = e.attribute(QStringLiteral("name")); if (group.isEmpty()) { - cerr << "Group without name" << endl; + std::cerr << "Group without name" << std::endl; exit (1); } @@ -512,7 +505,7 @@ if (entry) { mParseResult.entries.append(entry); } else { - cerr << "Can not parse entry." << endl; + std::cerr << "Can not parse entry." << std::endl; exit (1); } } @@ -539,7 +532,7 @@ { QString signalName = e.attribute(QStringLiteral("name")); if (signalName.isEmpty()) { - cerr << "Signal without name." << endl; + std::cerr << "Signal without name." << std::endl; exit (1); } Signal theSignal; @@ -550,7 +543,7 @@ Param argument; argument.type = e2.attribute(QStringLiteral("type")); if (argument.type.isEmpty()) { - cerr << "Signal argument without type." << endl; + std::cerr << "Signal argument without type." << std::endl; exit (1); } argument.name= e2.text(); diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -48,12 +48,6 @@ #include "KConfigSourceGenerator.h" #include "KConfigXmlParser.h" -namespace -{ -QTextStream cout(stdout); -QTextStream cerr(stderr); -} - QString varName(const QString &n, const KConfigParameters &cfg) { QString result; @@ -266,7 +260,7 @@ } else if (type == QLatin1String("urllist")) { return QStringLiteral("const QList &"); } else { - cerr << "kconfig_compiler_kf5 does not support type \"" << type << "\"" << endl; + std::cerr << "kconfig_compiler_kf5 does not support type \"" << qPrintable(type) << "\"" << std::endl; return QStringLiteral("QString"); //For now, but an assert would be better } } @@ -320,7 +314,7 @@ } else if (type == QLatin1String("urllist")) { return QStringLiteral("QList"); } else { - cerr << "kconfig_compiler_kf5 does not support type \"" << type << "\"" << endl; + std::cerr << "kconfig_compiler_kf5 does not support type \"" << qPrintable(type) << "\"" << std::endl; return QStringLiteral("QString"); //For now, but an assert would be better } } @@ -371,7 +365,7 @@ } else if (type == QLatin1String("urllist")) { return QStringLiteral("QList()"); } else { - cerr << "Error, kconfig_compiler_kf5 does not support the \"" << type << "\" type!" << endl; + std::cerr << "Error, kconfig_compiler_kf5 does not support the \"" << qPrintable(type) << "\" type!" << std::endl; return QStringLiteral("QString"); //For now, but an assert would be better } } @@ -594,20 +588,20 @@ { QString result = e->code; QTextStream out(&result, QIODevice::WriteOnly); - out << endl; + out << '\n'; if (!e->param.isEmpty()) { - out << " switch (i) {" << endl; + out << " switch (i) {\n"; for (int i = 0; i <= e->paramMax; ++i) { if (!e->paramDefaultValues[i].isEmpty()) { - out << " case " << i << ": return " << e->paramDefaultValues[i] << ';' << endl; + out << " case " << i << ": return " << e->paramDefaultValues[i] << ";\n"; } } QString defaultValue = e->defaultValue; - out << " default:" << endl; - out << " return " << defaultValue.replace("$(" + e->param + ')', QLatin1String("i")) << ';' << endl; - out << " }" << endl; + out << " default:\n"; + out << " return " << defaultValue.replace("$(" + e->param + ')', QLatin1String("i")) << ";\n"; + out << " }\n"; } else { out << " return " << e->defaultValue << ';'; } @@ -627,7 +621,7 @@ if (!e->param.isEmpty()) { out << "[i]"; } - out << ";" << endl; + out << ";\n"; return result; } @@ -645,25 +639,25 @@ for (int i = 0; i < spaces; i++) { out << " "; } - out << currLine << endl; + out << currLine << '\n'; } return result; } bool hasErrors(KConfigXmlParser &parser, const ParseResult& parseResult, const KConfigParameters &cfg) { if (cfg.className.isEmpty()) { - cerr << "Class name missing" << endl; + std::cerr << "Class name missing" << std::endl; return true; } if (cfg.singleton && !parseResult.parameters.isEmpty()) { - cerr << "Singleton class can not have parameters" << endl; + std::cerr << "Singleton class can not have parameters" << std::endl; return true; } if (!parseResult.cfgFileName.isEmpty() && parseResult.cfgFileNameArg) { - cerr << "Having both a fixed filename and a filename as argument is not possible." << endl; + std::cerr << "Having both a fixed filename and a filename as argument is not possible." << std::endl; return true; } @@ -681,7 +675,7 @@ * (to make things more interesting, it failed in a code that's never used within KDevelop... ) */ if (parseResult.entries.isEmpty()) { - cerr << "No entries." << endl; + std::cerr << "No entries." << std::endl; return false; } @@ -717,23 +711,23 @@ parser.process(app); if (parser.isSet(licenseOption)) { - cout << "Copyright 2003 Cornelius Schumacher, Waldo Bastian, Zack Rusin," << endl; - cout << " Reinhold Kainhofer, Duncan Mac-Vicar P., Harald Fernengel" << endl; - cout << "This program comes with ABSOLUTELY NO WARRANTY." << endl; - cout << "You may redistribute copies of this program" << endl; - cout << "under the terms of the GNU Library Public License." << endl; - cout << "For more information about these matters, see the file named COPYING." << endl; + std::cout << "Copyright 2003 Cornelius Schumacher, Waldo Bastian, Zack Rusin," << std::endl; + std::cout << " Reinhold Kainhofer, Duncan Mac-Vicar P., Harald Fernengel" << std::endl; + std::cout << "This program comes with ABSOLUTELY NO WARRANTY." << std::endl; + std::cout << "You may redistribute copies of this program" << std::endl; + std::cout << "under the terms of the GNU Library Public License." << std::endl; + std::cout << "For more information about these matters, see the file named COPYING." << std::endl; return 0; } const QStringList args = parser.positionalArguments(); if (args.count() < 2) { - cerr << "Too few arguments." << endl; + std::cerr << "Too few arguments." << std::endl; return 1; } if (args.count() > 2) { - cerr << "Too many arguments." << endl; + std::cerr << "Too many arguments." << std::endl; return 1; } inputFilename = args.at(0);