Use str.char_offset_iter instead of manually calling str.char_range_at.