Check segment count rather than slash count

The former has the advantage of only needing to scan the string twice.
In addition, we can always pass a maximum split count to the split
function so that we do not end up doing unnecessary work on the string
once we have hit the limit.