Use const qualifier where possible.
Minor code rewrite to avoid distributed complexity.

Better to handle the +1 offset for the \0 characters in a single place.