It is doing something a little smarter than that, as gofmt understands the language it is parsing it rather than just a textual find/replace.
The interesting thing here is that you can make your other tools use this, it makes writing tools around go a lot easier.