コード例 #1
0
 def _startswith(self, space, value, w_prefix, start, end):
     prefix = self._op_val(space, w_prefix)
     if self._starts_ends_unicode:   # bug-to-bug compat
         if len(prefix) == 0:
             return True
     else:
         if start > len(value):
             return False
     return startswith(value, prefix, start, end)
コード例 #2
0
def PyUnicode_Tailmatch(space, w_str, w_substr, start, end, direction):
    """Return 1 if substr matches str[start:end] at the given tail end
    (direction == -1 means to do a prefix match, direction == 1 a
    suffix match), 0 otherwise. Return -1 if an error occurred."""
    str = space.unicode_w(w_str)
    substr = space.unicode_w(w_substr)
    if rffi.cast(lltype.Signed, direction) <= 0:
        return rstring.startswith(str, substr, start, end)
    else:
        return rstring.endswith(str, substr, start, end)
コード例 #3
0
ファイル: unicodeobject.py プロジェクト: mozillazg/pypy
def PyUnicode_Tailmatch(space, w_str, w_substr, start, end, direction):
    """Return 1 if substr matches str[start:end] at the given tail end
    (direction == -1 means to do a prefix match, direction == 1 a
    suffix match), 0 otherwise. Return -1 if an error occurred."""
    str = space.unicode_w(w_str)
    substr = space.unicode_w(w_substr)
    if rffi.cast(lltype.Signed, direction) <= 0:
        return rstring.startswith(str, substr, start, end)
    else:
        return rstring.endswith(str, substr, start, end)
コード例 #4
0
ファイル: unicodeobject.py プロジェクト: charred/pypy
def unicode_startswith__Unicode_ANY_ANY_ANY(space, w_unistr, w_prefixes,
                                              w_start, w_end):
    if not space.isinstance_w(w_prefixes, space.w_tuple):
        raise FailedToImplement
    unistr, start, end = _convert_idx_params(space, w_unistr,
                                             w_start, w_end, True)
    for w_prefix in space.fixedview(w_prefixes):
        prefix = space.unicode_w(w_prefix)
        if startswith(unistr, prefix, start, end):
            return space.w_True
    return space.w_False
コード例 #5
0
ファイル: stringobject.py プロジェクト: charred/pypy
def str_startswith__String_ANY_ANY_ANY(space, w_self, w_prefixes, w_start, w_end):
    if not space.isinstance_w(w_prefixes, space.w_tuple):
        raise FailedToImplement
    (u_self, start, end) = _convert_idx_params(space, w_self,
                                               w_start, w_end, True)
    for w_prefix in space.fixedview(w_prefixes):
        if space.isinstance_w(w_prefix, space.w_unicode):
            w_u = space.call_function(space.w_unicode, w_self)
            return space.call_method(w_u, "startswith", w_prefixes, w_start,
                                     w_end)
        prefix = space.str_w(w_prefix)
        if startswith(u_self, prefix, start, end):
            return space.w_True
    return space.w_False
コード例 #6
0
ファイル: stringobject.py プロジェクト: sota/pypy-old
def str_startswith__String_ANY_ANY_ANY(space, w_self, w_prefixes, w_start, w_end):
    if not space.isinstance_w(w_prefixes, space.w_tuple):
        raise FailedToImplement
    (u_self, start, end) = _convert_idx_params(space, w_self,
                                               w_start, w_end, True)
    for w_prefix in space.fixedview(w_prefixes):
        if space.isinstance_w(w_prefix, space.w_unicode):
            w_u = space.call_function(space.w_unicode, w_self)
            return space.call_method(w_u, "startswith", w_prefixes, w_start,
                                     w_end)
        prefix = space.str_w(w_prefix)
        if startswith(u_self, prefix, start, end):
            return space.w_True
    return space.w_False
コード例 #7
0
ファイル: stringmethods.py プロジェクト: sota/pypy-old
 def _startswith(self, space, value, w_prefix, start, end):
     prefix = self._op_val(space, w_prefix)
     if start > len(value):
         return self._starts_ends_overflow(prefix)
     return startswith(value, prefix, start, end)
コード例 #8
0
ファイル: test_rstring.py プロジェクト: Darriall/pypy
 def check_startswith(value, sub, *args, **kwargs):
     result = kwargs['res']
     assert startswith(value, sub, *args) is result
     assert startswith(list(value), sub, *args) is result
コード例 #9
0
ファイル: stringobject.py プロジェクト: charred/pypy
def str_startswith__String_String_ANY_ANY(space, w_self, w_prefix, w_start, w_end):
    (u_self, start, end) = _convert_idx_params(space, w_self, w_start,
                                               w_end, True)
    return space.newbool(startswith(u_self, w_prefix._value, start, end))
コード例 #10
0
ファイル: stringobject.py プロジェクト: sota/pypy-old
def str_startswith__String_String_ANY_ANY(space, w_self, w_prefix, w_start, w_end):
    (u_self, start, end) = _convert_idx_params(space, w_self, w_start,
                                               w_end, True)
    return space.newbool(startswith(u_self, w_prefix._value, start, end))
コード例 #11
0
 def _startswith(self, space, value, w_prefix, start, end):
     prefix = self._op_val(space, w_prefix)
     if start > len(value):
         return False
     return startswith(value, prefix, start, end)
コード例 #12
0
 def check_startswith(value, sub, *args, **kwargs):
     result = kwargs['res']
     assert startswith(value, sub, *args) is result
     assert startswith(list(value), sub, *args) is result
コード例 #13
0
ファイル: stringmethods.py プロジェクト: zielmicha/pypy
 def _startswith(self, space, value, w_prefix, start, end):
     return startswith(value, self._op_val(space, w_prefix), start, end)
コード例 #14
0
ファイル: stringmethods.py プロジェクト: mozillazg/pypy
 def _startswith(self, space, value, w_prefix, start, end):
     prefix = self._op_val(space, w_prefix)
     if start > len(value):
         return self._starts_ends_overflow(prefix)
     return startswith(value, prefix, start, end)
コード例 #15
0
ファイル: test_rstring.py プロジェクト: charred/pypy
def test_startswith():
    assert startswith('ab', 'ab') is True
    assert startswith('ab', 'a') is True
    assert startswith('ab', '') is True
    assert startswith('x', 'a') is False
    assert startswith('x', 'x') is True
    assert startswith('', '') is True
    assert startswith('', 'a') is False
    assert startswith('x', 'xx') is False
    assert startswith('y', 'xx') is False
    assert startswith('ab', 'a', 0) is True
    assert startswith('ab', 'a', 1) is False
    assert startswith('ab', 'b', 1) is True
    assert startswith('abc', 'bc', 1, 2) is False
    assert startswith('abc', 'c', -1, 4) is True
コード例 #16
0
ファイル: unicodeobject.py プロジェクト: charred/pypy
def unicode_startswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end):
    self, start, end = _convert_idx_params(space, w_self, w_start, w_end, True)
    return space.newbool(startswith(self, w_substr._value, start, end))