Factoring out String length check.

All string generating methods were performing the same check for the
type and value of the ``length`` argument. I have created a new
``is_valid_length`` method that removes the redundant code and seems to
speed up tests ten-fold.