Fix prefix/suffix detection edge cases.

This fixes a few cases with shared prefix/suffix, where an error
condition could occur when attempting to create negative-sized
substrings, or blank symbols could occur when a symbol was entirely a
prefix or suffix of another.