LeaVerou / brep

Write batch find & replace scripts that transform files with a simple human-readable syntax
12 stars 0 forks source link

Swap? #3

Open LeaVerou opened 2 months ago

LeaVerou commented 2 months ago

Currently, swapping a string for another means you need to convert it to a temp first. E.g. replacing a with b and b with a would look like this:

[[ replace ]]
from = "a"
to = "c"

[[ replace ]]
from = "b"
to = "a"

[[ replace ]]
from = "c"
to = "b"

This is pretty awkward, especially for nonprogrammers, and error-prone (what if the string you choose already exists in the doc?).

I propose we have a mode that does this automatically. Something like:

swap = true
from = "a"
to = "b"

Since this only works with exact matches, perhaps the syntax should not allow combining it with regex by switching them both to a mode (or strategy?) setting:

mode = "swap"
from = "a"
to = "b"

(and regexp = true would become mode = regexp)

LeaVerou commented 1 month ago

On second thought, not sure there are use cases.