Move string-parsing code to where it can be reused