Author: Tyler Wade <way...@gmail.com> Branch: utf8-unicode2 Changeset: r73353:20c49b3d0e22 Date: 2014-09-06 15:42 -0500 http://bitbucket.org/pypy/pypy/changeset/20c49b3d0e22/
Log: Rename this method diff --git a/pypy/interpreter/test/test_utf8.py b/pypy/interpreter/test/test_utf8.py --- a/pypy/interpreter/test/test_utf8.py +++ b/pypy/interpreter/test/test_utf8.py @@ -109,13 +109,13 @@ def test_convert_indices(): s = build_utf8str() - assert s.index_of_char(0) == 0 - assert s.index_of_char(1) == 1 - assert s.index_of_char(2) == 3 - assert s.index_of_char(3) == 6 + assert s.byte_index_of_char(0) == 0 + assert s.byte_index_of_char(1) == 1 + assert s.byte_index_of_char(2) == 3 + assert s.byte_index_of_char(3) == 6 for i in range(len(s)): - assert s.char_index_of_byte(s.index_of_char(i)) == i + assert s.char_index_of_byte(s.byte_index_of_char(i)) == i def test_join(): s = Utf8Str(' ') diff --git a/pypy/interpreter/utf8.py b/pypy/interpreter/utf8.py --- a/pypy/interpreter/utf8.py +++ b/pypy/interpreter/utf8.py @@ -57,7 +57,7 @@ return res def utf8ord(ustr, start=0): - start = ustr.index_of_char(start) + start = ustr.byte_index_of_char(start) return utf8ord_bytes(ustr.bytes, start) @specialize.argtype(0) @@ -161,10 +161,10 @@ self._len = length - def index_of_char(self, char): + def byte_index_of_char(self, char): return self._cache_scheme.byte_index_of_char(char) - def index_of_char_from_known(self, char, start_char, start_byte): + def byte_index_of_char_from_known(self, char, start_char, start_byte): if start_char > char: pos = start_char byte_pos = start_byte @@ -246,7 +246,7 @@ if self._is_ascii: return Utf8Str(self.bytes[start:stop], True) - start_byte = self.index_of_char(start) + start_byte = self.byte_index_of_char(start) stop_byte = start_byte stop_pos = start # TODO: Is detecting ascii-ness here actually useful? If it will @@ -364,11 +364,11 @@ if start < 0: start = 0 else: - start = self.index_of_char(start) + start = self.byte_index_of_char(start) elif start > len(self): start = -1 else: - start = self.index_of_char(start) + start = self.byte_index_of_char(start) if end is None or end >= len(self): end = len(self.bytes) @@ -377,11 +377,11 @@ if end < 0: end = 0 else: - end = self.index_of_char(end) + end = self.byte_index_of_char(end) elif end > len(self): end = len(self.bytes) else: - end = self.index_of_char(end) + end = self.byte_index_of_char(end) return start, end @@ -755,8 +755,8 @@ if isinstance(s, str): self._builder.append_slice(s, start, end) elif isinstance(s, Utf8Str): - self._builder.append_slice(s.bytes, s.index_of_char(start), - s.index_of_char(end)) + self._builder.append_slice(s.bytes, s.byte_index_of_char(start), + s.byte_index_of_char(end)) if not s._is_ascii: self._is_ascii = False else: @@ -852,7 +852,7 @@ self._pos = start self._calculated_pos = start - self._byte_pos = str.index_of_char(start) + self._byte_pos = str.byte_index_of_char(start) self._current = utf8ord_bytes(self._str.bytes, self._byte_pos) def _calc_current(self): @@ -932,7 +932,7 @@ if end_dist[0] < min[0]: min = end_dist - b = self.str.index_of_char_from_known(pos, min[1], min[2]) + b = self.str.byte_index_of_char_from_known(pos, min[1], min[2]) self.prev_pos = pos self.prev_byte_pos = b return b diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py --- a/pypy/module/cpyext/unicodeobject.py +++ b/pypy/module/cpyext/unicodeobject.py @@ -693,8 +693,8 @@ suffix match), 0 otherwise. Return -1 if an error occurred.""" str = space.unicode_w(w_str) substr = space.unicode_w(w_substr) - start = str.index_of_char(start) - end = str.index_of_char(end) + start = str.byte_index_of_char(start) + end = str.byte_index_of_char(end) if rffi.cast(lltype.Signed, direction) <= 0: return rstring.startswith(str.bytes, substr.bytes, start, end) else: diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -334,11 +334,13 @@ def _startswith(self, space, value, w_prefix, start, end): return startswith(value.bytes, self._op_val(space, w_prefix).bytes, - value.index_of_char(start), value.index_of_char(end)) + value.byte_index_of_char(start), + value.byte_index_of_char(end)) def _endswith(self, space, value, w_prefix, start, end): return endswith(value.bytes, self._op_val(space, w_prefix).bytes, - value.index_of_char(start), value.index_of_char(end)) + value.byte_index_of_char(start), + value.byte_index_of_char(end)) @staticmethod def _split(value, sep=None, maxsplit=-1): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit