LCOV - code coverage report
Current view: top level - src - filecontent.cpp (source / functions) Coverage Total Hit
Test: .lcov.total Lines: 100.0 % 39 39
Test Date: 2026-03-23 21:55:57 Functions: 100.0 % 10 10

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
       2              : // SPDX-License-Identifier: GPL-3.0-or-later
       3              : #include "filecontent.h"
       4              : 
       5              : #include "helpers.h"
       6              : #include <utility>
       7              : 
       8         1046 : static auto isLineHidden(const QString &line) -> bool {
       9         2092 :   return line.startsWith("otpauth://", Qt::CaseInsensitive);
      10              : }
      11              : 
      12          810 : auto FileContent::parse(const QString &fileContent,
      13              :                         const QStringList &templateFields, bool allFields)
      14              :     -> FileContent {
      15          810 :   QStringList lines = fileContent.split("\n");
      16          810 :   QString password = lines.takeFirst();
      17          810 :   QStringList remainingData;
      18          810 :   QStringList remainingDataDisplay;
      19          810 :   NamedValues namedValues;
      20         2326 :   for (const QString &line : AS_CONST(lines)) {
      21         3032 :     if (line.contains(":")) {
      22          732 :       int colon = line.indexOf(':');
      23          732 :       QString name = line.left(colon);
      24          732 :       QString value = line.right(line.length() - colon - 1);
      25          285 :       if ((allFields &&
      26          285 :            !value.startsWith(
      27         1017 :                "//")) // if value startswith  // colon is probably from a url
      28          732 :           || templateFields.contains(name)) {
      29          470 :         namedValues.append({name.trimmed(), value.trimmed()});
      30              :         continue;
      31              :       }
      32              :     }
      33              : 
      34              :     remainingData.append(line);
      35         1046 :     if (!isLineHidden(line)) {
      36              :       remainingDataDisplay.append(line);
      37              :     }
      38              :   }
      39         1620 :   return {password, namedValues, remainingData.join("\n"),
      40         3240 :           remainingDataDisplay.join("\n")};
      41              : }
      42              : 
      43          552 : auto FileContent::getPassword() const -> QString { return this->password; }
      44              : 
      45          624 : auto FileContent::getNamedValues() const -> NamedValues {
      46          624 :   return this->namedValues;
      47              : }
      48              : 
      49          579 : auto FileContent::getRemainingData() const -> QString {
      50          579 :   return this->remainingData;
      51              : }
      52              : 
      53           75 : auto FileContent::getRemainingDataForDisplay() const -> QString {
      54           75 :   return this->remainingDataDisplay;
      55              : }
      56              : 
      57          810 : FileContent::FileContent(QString password, NamedValues namedValues,
      58          810 :                          QString remainingData, QString remainingDataDisplay)
      59              :     : password(std::move(password)), namedValues(std::move(namedValues)),
      60              :       remainingData(std::move(remainingData)),
      61          810 :       remainingDataDisplay(std::move(remainingDataDisplay)) {}
      62              : 
      63          954 : NamedValues::NamedValues() = default;
      64              : 
      65          114 : NamedValues::NamedValues(std::initializer_list<NamedValue> values)
      66          114 :     : QList(values) {}
      67              : 
      68          289 : auto NamedValues::takeValue(const QString &name) -> QString {
      69          403 :   for (int i = 0; i < length(); ++i) {
      70          289 :     if (at(i).name == name) {
      71          350 :       return takeAt(i).value;
      72              :     }
      73              :   }
      74          114 :   return {};
      75              : }
        

Generated by: LCOV version 2.4-beta