MCPcopy Create free account
hub / github.com/IJHack/QtPass / parse

Method parse

src/filecontent.cpp:24–56  ·  view source on GitHub ↗

* @brief Parses password file content into structured data. * @param fileContent Raw file content * @param templateFields Fields defined in the template * @param allFields Whether to include all name:value pairs * @return Parsed FileContent object */

Source from the content-addressed store, hash-verified

22 * @return Parsed FileContent object
23 */
24auto FileContent::parse(const QString &fileContent,
25 const QStringList &templateFields, bool allFields)
26 -> FileContent {
27 QStringList lines = fileContent.split("\n");
28 QString password;
29 if (!lines.isEmpty()) {
30 password = lines.takeFirst();
31 }
32 QStringList remainingData;
33 QStringList remainingDataDisplay;
34 NamedValues namedValues;
35 for (const QString &line : AS_CONST(lines)) {
36 if (line.contains(":")) {
37 int colon = line.indexOf(':');
38 QString name = line.left(colon);
39 QString value = line.right(line.length() - colon - 1);
40 if ((allFields &&
41 !value.startsWith(
42 "//")) // if value startswith // colon is probably from a url
43 || templateFields.contains(name)) {
44 namedValues.append({name.trimmed(), value.trimmed()});
45 continue;
46 }
47 }
48
49 remainingData.append(line);
50 if (!isLineHidden(line)) {
51 remainingDataDisplay.append(line);
52 }
53 }
54 return {password, namedValues, remainingData.join("\n"),
55 remainingDataDisplay.join("\n")};
56}
57
58/**
59 * @brief Gets the password from the parsed file.

Callers

nothing calls this directly

Calls 1

isLineHiddenFunction · 0.85

Tested by

no test coverage detected