Rewrite shp(ts) parsing to avoid offset issues.

Fixes #6822.  May also fix #6020, but I don't have a testcase for that.