| 42 | } |
| 43 | |
| 44 | bool KDevFormatFile::read() |
| 45 | { |
| 46 | constexpr QChar delimiter = QLatin1Char(':'); |
| 47 | |
| 48 | QFile formatFile(formatFileName); |
| 49 | if (!formatFile.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 50 | qStdOut() << "unable to open \"" << formatFileName << "\"\n"; |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | int lineNumber = 0; |
| 55 | while (!formatFile.atEnd()) { |
| 56 | ++lineNumber; |
| 57 | |
| 58 | QString line = QString::fromUtf8(formatFile.readLine().trimmed()); |
| 59 | if (line.isEmpty() || line.startsWith(QLatin1Char('#'))) |
| 60 | continue; |
| 61 | |
| 62 | if (line.indexOf(delimiter) < 0) { |
| 63 | // We found the simple syntax without wildcards, and only with the command |
| 64 | m_formatLines.append({QStringList{}, std::move(line)}); |
| 65 | } else { |
| 66 | // We found the correct syntax with "wildcards : command" |
| 67 | |
| 68 | QStringList wildcards = line.section(delimiter, 0, 0).split(QLatin1Char(' '), Qt::SkipEmptyParts); |
| 69 | QString command = line.section(delimiter, 1).trimmed(); |
| 70 | |
| 71 | if (wildcards.isEmpty()) { |
| 72 | qStdOut() << formatFileName << ":" << lineNumber |
| 73 | << ": error: empty wildcard, skip the line\n"; |
| 74 | continue; |
| 75 | } |
| 76 | m_formatLines.append({std::move(wildcards), std::move(command)}); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if (m_formatLines.isEmpty()) { |
| 81 | qStdOut() << formatFileName << ": error: no commands are found\n"; |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | bool KDevFormatFile::apply() |
| 89 | { |