fix a bug in _str_to_index function.