Fix StringData::substr with single argument

Original version had an overflow bug
added unit test for BytesQuantity, and fixed some bugs #266

Also noticed that we needed to backport a bugfix for StringData::substr.

closes #266