The AttributeSubstitutor class substitutes attribute keys in strings with their actual values (e.g. replace "{{NAME}}" by "U42", a component's name)
More...
#include <attributesubstitutor.h>
|
static bool | searchVariablesInText (const QString &text, int startPos, int &pos, int &length, QStringList &keys) noexcept |
| Search the next variables (e.g. "{{KEY or FALLBACK}}") in a given text.
|
|
static void | applyFilter (QString &str, int &start, int &end, FilterFunction filter) noexcept |
|
static bool | getValueOfKey (const QString &key, QString &value, LookupFunction lookup) noexcept |
|
The AttributeSubstitutor class substitutes attribute keys in strings with their actual values (e.g. replace "{{NAME}}" by "U42", a component's name)
Please read the documentation about the Attributes System to get an idea how the Attributes System works in detail.
- See also
- librepcb::ProjectAttributeLookup
-
Attributes System
- Todo:
Fix side-effect of the endless loop detection ("{{FOO}} {{FOO}}" is currently substituted by "{{FOO}} " because of the endless loop detection, even if there is actually no endless loop).
Properly implement multiple key substitution ("{{FOO or BAR}}" is currently substituted by "{{FOO}}", even if the attribute {{FOO}} indirectly evaluates to an empty string).
◆ LookupFunction
◆ FilterFunction
◆ AttributeSubstitutor() [1/2]
◆ AttributeSubstitutor() [2/2]
◆ ~AttributeSubstitutor()
◆ operator=()
◆ substitute()
Substitute all attribute keys in a string with their attribute values.
- Parameters
-
str | A string which can contain variables ("{{NAME}}"). The attributes will be substituted directly in this string. |
lookup | The attribute lookup function (key -> value). |
filter | If a function is passed here, the substituted values will be passed to this function first. This allows for example to remove invalid characters if the resulting string is used for a file path. |
- Returns
- True if str was modified in some way, false if not
◆ searchVariablesInText()
bool searchVariablesInText |
( |
const QString & |
text, |
|
|
int |
startPos, |
|
|
int & |
pos, |
|
|
int & |
length, |
|
|
QStringList & |
keys |
|
) |
| |
|
staticprivatenoexcept |
Search the next variables (e.g. "{{KEY or FALLBACK}}") in a given text.
- Parameters
-
text | A text which can contain variables |
startPos | The search start index (use 0 to search in the whole text) |
pos | The index of the next variable in the specified text (index of the first '{' character, or -1 if no variable found) will be written into this variable. |
length | If a variable is found, the length (incl. '{{}}') will be written into this variable. |
keys | The variable key names (text between '{{' and '}}', split by ' or ') |
- Returns
- true if a variable is found, false if not
◆ applyFilter()
void applyFilter |
( |
QString & |
str, |
|
|
int & |
start, |
|
|
int & |
end, |
|
|
FilterFunction |
filter |
|
) |
| |
|
staticprivatenoexcept |
◆ getValueOfKey()
bool getValueOfKey |
( |
const QString & |
key, |
|
|
QString & |
value, |
|
|
LookupFunction |
lookup |
|
) |
| |
|
staticprivatenoexcept |
The documentation for this class was generated from the following files: