Match rewrite rules iteratively, using array structure #2439
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Disclaimer: I don't know C++, so this is the result of trial and error!
This is not ready to be merged (although it works for me), I just wanted to check if this was something that might be desirable? Basically, I wanted to guarantee the order of rewrite rules (which is possible when rewrite rules are specified as an array, but not an object), and to allow successive rules to match against and replace the results of previous rules.
Here is an example config:
The motivation was to have both the
{name}
and the{title}
available in the format string so I can match against either on a case by case basis (falling back to one of the two if nothing earlier matches).The array structure should be an alternative to the existing object structure although I didn't get that far as I'm just not comfortable with C++. If an object is passed to the function it should probably just restructure it into an array.
The other change, which could potentially alter the behaviour of existing configs (so probably more of a concern) is that it matches against the current value of
res
rather than the originalvalue
in the conditional which decides whether or not to apply the rule.