Simplify location-replace logic - fewer ops, easier to understand

Previously, we'd step through each location that needed to be replaced. We'd replace the string at that position, re-find all offsets, and repeat.

This patch simplifies that logic, building a list of strings, including a substitution where needed. The list is then joined.