Test strings on length before content

A substring can of course not be longer that the full string. Also fixes
problems with CMake-versions that doesn't handle out-of-range parameters
to the SUBSTRING sub-command.
Merge pull request #194 from rolk/194_bugfix

Test strings on length before content