Move some string formatting code into a shared place