There's a whole literature on string parsing, yet code like 'if charAtIndexIs(idx + 1, 'n')' could easily serve as pseudocode for the 8086 assembly version. If you're ever looking at an index counter, if correctness ever depends on manual checks for boundary conditions, if you're analyzing the string from the standpoint of individual characters rather than meaningful tokens, then you're partying like it's 1975.

The question becomes one of performance. We are not parsing so many format strings that performance is important, so I would implement this at a very high level, with parser combinators probably. But if I thought that was too slow, I'd still isolate the assembly code from the logic. The semantics being implemented - the fact that "%n" is a meaningful token within the string - are freely being mixed with the ultra-low-level detail of what's to be found at some register offset. Such code will always have bugs; more importantly, such code is utterly brutal to modify, especially for anyone who didn't write it.