add range checking to utf8len function