Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r90836:2c39618c2b77 Date: 2017-03-28 13:22 +0200 http://bitbucket.org/pypy/pypy/changeset/2c39618c2b77/
Log: hg merge lstrip_to_empty_string PR #531. Thanks Nate! diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py --- a/rpython/rtyper/lltypesystem/rstr.py +++ b/rpython/rtyper/lltypesystem/rstr.py @@ -435,7 +435,7 @@ lpos = 0 rpos = s_len - 1 if left: - while lpos < rpos and s.chars[lpos] == ch: + while lpos <= rpos and s.chars[lpos] == ch: lpos += 1 if right: while lpos < rpos + 1 and s.chars[rpos] == ch: @@ -456,7 +456,7 @@ lpos = 0 rpos = s_len - 1 if left: - while lpos < rpos and s.chars[lpos].isspace(): + while lpos <= rpos and s.chars[lpos].isspace(): lpos += 1 if right: while lpos < rpos + 1 and s.chars[rpos].isspace(): @@ -477,7 +477,7 @@ lpos = 0 rpos = s_len - 1 if left: - while lpos < rpos and LLHelpers.ll_contains(s2, s.chars[lpos]): + while lpos <= rpos and LLHelpers.ll_contains(s2, s.chars[lpos]): lpos += 1 if right: while lpos < rpos + 1 and LLHelpers.ll_contains(s2, s.chars[rpos]): diff --git a/rpython/rtyper/test/test_rstr.py b/rpython/rtyper/test/test_rstr.py --- a/rpython/rtyper/test/test_rstr.py +++ b/rpython/rtyper/test/test_rstr.py @@ -459,6 +459,8 @@ return const(' ').strip(' ') def left2(): return const('a ').strip(' ') + def leftall(): + return const('!!').lstrip(const('!')) res = self.interpret(both, []) assert self.ll_to_string(res) == const('ab') res = self.interpret(left, []) @@ -469,6 +471,8 @@ assert self.ll_to_string(res) == const('') res = self.interpret(left2, []) assert self.ll_to_string(res) == const('a') + res = self.interpret(leftall, []) + assert self.ll_to_string(res) == const('') def test_strip_multiple_chars(self): const = self.const @@ -482,6 +486,8 @@ return const(' \t\t ').strip('\t ') def left2(): return const('a ').strip(' \t') + def leftall(): + return const('!ab!').lstrip(const('!ab')) res = self.interpret(both, []) assert self.ll_to_string(res) == const('b') res = self.interpret(left, []) @@ -492,6 +498,8 @@ assert self.ll_to_string(res) == const('') res = self.interpret(left2, []) assert self.ll_to_string(res) == const('a') + res = self.interpret(leftall, []) + assert self.ll_to_string(res) == const('') def test_upper(self): const = self.const _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit