Reimplemented format string using a state machine