Warning, file /utilities/kate/addons/gdbplugin/json_placeholders.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2022 Héctor Mesa Jiménez <wmj.py@gmx.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include <QHash>
0009 #include <QSet>
0010 #include <QString>
0011 #include <optional>
0012 #include <utility>
0013 
0014 class QJsonObject;
0015 class QJsonArray;
0016 class QJsonValue;
0017 
0018 /**
0019  * @brief Utility for replacing variable placeholders in JSON documents
0020  *
0021  * Format:
0022  *
0023  *  ${variable} -> key="variable"
0024  *  ${long.variable} -> key="long.variable"
0025  *  ${#variable} -> key="#variable"
0026  *  ${#long.variable} -> key="#long.variable"
0027  *
0028  * A variable can be transformed by using a filter:
0029  *
0030  *  ${variable|base} -> file base name
0031  *  ${variable|dir} -> parent dir
0032  *
0033  *  ${variable|int} -> transform to an integer value
0034  *  ${variable|bool} -> transform to a boolean value
0035  *  ${variable|list} -> transform or keep as a stringlist
0036  *
0037  * "int" and "bool" filters are only applied when the string contains only the placeholder
0038  */
0039 namespace json
0040 {
0041 typedef QHash<QString, QJsonValue> VarMap;
0042 
0043 /**
0044  * @brief findVariables find variable templates and store in `variables`
0045  * @param map
0046  * @param variables
0047  */
0048 void findVariables(const QJsonObject &map, QSet<QString> &variables);
0049 void findVariables(const QJsonValue &value, QSet<QString> &variables);
0050 void findVariables(const QJsonArray &array, QSet<QString> &variables);
0051 void findVariables(const QString &text, QSet<QString> &variables);
0052 
0053 /**
0054  * @brief resolve replace variable templates with the values in `variables`
0055  * @param text
0056  * @param variables
0057  * @return
0058  */
0059 QJsonValue resolve(const QString &text, const VarMap &variables);
0060 QJsonObject resolve(const QJsonObject &map, const VarMap &variables);
0061 QJsonArray resolve(const QJsonArray &array, const VarMap &variables);
0062 QJsonValue resolve(const QJsonValue &value, const VarMap &variables);
0063 
0064 }