Move string-parsing code to where it can be reused

Change-Id: Ie043e403828237ee3a58baaa1521df2ea58d2f6d